This fixes some warnings when compiling Clang & LLD on a out-of-the-box WSL/Ubuntu 18.04 shell.
Details
- Reviewers
spatel rnk nikic chandlerc MaskRay ioeric • espindola shafik martong - Commits
- rZORG11e82ed55fa1: Fix compilation warnings when compiling with GCC 7.3
rZORG5bc29e7a939b: Fix compilation warnings when compiling with GCC 7.3
rG11e82ed55fa1: Fix compilation warnings when compiling with GCC 7.3
rG5bc29e7a939b: Fix compilation warnings when compiling with GCC 7.3
rG799d96ec395f: Fix compilation warnings when compiling with GCC 7.3
rL360044: Fix compilation warnings when compiling with GCC 7.3
Diff Detail
- Repository
- rL LLVM
Event Timeline
clang/trunk/unittests/AST/ASTImporterTest.cpp | ||
---|---|---|
4054 ↗ | (On Diff #196354) | Fixes [2097/2979] Building CXX object tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/LookupTest.cpp.o /mnt/f/svn/clang/unittests/Tooling/LookupTest.cpp: In lambda function: /mnt/f/svn/clang/unittests/Tooling/LookupTest.cpp:220:8: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wdangling-else] if (Type.getDecl()->getQualifiedNameAsString() == "x::y::Old") ^ |
clang/trunk/unittests/Tooling/LookupTest.cpp | ||
222 ↗ | (On Diff #196354) | Fixes [2107/2979] Building CXX object tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o /mnt/f/svn/clang/unittests/AST/ASTImporterTest.cpp: In member function ‘void clang::ast_matchers::RedeclChain<TypeParam>::TypedTest_PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition()’: /mnt/f/svn/clang/unittests/AST/ASTImporterTest.cpp:4051:8: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wdangling-else] if (auto *ToT = dyn_cast<TemplateDecl>(ToD)) ^ |
lld/trunk/ELF/LinkerScript.cpp | ||
892 ↗ | (On Diff #196354) | Fixes [2238/2979] Building CXX object tools/lld/ELF/CMakeFiles/lldELF.dir/LinkerScript.cpp.o /mnt/f/svn/lld/ELF/LinkerScript.cpp: In member function ‘void lld::elf::LinkerScript::adjustSectionsBeforeSorting()’: /mnt/f/svn/lld/ELF/LinkerScript.cpp:891:35: warning: enumeral and non-enumeral type in conditional expression [-Wextra] Flags & ((Sec->NonAlloc ? 0 : SHF_ALLOC) | SHF_WRITE | SHF_EXECINSTR); ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ |
llvm/trunk/unittests/Support/TypeTraitsTest.cpp | ||
21–1 | Fixes a bunch of [2828/2979] Building CXX object unittests/Support/CMakeFiles/SupportTests.dir/TypeTraitsTest.cpp.o /mnt/f/svn/llvm/unittests/Support/TypeTraitsTest.cpp:20:6: warning: ‘void {anonymous}::triviality::TrivialityTester() [with T = {anonymous}::triviality::B&&; bool IsTriviallyCopyConstructible = false; bool IsTriviallyMoveConstructible = true]’ defined but not used [-Wunused-function] void TrivialityTester() { ^~~~~~~~~~~~~~~~ | |
llvm/trunk/unittests/Transforms/Scalar/CMakeLists.txt | ||
6 | Fixes [2894/2979] Building CXX object unittests/Transforms/Scalar/CMakeFiles/ScalarTests.dir/LoopPassManagerTest.cpp.o In file included from /mnt/f/svn/llvm/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h:43:0, from /mnt/f/svn/llvm/utils/unittest/googlemock/include/gmock/gmock.h:61, from /mnt/f/svn/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp:29: /mnt/f/svn/llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h:896:11: warning: ‘testing::internal::TypedExpectation<F>::~TypedExpectation() noexcept [with F = {anonymous}::MockAnalysisHandleBase<{anonymous}::MockFunctionAnalysisHandle, llvm::Function>::Analysis::Result(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)]’ declared ‘static’ but never defined [-Wunused-function] virtual ~TypedExpectation() { ^ |
llvm/trunk/lib/Target/AMDGPU/R600ISelLowering.cpp | ||
---|---|---|
7–12 | We don't want to have ifdefs for specific compilers, can this be fixed another way or dropped from the patch? | |
llvm/trunk/unittests/IR/ConstantRangeTest.cpp | ||
2–5 | Same here, no compiler specific ifdefs. | |
llvm/trunk/unittests/Transforms/Scalar/CMakeLists.txt | ||
3–6 | Same thing here too. |
llvm/trunk/include/llvm/BinaryFormat/ELF.h | ||
---|---|---|
878 ↗ | (On Diff #196358) | SHF_NONE is not defined in /usr/binclude/elf.h. (unsigned)SHF_ALLOC is probably better. |
llvm/trunk/unittests/IR/ConstantRangeTest.cpp | ||
---|---|---|
2–5 | Just doing an unconditional (void)HaveInterrupt3; should be fine here. This warning is likely not specific to GCC 7 anyway. |
clang/trunk/unittests/AST/ASTImporterTest.cpp | ||
---|---|---|
4054 ↗ | (On Diff #196354) | You mixed up the error messages but I see what is going on. So you may want to add a comment since it is not apparent that what is going on is due the EXPECT_TRUE macro eventually expanding to an if..else which is what is triggering the warning. Since someone may come by in the future and just remove the braces since it is not apparent why they are there. Same below as well. |
clang/trunk/unittests/AST/ASTImporterTest.cpp | ||
---|---|---|
4054 ↗ | (On Diff #196354) | EXPECT_* inside if is quite common, I don't think we should add a comment every time it is used. |
Adressed some of the comments.
llvm/trunk/lib/Target/AMDGPU/R600ISelLowering.cpp | ||
---|---|---|
7–12 | Removed ifdefs, but I kept the test. This looks like an optimizer issue in GCC, however the regression tests are unaffected by this change. I will c-reduce and report it if it's still there in the latest GCC. | |
llvm/trunk/unittests/Transforms/Scalar/CMakeLists.txt | ||
3–6 | Not sure I understand, there're plenty of compiler-specific examples in the .cmake files. Is there an alternate way to fix this? |
llvm/trunk/unittests/Transforms/Scalar/CMakeLists.txt | ||
---|---|---|
3–6 | I know there are some, but I don't think a warning like this is important enough to fix with a compiler specific work-around. |
clang/trunk/unittests/AST/ASTImporterTest.cpp | ||
---|---|---|
4054 ↗ | (On Diff #196354) | This is a longstanding issue. gtest even includes this beautiful snippet of code: // The GNU compiler emits a warning if nested "if" statements are followed by // an "else" statement and braces are not used to explicitly disambiguate the // "else" binding. This leads to problems with code like: // // if (gate) // ASSERT_*(condition) << "Some message"; // // The "switch (0) case 0:" idiom is used to suppress this. #ifdef __INTEL_COMPILER # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ #else # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT #endif The expansion looks something like this: if (user_cond) switch (0) case 0: default: if (const TestResult res = ...); else fail(res, ...) << "User streaming can follow" It seems new versions of GCC have gotten "smarter" and this pattern no longer suppresses the warning as desired. It might be worth disabling -Wdangling-else for GCC at this point, since this will be an ongoing problem because LLVM typically elides braces when possible. Oh, we even reported it back in 2017: |
clang/trunk/unittests/AST/ASTImporterTest.cpp | ||
---|---|---|
4054 ↗ | (On Diff #196354) | So revert those braces and disable -Wdangling-else if CMAKE_COMPILER_IS_GNUCXX ? (somewhere in HandleLLVMOptions.cmake) |
llvm/trunk/unittests/Transforms/Scalar/CMakeLists.txt | ||
3–6 | You mean more like # Workaround for the gcc 6.1 bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80916. if (NOT MSVC) set_source_files_properties(LoopPassManagerTest.cpp PROPERTIES COMPILE_FLAGS -Wno-unused-function) endif() Or leave the warning? There's already an #ifdef below in LoopPassManagerTest.cpp but it's not at the right place, this simply corrects it. |
llvm/trunk/unittests/Transforms/Scalar/CMakeLists.txt | ||
---|---|---|
3–6 | Ok, I see in this case you are just moving the ifdef out of the code and into CMake. I really don't like either approach, but I guess this is fine. I would limit the work-around to only known broken compilers though. It looks like this might be fixed in gcc 9. |
Please let me know if other changes are needed.
llvm/trunk/unittests/Transforms/Scalar/CMakeLists.txt | ||
---|---|---|
3–6 | Scoping this issue under GCC version range [6.1, 9.0) |
lgtm
The only remaining change I find questionable is the R600 backend change, but on the whole I think it's fine and you don't need to wait for more review. Better to fix the warnings and people with concerns can repaint the bikeshed as they like.
llvm/trunk/unittests/IR/ConstantRangeTest.cpp | ||
---|---|---|
2 | I don't think a comment here is necessary, casting something to avoid before an assert is a pretty standard idiom for "suppress -Wunused-variable". |
creduce'd and reported here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63477#c4 - it is still present with GCC 9.1
We don't want to have ifdefs for specific compilers, can this be fixed another way or dropped from the patch?