Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,8 @@
allowed = {
"Address",
"Fuzzer", -- Visual Studio 2022+ only
"Thread",
"UndefinedBehavior",
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
},
sanitize = {
Address = "-fsanitize=address",
Thread = "-fsanitize=thread",
UndefinedBehavior = "-fsanitize=undefined",
},
visibility = {
Default = "-fvisibility=default",
Expand Down
52 changes: 36 additions & 16 deletions tests/tools/test_clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,45 @@
-- Check handling of linker flag.
--

function suite.ldflags_linker_lld()
linker "LLD"
prepare()
test.contains("-fuse-ld=lld", clang.getldflags(cfg))
end
function suite.ldflags_linker_lld()
linker "LLD"
prepare()
test.contains("-fuse-ld=lld", clang.getldflags(cfg))
end

--
-- Check the translation of CXXFLAGS.
--

function suite.onSanitizeAddress()
sanitize { "Address" }
prepare()
test.contains({ "-fsanitize=address" }, clang.getcxxflags(cfg))
test.contains({ "-fsanitize=address" }, clang.getldflags(cfg))
end
function suite.onSanitizeAddress()
sanitize { "Address" }
prepare()
test.contains({ "-fsanitize=address" }, clang.getcxxflags(cfg))
test.contains({ "-fsanitize=address" }, clang.getcflags(cfg))
test.contains({ "-fsanitize=address" }, clang.getldflags(cfg))
end

function suite.cxxflags_onSanitizeFuzzer()
sanitize { "Fuzzer" }
prepare()
test.contains({ "-fsanitize=fuzzer" }, clang.getcxxflags(cfg))
test.contains({ "-fsanitize=fuzzer" }, clang.getcflags(cfg))
test.contains({ "-fsanitize=fuzzer" }, clang.getldflags(cfg))
end

function suite.cxxflags_onSanitizeThread()
sanitize { "Thread" }
prepare()
test.contains({ "-fsanitize=thread" }, clang.getcxxflags(cfg))
test.contains({ "-fsanitize=thread" }, clang.getcflags(cfg))
test.contains({ "-fsanitize=thread" }, clang.getldflags(cfg))
end

function suite.cxxflags_onSanitizeFuzzer()
sanitize { "Fuzzer" }
prepare()
test.contains({ "-fsanitize=fuzzer" }, clang.getcxxflags(cfg))
end
-- UBSan
function suite.cxxflags_onSanitizeUndefined()
sanitize { "UndefinedBehavior" }
prepare()
test.contains({ "-fsanitize=undefined" }, clang.getcxxflags(cfg))
test.contains({ "-fsanitize=undefined" }, clang.getcflags(cfg))
test.contains({ "-fsanitize=undefined" }, clang.getldflags(cfg))
end
17 changes: 17 additions & 0 deletions tests/tools/test_gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,23 @@
test.contains({ "-fsanitize=address" }, gcc.getldflags(cfg))
end

function suite.cxxflags_onSanitizeThread()
sanitize { "Thread" }
prepare()
test.contains({ "-fsanitize=thread" }, gcc.getcxxflags(cfg))
test.contains({ "-fsanitize=thread" }, gcc.getcflags(cfg))
test.contains({ "-fsanitize=thread" }, gcc.getldflags(cfg))
end

-- UBSan
function suite.cxxflags_onSanitizeUndefined()
sanitize { "UndefinedBehavior" }
prepare()
test.contains({ "-fsanitize=undefined" }, gcc.getcxxflags(cfg))
test.contains({ "-fsanitize=undefined" }, gcc.getcflags(cfg))
test.contains({ "-fsanitize=undefined" }, gcc.getldflags(cfg))
end

--
-- Check the basic translation of LDFLAGS for a Posix system.
--
Expand Down
10 changes: 6 additions & 4 deletions website/docs/sanitize.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ sanitize { "value_list" }

`value_list` specifies the desired `fsanitize` options to enable.

| Value | Description |
|-------------|--------------------------------------------------------|
| Address | Enables compiler support for AddressSanitizer. | Visual Studio support starts with 2019 16.9 |
| Fuzzer | Enables support for LibFuzzer, a coverage-guided fuzzing library. | Visual Studio support starts with 2019 16.9 |
| Value | Description | Notes |
|-------------------|--------------------------------------------------------|---|
| Address | Enables compiler support for AddressSanitizer (ASan). | Visual Studio support starts with 2019 16.9 |
| Fuzzer | Enables support for LibFuzzer, a coverage-guided fuzzing library. | Unsupported with GCC. Visual Studio support starts with 2019 16.9 |
| Thread | Enables compiler support for ThreadSanitizer (TSan). | GCC & Clang only |
| UndefinedBehavior | Enables compiler support for UndefinedBehaviorSanitizer (UBSan). | GCC & Clang only |

### Applies To ###

Expand Down
Loading