[clang] [Clang][Sema] Skip checking anonymous enum in using enum declaration (PR #87144)
Qizhi Hu via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 16 01:41:39 PDT 2024
jcsxky wrote:
> This change has caused a regression in one of our systems integration tests that test static analysis for the bstring lib project (https://github.com/websnarf/bstrlib) with cross translation unit analysis enabled. Unfortunately I do not have a simple reproducer that stands alone just using clang, but I do have a reproducer that uses CodeChecker and can paste in the crash signature here. Please consider reverting the change until a proper fix can be made and this issue is addressed.
>
> ```
> bstrwrap.cpp
> 1 #include "bstrwrap.h"
> 2 #include <iostream>
> 3
> 4 Bstrlib::CBString::CBString () {
> 5 }
>
> bstrwrap.h
> 1 #include <string>
> 2
> 3 namespace Bstrlib {
> 4 struct CBString {
> 5 CBString ();
> 6 };
> 7
> 8 extern std::istream& getline (std::istream& sin, CBString& b, char terminator='\n');
> 9
> 10 } // namespace Bstrlib
>
>
> test.cpp
> 1 #include "bstrwrap.h"
> 2
> 3 int test0 (void) {
> 4 Bstrlib::CBString c0;
> 5 return 0;
> 6 }
> ```
>
> Using CodeChecker from https://github.com/Ericsson/codechecker, Log the build
>
> `CodeChecker log -b "g++ -c test.cpp bstrwrap.cpp" -o comp.json`
>
> Repro step
>
> ```
> ``env PATH=<UpstreamCompilerPath>:$PATH CC_ANALYZERS_FROM_PATH=1 CodeChecker analyze comp.json --clean --ctu -o report --analyzers clangsa``
> ```
>
> The crash signature, appears to be crashing in AST Import.
>
> ```
> 1. <eof> parser at end of file
> 2. While analyzing stack:
> #0 Calling test0()
> 3. test.cpp:4:21: Error evaluating statement
> 4. test.cpp:4:21: Error evaluating statement
> #0 0x0000000003cb7248 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (clang-19+0x3cb7248)
> #1 0x0000000003cb4f2c llvm::sys::CleanupOnSignal(unsigned long) (clang-19+0x3cb4f2c)
> #2 0x0000000003bfd308 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
> #3 0x00007f9e5d53d630 __restore_rt sigaction.c:0:0
> #4 0x00007f9e5af39387 raise (/lib64/libc.so.6+0x36387)
> #5 0x00007f9e5af3aa78 abort (/lib64/libc.so.6+0x37a78)
> #6 0x00007f9e5af321a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
> #7 0x00007f9e5af32252 (/lib64/libc.so.6+0x2f252)
> #8 0x00000000072ada26 clang::FunctionDecl::setDescribedFunctionTemplate(clang::FunctionTemplateDecl*) (clang-19+0x72ada26)
> #9 0x0000000007190a56 clang::ASTNodeImporter::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl*) (clang-19+0x7190a56)
> #10 0x000000000716e998 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*>>::Visit(clang::Decl*) crtstuff.c:0:0
> #11 0x000000000716eedb clang::ASTImporter::Import(clang::Decl*) (clang-19+0x716eedb)
> #12 0x0000000007172108 std::conditional<is_base_of_v<clang::Type, clang::Decl>, llvm::Expected<clang::Decl const*>, llvm::Expected<clang::Decl*>>::type clang::ASTNodeImporter::import<clang::Decl>(clang::Decl*) crtstuff.c:0:0
> #13 0x000000000717d072 clang::ASTNodeImporter::ImportDeclContext(clang::DeclContext*, bool) (clang-19+0x717d072)
> #14 0x000000000718677b clang::ASTNodeImporter::VisitNamespaceDecl(clang::NamespaceDecl*) (clang-19+0x718677b)
> #15 0x000000000716ea38 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*>>::Visit(clang::Decl*) crtstuff.c:0:0
> #16 0x000000000716eedb clang::ASTImporter::Import(clang::Decl*) (clang-19+0x716eedb)
> #17 0x0000000007175146 clang::ASTImporter::Import(clang::NestedNameSpecifier*) (clang-19+0x7175146)
> #18 0x000000000717a0bb clang::ASTNodeImporter::VisitElaboratedType(clang::ElaboratedType const*) (clang-19+0x717a0bb)
> #19 0x0000000007174945 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType>>::Visit(clang::Type const*) crtstuff.c:0:0
> #20 0x0000000007174c07 clang::ASTImporter::Import(clang::Type const*) (clang-19+0x7174c07)
> #21 0x0000000007175bd7 clang::ASTImporter::Import(clang::QualType) (clang-19+0x7175bd7)
> #22 0x0000000007177e20 clang::ASTNodeImporter::VisitLValueReferenceType(clang::LValueReferenceType const*) (clang-19+0x7177e20)
> ```
Looks like ASTImporter issue. Could you please provider a reproducer using clang only? That would be better to catch the issue. Just reverting this patch may not crash any more, but it would lead to incorrect AST be imported and influenced the accuracy of static analysis.
https://github.com/llvm/llvm-project/pull/87144
More information about the cfe-commits
mailing list