Skip to content

[clang] Crash in clang codegen after CXXDependentScopeMemberExpr change #97483

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

Closed
mikerice1969 opened this issue Jul 2, 2024 · 8 comments · Fixed by #97596
Closed

[clang] Crash in clang codegen after CXXDependentScopeMemberExpr change #97483

mikerice1969 opened this issue Jul 2, 2024 · 8 comments · Fixed by #97596
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@mikerice1969
Copy link
Contributor

Attached test crashes in clang codegen after fd87d76. The test has been creduced from some 600,000+ lines of preprocessed Windows blender code. The crash happens in the same place in the full code (but the expression is used).

t.cpp:66:21: warning: expression result unused [-Wunused-value]
   66 |   void bl() { bf::l &m; }
      |               ~~~~~ ^~
t.cpp:143:6: note: in instantiation of member function 'bk<3>::bl' requested here
  143 |   r->bl();
      |      ^
t.cpp:133:26: note: in instantiation of function template specialization 'ci<int, int, int, int>::decode<f>' requested here
  133 |           bg->bc(cz.e(), decode(da));
      |                          ^
t.cpp:117:3: note: in instantiation of function template specialization 'ci<int, int, int, int>::cn<g>' requested here
  117 |   cn(cm);
      |   ^
t.cpp:157:4: note: in instantiation of member function 'ci<int, int, int, int>::operator()' requested here
  157 |   s(bq, db, y, dd);
      |    ^
t.cpp:162:5: note: in instantiation of function template specialization 'de<int, int, int>' requested here
  162 |     de<int, int, int>(df);
      |     ^
t.cpp:87:15: note: in instantiation of function template specialization 'v::operator()<h, h, float, 1>' requested here
   87 |   bt.template operator()<j, j, float, 1>(bq);
      |               ^
t.cpp:168:3: note: in instantiation of function template specialization 'bs<v>' requested here
  168 |   bs(bq, bt);
      |   ^
Unhandled DeclRefExpr
UNREACHABLE executed at /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3180!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang-cl -cc1 -triple x86_64-pc-windows-msvc19.29.30154 -emit-obj -mincremental-linker-compatible -disable-free -clear-ast-before-backend -main-file-name image_vdb.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -menable-no-infs -menable-no-nans -fapprox-func -funsafe-math-optimizations -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -complex-range=basic -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -fdeprecated-macro -ferror-limit 19 -fopenmp -fno-signed-char -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.29.30154 -std=c++17 -finline-functions -fskip-odr-check-in-gmf -fdelayed-template-parsing -vectorize-loops -vectorize-slp -faddrsig -x c++ t.cpp
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	t.cpp:66:8: Generating code for declaration 'bk<3>::bl'
 #0 0x00007fc423b55f6a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x00007fc423b563b2 PrintStackTraceSignalHandler(void*) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00007fc423b53ba7 llvm::sys::RunSignalHandlers() /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x00007fc423b55932 SignalHandler(int) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007fc4233efdb0 __restore_rt (/lib64/libc.so.6+0x59db0)
 #5 0x00007fc42343c42c __pthread_kill_implementation (/lib64/libc.so.6+0xa642c)
 #6 0x00007fc4233efd06 gsignal (/lib64/libc.so.6+0x59d06)
 #7 0x00007fc4233c27d3 abort (/lib64/libc.so.6+0x2c7d3)
 #8 0x00007fc423a3e827 bindingsErrorHandler(void*, char const*, bool) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/ErrorHandling.cpp:222:55
 #9 0x00007fc42be3808d clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3181:1
