Issue 123249
Summary [clang] Compiler crash with "echo 'a; b() { __atomic_test_and_set(a, b); }' | ./clang -cc1 -emit-llvm -o -"
Labels clang
Assignees
Reporter thurstond
    Using clang built from today's source:
```
commit a98df676140c9b3e44f6e094df40d49f53e9a89c (HEAD -> main, upstream/main, upstream/HEAD)
Date:   Thu Jan 16 14:00:42 2025 -0800
```
and running this command:
```
$ echo 'a; b() { __atomic_test_and_set(a, b); }' | ./clang -cc1 -emit-llvm -o -
```

crashes the compiler:
```
<stdin>:1:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    1 | a; b() { __atomic_test_and_set(a, b); }
      | ^
      | int
<stdin>:1:4: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    1 | a; b() { __atomic_test_and_set(a, b); }
      |    ^
      |    int
<stdin>:1:32: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'volatile void *' [-Wint-conversion]
    1 | a; b() { __atomic_test_and_set(a, b); }
      | ^
<stdin>:1:35: error: incompatible pointer to integer conversion passing 'int ()' to parameter of type 'int' [-Wint-conversion]
    1 | a; b() { __atomic_test_and_set(a, b); }
      | ^
clang: /usr/local/google/home/thurston/llvm-projectG/clang/include/clang/AST/Type.h:8810: const T *clang::Type::castAs() const [T = clang::PointerType]: Assertion `isa<T>(CanonicalType)' failed.
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: /usr/local/google/home/thurston/llvm-projectG/build/bin/clang -cc1 -emit-llvm -o -
1.	<eof> parser at end of file
2.	<stdin>:1:4: LLVM IR generation of declaration 'b'
3.	<stdin>:1:4: Generating code for declaration 'b'
 #0 0x00005608f980d9a1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/thurston/llvm-projectG/llvm/lib/Support/Unix/Signals.inc:798:11
 #1 0x00005608f980de9b PrintStackTraceSignalHandler(void*) /usr/local/google/home/thurston/llvm-projectG/llvm/lib/Support/Unix/Signals.inc:874:1
 #2 0x00005608f980be96 llvm::sys::RunSignalHandlers() /usr/local/google/home/thurston/llvm-projectG/llvm/lib/Support/Signals.cpp:105:5
 #3 0x00005608f980e635 SignalHandler(int) /usr/local/google/home/thurston/llvm-projectG/llvm/lib/Support/Unix/Signals.inc:415:1
 #4 0x00007f0859056590 (/lib/x86_64-linux-gnu/libc.so.6+0x3f590)
 #5 0x00007f08590a53ac __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f08590564f2 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f085903f4ed abort ./stdlib/abort.c:81:7
 #8 0x00007f085903f415 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007f085904f012 (/lib/x86_64-linux-gnu/libc.so.6+0x38012)
