Skip to content

[NFC] [CMake] Add -Wno-dangling-else for GCC built unittests #112817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 26, 2024
Merged
Changes from all 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
14 changes: 14 additions & 0 deletions llvm/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ function(add_llvm_target_unittest test_dir_name)
add_llvm_unittest(${test_dir_name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
endfunction()

# gtest macros like EXPECT_TRUE are expanded to a single line
# multi-statement code with if/else. eg:
# if (...)
# EXPECT_TURE(...)
# will be expanded into something like:
# if(...)
# switch (0) case 0: default: if (...) ; else return;;
Comment on lines +19 to +23
Copy link
Collaborator

Choose a reason for hiding this comment

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

EXPECT_TURE -> EXPECT_TRUE
if(...) -> if (...)

# GCC may emit false positive dangling-else warnings for such code.
# However, such warnings are actually against LLVM's style guide.
# disable the warning for GCC so that one can enbable Werror.
Copy link
Collaborator

Choose a reason for hiding this comment

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

disable -> Disable
enbable -> enable

I'd also do Werror -> -Werror to make it clear that this is an option.

if (CMAKE_COMPILER_IS_GNUCXX)
list(APPEND LLVM_COMPILE_FLAGS "-Wno-dangling-else")
endif ()

add_subdirectory(ADT)
add_subdirectory(Analysis)
add_subdirectory(AsmParser)
Expand Down
Loading