#10 0x00007fc42be2e9fb clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1552:50
#11 0x00007fc42be2e641 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1505:22
#12 0x00007fc42be2e3d9 clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1472:20
#13 0x00007fc42bebdb33 (anonymous namespace)::ScalarExprEmitter::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:255:40
#14 0x00007fc42bebddf9 (anonymous namespace)::ScalarExprEmitter::EmitLoadOfLValue(clang::Expr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:303:32
#15 0x00007fc42bebe9ff (anonymous namespace)::ScalarExprEmitter::VisitDeclRefExpr(clang::DeclRefExpr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:523:30
#16 0x00007fc42bedbd48 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:456:1
#17 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#18 0x00007fc42bec8530 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:2479:17
#19 0x00007fc42bedd415 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:516:1
#20 0x00007fc42bedbe08 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:516:1
#21 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#22 0x00007fc42bed95ab clang::CodeGen::CodeGenFunction::EmitPromotedScalarExpr(clang::Expr const*, clang::QualType) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5516:64
#23 0x00007fc42bece645 (anonymous namespace)::ScalarExprEmitter::EmitBinOps(clang::BinaryOperator const*, clang::QualType) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:3467:14
#24 0x00007fc42bec0612 (anonymous namespace)::ScalarExprEmitter::VisitBinAnd(clang::BinaryOperator const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:871:3
#25 0x00007fc42bedb2fb clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/clang/include/clang/AST/StmtVisitor.h:68:26
#26 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#27 0x00007fc42bed93a5 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5485:1
#28 0x00007fc42be279f2 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:229:23
#29 0x00007fc42be278e8 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:204:29
#30 0x00007fc42c077bc4 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGStmt.cpp:130:56
#31 0x00007fc42c078fea clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGStmt.cpp:514:3
#32 0x00007fc42c140cf6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1300:33
#33 0x00007fc42c141cdd clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1526:21
#34 0x00007fc42c172941 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5900:3
#35 0x00007fc42c16aec6 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4100:28
#36 0x00007fc42c166b76 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3197:31
#37 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#38 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#39 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#40 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#41 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#42 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#43 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#44 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#45 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#46 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#47 0x00007fc42c15a80b clang::CodeGen::CodeGenModule::Release() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:845:23
#48 0x00007fc42c3240a5 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:291:11
#49 0x00007fc42c123928 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:283:9
#50 0x00007fc41d3bdef0 clang::ParseAST(clang::Sema&, bool, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/Parse/ParseAST.cpp:183:14
#51 0x00007fc4289ec228 clang::ASTFrontendAction::ExecuteAction() /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1192:11
#52 0x00007fc42c12801f clang::CodeGenAction::ExecuteAction() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1147:5
#53 0x00007fc4289ebb41 clang::FrontendAction::Execute() /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1082:38
#54 0x00007fc4288ee589 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1061:42
#55 0x00007fc42e24297b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /export/iusers/mprice1/community1/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:38
#56 0x000000000041df72 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/cc1_main.cpp:232:40
#57 0x0000000000410391 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/driver.cpp:215:20
#58 0x0000000000410886 clang_main(int, char**, llvm::ToolContext const&) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/driver.cpp:256:26
#59 0x0000000000446cc5 main /export/iusers/mprice1/community1/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:20
#60 0x00007fc4233dae50 __libc_start_call_main (/lib64/libc.so.6+0x44e50)
#61 0x00007fc4233daefc __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x44efc)
#62 0x000000000040f7d5 _start (/localdisk2/mprice1/community1/llvm-project/build/bin/clang-19+0x40f7d5)
t.sh: line 1: 3845825 Aborted                 (core dumped) clang-cl "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30154" "-emit-obj" "-mincremental-linker-compatible" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "image_vdb.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-relaxed-aliasing" "-menable-no-infs" "-menable-no-nans" "-fapprox-func" "-funsafe-math-optimizations" "-fno-signed-zeros" "-mreassociate" "-freciprocal-math" "-ffp-contract=fast" "-fno-rounding-math" "-ffast-math" "-ffinite-math-only" "-complex-range=basic" "-mconstructor-aliases" "-fms-volatile" "-funwind-tables=2" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-fdeprecated-macro" "-ferror-limit" "19" "-fopenmp" "-fno-signed-char" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30154" "-std=c++17" "-finline-functions" "-fskip-odr-check-in-gmf" "-fdelayed-template-parsing" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-x" "c++" "t.cpp"

testcase.zip

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jul 2, 2024
@mikerice1969
Copy link
Contributor Author

@sdkrystian would you mind taking a look at this? It seems to be a regression from #92318

@EugeneZelenko EugeneZelenko added clang:codegen IR generation bugs: mangling, exceptions, etc. crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Jul 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2024

@llvm/issue-subscribers-clang-codegen

Author: Mike Rice (mikerice1969)