#10 0x00005608f9df5bb3 clang::PointerType const* clang::Type::castAs<clang::PointerType>() const /usr/local/google/home/thurston/llvm-projectG/clang/include/clang/AST/Type.h:0:3
#11 0x00005608fa372b7f clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGBuiltin.cpp:5135:16
#12 0x00005608f9de34d2 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGExpr.cpp:5607:12
#13 0x00005608f9e97918 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGExprScalar.cpp:627:36
#14 0x00005608f9e8e871 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /usr/local/google/home/thurston/llvm-projectG/build/tools/clang/include/clang/AST/StmtNodes.inc:614:1
#15 0x00005608f9e83435 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGExprScalar.cpp:448:52
#16 0x00005608f9e8326a clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGExprScalar.cpp:5590:3
#17 0x00005608f9dc03e9 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGExpr.cpp:242:24
#18 0x00005608f9dc0299 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGExpr.cpp:217:5
#19 0x00005608f9fc7540 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGStmt.cpp:129:5
#20 0x00005608f9fd1901 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CGStmt.cpp:560:3
#21 0x00005608fa0888e3 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenFunction.cpp:1360:5
#22 0x00005608fa0897ce clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenFunction.cpp:1587:3
#23 0x00005608fa0c0eab clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenModule.cpp:6115:3
#24 0x00005608fa0b728c clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenModule.cpp:4243:12
#25 0x00005608fa0bca8a clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenModule.cpp:3954:5
#26 0x00005608fa0b598a clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenModule.cpp:7000:5
#27 0x00005608fa78476d (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/ModuleBuilder.cpp:189:73
#28 0x00005608fa771929 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenAction.cpp:169:8
#29 0x00005608fd9593c9 clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/thurston/llvm-projectG/clang/lib/Parse/ParseAST.cpp:175:11
#30 0x00005608faa7a191 clang::ASTFrontendAction::ExecuteAction() /usr/local/google/home/thurston/llvm-projectG/clang/lib/Frontend/FrontendAction.cpp:1188:1
#31 0x00005608fa7765a0 clang::CodeGenAction::ExecuteAction() /usr/local/google/home/thurston/llvm-projectG/clang/lib/CodeGen/CodeGenAction.cpp:1101:5
#32 0x00005608faa79ba6 clang::FrontendAction::Execute() /usr/local/google/home/thurston/llvm-projectG/clang/lib/Frontend/FrontendAction.cpp:1076:7
#33 0x00005608fa99278e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /usr/local/google/home/thurston/llvm-projectG/clang/lib/Frontend/CompilerInstance.cpp:1056:23
#34 0x00005608fac602d7 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /usr/local/google/home/thurston/llvm-projectG/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:296:8
#35 0x00005608f57c552a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /usr/local/google/home/thurston/llvm-projectG/clang/tools/driver/cc1_main.cpp:290:13
#36 0x00005608f57b7ff2 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /usr/local/google/home/thurston/llvm-projectG/clang/tools/driver/driver.cpp:218:5
#37 0x00005608f57b6d3b clang_main(int, char**, llvm::ToolContext const&) /usr/local/google/home/thurston/llvm-projectG/clang/tools/driver/driver.cpp:259:5
#38 0x00005608f57eb3e5 main /usr/local/google/home/thurston/llvm-projectG/build/tools/clang/tools/driver/clang-driver.cpp:17:3
#39 0x00007f0859040c8a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#40 0x00007f0859040d45 call_init ./csu/../csu/libc-start.c:128:20
#41 0x00007f0859040d45 __libc_start_main ./csu/../csu/libc-start.c:347:5
#42 0x00005608f57b67c1 _start (/usr/local/google/home/thurston/llvm-projectG/build/bin/clang+0x1e067c1)
Aborted
```

It crashes without dumping preprocessed source or a run script (though the reproducer above is already creduce'd).

---------------------------------------

## Partial bisection

The same crash occurs with:
```
commit 1a0d0ae234544dc4978f1e12730408cb83f6b923 (HEAD)
Author: Owen Pan <owenpi...@gmail.com>
Date:   Wed Jan 1 18:24:56 2025 -0800
```

clang built from source a month ago does not crash:
```
commit 954e3e4096c4e45baf5470aa678a0fee96db7691 (HEAD -> main)
Date:   Thu Dec 19 18:46:38 2024 +0000
```
```
<stdin>:1:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    1 | a; b() { __atomic_test_and_set(a, b); }
      | ^
      | int
<stdin>:1:4: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
    1 | a; b() { __atomic_test_and_set(a, b); }
      |    ^
      | int
<stdin>:1:32: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'volatile void *' [-Wint-conversion]
    1 | a; b() { __atomic_test_and_set(a, b); }
      | ^
<stdin>:1:35: error: incompatible pointer to integer conversion passing 'int ()' to parameter of type 'int' [-Wint-conversion]
    1 | a; b() { __atomic_test_and_set(a, b); }
      | ^
4 errors generated.
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to