Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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/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",
Undefined = "-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 { "Undefined" }
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 { "Undefined" }
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
2 changes: 2 additions & 0 deletions website/docs/sanitize.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ sanitize { "value_list" }
|-------------|--------------------------------------------------------|
| 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 |
| Thread | Enables compiler support for ThreadSanitizer. |
| Undefined | Enables compiler support for UndefinedBehaviorSanitizer (UBSan). |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supported only by gcc/clang

Check also if msvc with clang toolset can support it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-cl supports passing -fsanitize=undefined to it, but I am unable to find a corresponding vcxproj flag for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keeping it with gcc/clang without MSVC/MSBuild support is perfectly sufficient for now.


### Applies To ###

Expand Down