Attached test crashes in clang codegen after fd87d76. The test has been creduced from some 600,000+ lines of preprocessed Windows blender code. The crash happens in the same place in the full code (but the expression is used).
t.cpp:66:21: warning: expression result unused [-Wunused-value]
   66 |   void bl() { bf::l &amp;m; }
      |               ~~~~~ ^~
t.cpp:143:6: note: in instantiation of member function 'bk&lt;3&gt;::bl' requested here
  143 |   r-&gt;bl();
      |      ^
t.cpp:133:26: note: in instantiation of function template specialization 'ci&lt;int, int, int, int&gt;::decode&lt;f&gt;' requested here
  133 |           bg-&gt;bc(cz.e(), decode(da));
      |                          ^
t.cpp:117:3: note: in instantiation of function template specialization 'ci&lt;int, int, int, int&gt;::cn&lt;g&gt;' requested here
  117 |   cn(cm);
      |   ^
t.cpp:157:4: note: in instantiation of member function 'ci&lt;int, int, int, int&gt;::operator()' requested here
  157 |   s(bq, db, y, dd);
      |    ^
t.cpp:162:5: note: in instantiation of function template specialization 'de&lt;int, int, int&gt;' requested here
  162 |     de&lt;int, int, int&gt;(df);
      |     ^
t.cpp:87:15: note: in instantiation of function template specialization 'v::operator()&lt;h, h, float, 1&gt;' requested here
   87 |   bt.template operator()&lt;j, j, float, 1&gt;(bq);
      |               ^
t.cpp:168:3: note: in instantiation of function template specialization 'bs&lt;v&gt;' requested here
  168 |   bs(bq, bt);
      |   ^
Unhandled DeclRefExpr
UNREACHABLE executed at /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3180!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang-cl -cc1 -triple x86_64-pc-windows-msvc19.29.30154 -emit-obj -mincremental-linker-compatible -disable-free -clear-ast-before-backend -main-file-name image_vdb.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -menable-no-infs -menable-no-nans -fapprox-func -funsafe-math-optimizations -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -complex-range=basic -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -fdeprecated-macro -ferror-limit 19 -fopenmp -fno-signed-char -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.29.30154 -std=c++17 -finline-functions -fskip-odr-check-in-gmf -fdelayed-template-parsing -vectorize-loops -vectorize-slp -faddrsig -x c++ t.cpp
1.	&lt;eof&gt; parser at end of file
2.	Per-file LLVM IR generation
3.	t.cpp:66:8: Generating code for declaration 'bk&lt;3&gt;::bl'
 #<!-- -->0 0x00007fc423b55f6a llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #<!-- -->1 0x00007fc423b563b2 PrintStackTraceSignalHandler(void*) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #<!-- -->2 0x00007fc423b53ba7 llvm::sys::RunSignalHandlers() /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #<!-- -->3 0x00007fc423b55932 SignalHandler(int) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #<!-- -->4 0x00007fc4233efdb0 __restore_rt (/lib64/libc.so.6+0x59db0)
 #<!-- -->5 0x00007fc42343c42c __pthread_kill_implementation (/lib64/libc.so.6+0xa642c)
 #<!-- -->6 0x00007fc4233efd06 gsignal (/lib64/libc.so.6+0x59d06)
 #<!-- -->7 0x00007fc4233c27d3 abort (/lib64/libc.so.6+0x2c7d3)
 #<!-- -->8 0x00007fc423a3e827 bindingsErrorHandler(void*, char const*, bool) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/ErrorHandling.cpp:222:55
 #<!-- -->9 0x00007fc42be3808d clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3181:1
#<!-- -->10 0x00007fc42be2e9fb clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1552:50
#<!-- -->11 0x00007fc42be2e641 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1505:22
#<!-- -->12 0x00007fc42be2e3d9 clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1472:20
#<!-- -->13 0x00007fc42bebdb33 (anonymous namespace)::ScalarExprEmitter::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:255:40
#<!-- -->14 0x00007fc42bebddf9 (anonymous namespace)::ScalarExprEmitter::EmitLoadOfLValue(clang::Expr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:303:32
#<!-- -->15 0x00007fc42bebe9ff (anonymous namespace)::ScalarExprEmitter::VisitDeclRefExpr(clang::DeclRefExpr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:523:30
#<!-- -->16 0x00007fc42bedbd48 clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:456:1
#<!-- -->17 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#<!-- -->18 0x00007fc42bec8530 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:2479:17
#<!-- -->19 0x00007fc42bedd415 clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::VisitImplicitCastExpr(clang::ImplicitCastExpr*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:516:1
#<!-- -->20 0x00007fc42bedbe08 clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:516:1
#<!-- -->21 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#<!-- -->22 0x00007fc42bed95ab clang::CodeGen::CodeGenFunction::EmitPromotedScalarExpr(clang::Expr const*, clang::QualType) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5516:64
#<!-- -->23 0x00007fc42bece645 (anonymous namespace)::ScalarExprEmitter::EmitBinOps(clang::BinaryOperator const*, clang::QualType) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:3467:14
#<!-- -->24 0x00007fc42bec0612 (anonymous namespace)::ScalarExprEmitter::VisitBinAnd(clang::BinaryOperator const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:871:3
#<!-- -->25 0x00007fc42bedb2fb clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/clang/include/clang/AST/StmtVisitor.h:68:26
#<!-- -->26 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#<!-- -->27 0x00007fc42bed93a5 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5485:1
#<!-- -->28 0x00007fc42be279f2 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:229:23
#<!-- -->29 0x00007fc42be278e8 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:204:29
#<!-- -->30 0x00007fc42c077bc4 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef&lt;clang::Attr const*&gt;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGStmt.cpp:130:56
#<!-- -->31 0x00007fc42c078fea clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&amp;, bool, clang::CodeGen::AggValueSlot) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGStmt.cpp:514:3
#<!-- -->32 0x00007fc42c140cf6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1300:33
#<!-- -->33 0x00007fc42c141cdd clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1526:21
#<!-- -->34 0x00007fc42c172941 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5900:3
#<!-- -->35 0x00007fc42c16aec6 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4100:28
#<!-- -->36 0x00007fc42c166b76 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3197:31
#<!-- -->37 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->38 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->39 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->40 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->41 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->42 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->43 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->44 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->45 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->46 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->47 0x00007fc42c15a80b clang::CodeGen::CodeGenModule::Release() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:845:23
#<!-- -->48 0x00007fc42c3240a5 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:291:11
#<!-- -->49 0x00007fc42c123928 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:283:9
#<!-- -->50 0x00007fc41d3bdef0 clang::ParseAST(clang::Sema&amp;, bool, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/Parse/ParseAST.cpp:183:14
#<!-- -->51 0x00007fc4289ec228 clang::ASTFrontendAction::ExecuteAction() /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1192:11
#<!-- -->52 0x00007fc42c12801f clang::CodeGenAction::ExecuteAction() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1147:5
#<!-- -->53 0x00007fc4289ebb41 clang::FrontendAction::Execute() /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1082:38
#<!-- -->54 0x00007fc4288ee589 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1061:42
#<!-- -->55 0x00007fc42e24297b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /export/iusers/mprice1/community1/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:38
#<!-- -->56 0x000000000041df72 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/cc1_main.cpp:232:40
#<!-- -->57 0x0000000000410391 ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/driver.cpp:215:20
#<!-- -->58 0x0000000000410886 clang_main(int, char**, llvm::ToolContext const&amp;) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/driver.cpp:256:26
#<!-- -->59 0x0000000000446cc5 main /export/iusers/mprice1/community1/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:20
#<!-- -->60 0x00007fc4233dae50 __libc_start_call_main (/lib64/libc.so.6+0x44e50)
#<!-- -->61 0x00007fc4233daefc __libc_start_main@<!-- -->GLIBC_2.2.5 (/lib64/libc.so.6+0x44efc)
#<!-- -->62 0x000000000040f7d5 _start (/localdisk2/mprice1/community1/llvm-project/build/bin/clang-19+0x40f7d5)
t.sh: line 1: 3845825 Aborted                 (core dumped) clang-cl "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30154" "-emit-obj" "-mincremental-linker-compatible" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "image_vdb.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-relaxed-aliasing" "-menable-no-infs" "-menable-no-nans" "-fapprox-func" "-funsafe-math-optimizations" "-fno-signed-zeros" "-mreassociate" "-freciprocal-math" "-ffp-contract=fast" "-fno-rounding-math" "-ffast-math" "-ffinite-math-only" "-complex-range=basic" "-mconstructor-aliases" "-fms-volatile" "-funwind-tables=2" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-fdeprecated-macro" "-ferror-limit" "19" "-fopenmp" "-fno-signed-char" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30154" "-std=c++17" "-finline-functions" "-fskip-odr-check-in-gmf" "-fdelayed-template-parsing" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-x" "c++" "t.cpp"

testcase.zip

@sdkrystian
Copy link
Member

The problem here is that we transform the first operand of binary operator& as if it was the operand of the address of operator when unary operator& is overloaded.

@sdkrystian
Copy link
Member

Reduced to:

struct A { 
  int x;
};

void operator&(A);

template<typename T>
struct B {
  bool f() {
    return T::x & 1; // should diagnose this as an invalid id-expression naming a non-static data member per [expr.prim.id.general] p4.
  }
};

template struct B<A>;

@sdkrystian
Copy link
Member

@mikerice1969 Have a fix ready in #97596

@mikerice1969
Copy link
Contributor Author

@mikerice1969 Have a fix ready in #97596

Thanks. Taking a look now.

@mikerice1969
Copy link
Contributor Author

The full preprocessed test also seems to compile okay with this fix. @sdkrystian thanks for the quick fix!

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang:codegen IR generation bugs: mangling, exceptions, etc. labels Jul 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2024

@llvm/issue-subscribers-clang-frontend

Author: Mike Rice (mikerice1969)

Attached test crashes in clang codegen after fd87d76. The test has been creduced from some 600,000+ lines of preprocessed Windows blender code. The crash happens in the same place in the full code (but the expression is used).
t.cpp:66:21: warning: expression result unused [-Wunused-value]
   66 |   void bl() { bf::l &amp;m; }
      |               ~~~~~ ^~
t.cpp:143:6: note: in instantiation of member function 'bk&lt;3&gt;::bl' requested here
  143 |   r-&gt;bl();
      |      ^
t.cpp:133:26: note: in instantiation of function template specialization 'ci&lt;int, int, int, int&gt;::decode&lt;f&gt;' requested here
  133 |           bg-&gt;bc(cz.e(), decode(da));
      |                          ^
t.cpp:117:3: note: in instantiation of function template specialization 'ci&lt;int, int, int, int&gt;::cn&lt;g&gt;' requested here
  117 |   cn(cm);
      |   ^
t.cpp:157:4: note: in instantiation of member function 'ci&lt;int, int, int, int&gt;::operator()' requested here
  157 |   s(bq, db, y, dd);
      |    ^
t.cpp:162:5: note: in instantiation of function template specialization 'de&lt;int, int, int&gt;' requested here
  162 |     de&lt;int, int, int&gt;(df);
      |     ^
t.cpp:87:15: note: in instantiation of function template specialization 'v::operator()&lt;h, h, float, 1&gt;' requested here
   87 |   bt.template operator()&lt;j, j, float, 1&gt;(bq);
      |               ^
t.cpp:168:3: note: in instantiation of function template specialization 'bs&lt;v&gt;' requested here
  168 |   bs(bq, bt);
      |   ^
Unhandled DeclRefExpr
UNREACHABLE executed at /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3180!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang-cl -cc1 -triple x86_64-pc-windows-msvc19.29.30154 -emit-obj -mincremental-linker-compatible -disable-free -clear-ast-before-backend -main-file-name image_vdb.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -menable-no-infs -menable-no-nans -fapprox-func -funsafe-math-optimizations -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -complex-range=basic -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -fdeprecated-macro -ferror-limit 19 -fopenmp -fno-signed-char -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.29.30154 -std=c++17 -finline-functions -fskip-odr-check-in-gmf -fdelayed-template-parsing -vectorize-loops -vectorize-slp -faddrsig -x c++ t.cpp
1.	&lt;eof&gt; parser at end of file
2.	Per-file LLVM IR generation
3.	t.cpp:66:8: Generating code for declaration 'bk&lt;3&gt;::bl'
 #<!-- -->0 0x00007fc423b55f6a llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #<!-- -->1 0x00007fc423b563b2 PrintStackTraceSignalHandler(void*) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #<!-- -->2 0x00007fc423b53ba7 llvm::sys::RunSignalHandlers() /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #<!-- -->3 0x00007fc423b55932 SignalHandler(int) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #<!-- -->4 0x00007fc4233efdb0 __restore_rt (/lib64/libc.so.6+0x59db0)
 #<!-- -->5 0x00007fc42343c42c __pthread_kill_implementation (/lib64/libc.so.6+0xa642c)
 #<!-- -->6 0x00007fc4233efd06 gsignal (/lib64/libc.so.6+0x59d06)
 #<!-- -->7 0x00007fc4233c27d3 abort (/lib64/libc.so.6+0x2c7d3)
 #<!-- -->8 0x00007fc423a3e827 bindingsErrorHandler(void*, char const*, bool) /export/iusers/mprice1/community1/llvm-project/llvm/lib/Support/ErrorHandling.cpp:222:55
 #<!-- -->9 0x00007fc42be3808d clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3181:1
#<!-- -->10 0x00007fc42be2e9fb clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1552:50
#<!-- -->11 0x00007fc42be2e641 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1505:22
#<!-- -->12 0x00007fc42be2e3d9 clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1472:20
#<!-- -->13 0x00007fc42bebdb33 (anonymous namespace)::ScalarExprEmitter::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:255:40
#<!-- -->14 0x00007fc42bebddf9 (anonymous namespace)::ScalarExprEmitter::EmitLoadOfLValue(clang::Expr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:303:32
#<!-- -->15 0x00007fc42bebe9ff (anonymous namespace)::ScalarExprEmitter::VisitDeclRefExpr(clang::DeclRefExpr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:523:30
#<!-- -->16 0x00007fc42bedbd48 clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:456:1
#<!-- -->17 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#<!-- -->18 0x00007fc42bec8530 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:2479:17
#<!-- -->19 0x00007fc42bedd415 clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::VisitImplicitCastExpr(clang::ImplicitCastExpr*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:516:1
#<!-- -->20 0x00007fc42bedbe08 clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:516:1
#<!-- -->21 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#<!-- -->22 0x00007fc42bed95ab clang::CodeGen::CodeGenFunction::EmitPromotedScalarExpr(clang::Expr const*, clang::QualType) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5516:64
#<!-- -->23 0x00007fc42bece645 (anonymous namespace)::ScalarExprEmitter::EmitBinOps(clang::BinaryOperator const*, clang::QualType) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:3467:14
#<!-- -->24 0x00007fc42bec0612 (anonymous namespace)::ScalarExprEmitter::VisitBinAnd(clang::BinaryOperator const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:871:3
#<!-- -->25 0x00007fc42bedb2fb clang::StmtVisitorBase&lt;std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*&gt;::Visit(clang::Stmt*) /export/iusers/mprice1/community1/llvm-project/clang/include/clang/AST/StmtVisitor.h:68:26
#<!-- -->26 0x00007fc42bebe10e (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:422:57
#<!-- -->27 0x00007fc42bed93a5 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5485:1
#<!-- -->28 0x00007fc42be279f2 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:229:23
#<!-- -->29 0x00007fc42be278e8 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGExpr.cpp:204:29
#<!-- -->30 0x00007fc42c077bc4 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef&lt;clang::Attr const*&gt;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGStmt.cpp:130:56
#<!-- -->31 0x00007fc42c078fea clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&amp;, bool, clang::CodeGen::AggValueSlot) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CGStmt.cpp:514:3
#<!-- -->32 0x00007fc42c140cf6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1300:33
#<!-- -->33 0x00007fc42c141cdd clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1526:21
#<!-- -->34 0x00007fc42c172941 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5900:3
#<!-- -->35 0x00007fc42c16aec6 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4100:28
#<!-- -->36 0x00007fc42c166b76 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3197:31
#<!-- -->37 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->38 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->39 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->40 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->41 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->42 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->43 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->44 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->45 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->46 0x00007fc42c166bc4 clang::CodeGen::CodeGenModule::EmitDeferred() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3199:7
#<!-- -->47 0x00007fc42c15a80b clang::CodeGen::CodeGenModule::Release() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:845:23
#<!-- -->48 0x00007fc42c3240a5 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:291:11
#<!-- -->49 0x00007fc42c123928 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:283:9
#<!-- -->50 0x00007fc41d3bdef0 clang::ParseAST(clang::Sema&amp;, bool, bool) /export/iusers/mprice1/community1/llvm-project/clang/lib/Parse/ParseAST.cpp:183:14
#<!-- -->51 0x00007fc4289ec228 clang::ASTFrontendAction::ExecuteAction() /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1192:11
#<!-- -->52 0x00007fc42c12801f clang::CodeGenAction::ExecuteAction() /export/iusers/mprice1/community1/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1147:5
#<!-- -->53 0x00007fc4289ebb41 clang::FrontendAction::Execute() /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1082:38
#<!-- -->54 0x00007fc4288ee589 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) /export/iusers/mprice1/community1/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1061:42
#<!-- -->55 0x00007fc42e24297b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /export/iusers/mprice1/community1/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:38
#<!-- -->56 0x000000000041df72 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/cc1_main.cpp:232:40
#<!-- -->57 0x0000000000410391 ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/driver.cpp:215:20
#<!-- -->58 0x0000000000410886 clang_main(int, char**, llvm::ToolContext const&amp;) /export/iusers/mprice1/community1/llvm-project/clang/tools/driver/driver.cpp:256:26
#<!-- -->59 0x0000000000446cc5 main /export/iusers/mprice1/community1/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:20
#<!-- -->60 0x00007fc4233dae50 __libc_start_call_main (/lib64/libc.so.6+0x44e50)
#<!-- -->61 0x00007fc4233daefc __libc_start_main@<!-- -->GLIBC_2.2.5 (/lib64/libc.so.6+0x44efc)
#<!-- -->62 0x000000000040f7d5 _start (/localdisk2/mprice1/community1/llvm-project/build/bin/clang-19+0x40f7d5)
t.sh: line 1: 3845825 Aborted                 (core dumped) clang-cl "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30154" "-emit-obj" "-mincremental-linker-compatible" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "image_vdb.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-relaxed-aliasing" "-menable-no-infs" "-menable-no-nans" "-fapprox-func" "-funsafe-math-optimizations" "-fno-signed-zeros" "-mreassociate" "-freciprocal-math" "-ffp-contract=fast" "-fno-rounding-math" "-ffast-math" "-ffinite-math-only" "-complex-range=basic" "-mconstructor-aliases" "-fms-volatile" "-funwind-tables=2" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-fdeprecated-macro" "-ferror-limit" "19" "-fopenmp" "-fno-signed-char" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30154" "-std=c++17" "-finline-functions" "-fskip-odr-check-in-gmf" "-fdelayed-template-parsing" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-x" "c++" "t.cpp"

testcase.zip

kbluck pushed a commit to kbluck/llvm-project that referenced this issue Jul 6, 2024
…nary operator& (llvm#97596)

Currently, `TreeTransform::TransformCXXOperatorCallExpr` calls
`TreeTransform::TransformAddressOfOperand` to transform the first
operand of a `CXXOperatorCallExpr` when its `OverloadOperatorKind` is
`OO_Amp` -- regardless of arity. This results in the first operand of
binary `operator&` being incorrectly transformed as if it was the
operand of the address of operator in cases such as the following:
```
struct A {
  int x;
};

void operator&(A, A);

template<typename T>
struct B {
  int f() {
    return T::x & 1; // invalid reference to 'A::x' is not diagnosed because 'T::x' is incorrectly transformed as if it was the operand of unary operator&
  }
};

template struct B<A>;
```
Prior to llvm#92318 we would build a `CXXDependentScopeMemberExpr` for
`T::x` (as with most dependent qualified names that were not member
qualified names). Since `TreeTransform::TransformAddressOfOperand` only
differs from `TransformExpr` for `DependentScopeDeclRefExpr` and
`UnresolvedLookupExpr` operands, `T::x` was transformed "correctly". Now
that we build a `DependentScopeDeclRefExpr` for `T::x`, it is
incorrectly transformed as if it was the operand of the address of
operator and we fail to diagnose the invalid reference to a non-static
data member. This patch fixes the issue by only calling
`TreeTransform::TransformAddressOfOperand` for `CXXOperatorCallExpr`s
with a single operand. This fixes llvm#97483.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
4 participants