Issue 130849
Summary Clang crashes when processing pragma diagnostic directives with quoted warning names for attribute-alias
Labels clang
Assignees
Reporter bi6c
    Compiler Explorer: [https://godbolt.org/z/WGzd4KPaq](https://godbolt.org/z/WGzd4KPaq)

(Generated by fuzzer)

When compiling code that uses pragma diagnostic directives with quoted warning names for `-Wattribute-alias`, Clang crashes during code generation. 

**Code:**
```c
#define ATTR(...) __attribute__((__VA_ARGS__))

void target_no_nothrow(void)
{}

ATTR(alias("target_no_nothrow"), nothrow)
void alias_nothrow(void);

#pragma GCC diagnostic push "-Wattribute-alias"
#pragma GCC diagnostic ignored "-Wattribute-alias"
ATTR(alias("target_no_nothrow"), nothrow) void alias_nothrow_ignored(void);
#pragma GCC diagnostic pop "-Wattribute-alias"

ATTR(pure) int alias_pure(void);

int target_no_pure(void)
{
  return 0;
}

ATTR(alias("target_no_pure"))
int alias_pure(void);

ATTR(const) int alias_const(void);

int target_pure(void)
{
  return 0;
}

ATTR(alias("target_pure"))
int __attribute__((target_clones("default,avx"))) alias_const(void);

typedef int F(void);

ATTR(pure, leaf) F *resolve_to_const(void) { return alias_const; }

ATTR(ifunc("resolve_to_const")) F alias_no_const_ifunc;
ATTR(const, ifunc("resolve_to_const")) F alias_const_ifunc;
ATTR(ifunc("resolve_to_const")) int alias_no_leaf_ifunc(void);
```


**The compiler crashes with the following error and stack trace:**

```c
<source>:9:29: warning: unexpected token in pragma diagnostic [-Wunknown-pragmas]
    9 | #pragma GCC diagnostic push "-Wattribute-alias"
      | ^
<source>:10:32: warning: unknown warning group '-Wattribute-alias', ignored [-Wunknown-warning-option]
   10 | #pragma GCC diagnostic ignored "-Wattribute-alias"
      | ^
<source>:12:28: warning: unexpected token in pragma diagnostic [-Wunknown-pragmas]
   12 | #pragma GCC diagnostic pop "-Wattribute-alias"
      |                            ^
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: /opt/compiler-explorer/clang-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
 #0 0x0000000003b5bb38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3b5bb38)
 #1 0x0000000003b59c7c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3b59c7c)
 #2 0x0000000003aa9008 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000078e971e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000000000406a532 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x406a532)
 #5 0x0000000004078118 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4078118)
 #6 0x00000000040d27ab clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x40d27ab)
 #7 0x00000000040d4039 clang::CodeGen::CodeGenModule::emitMultiVersionFunctions()::'lambda0'(clang::FunctionDecl const*)::operator()(clang::FunctionDecl const*) const CodeGenModule.cpp:0:0
 #8 0x0000000006f79b0a clang::ASTContext::forEachMultiversionedFunctionVersion(clang::FunctionDecl const*, llvm::function_ref<void (clang::FunctionDecl*)>) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x6f79b0a)
 #9 0x00000000040d97b5 clang::CodeGen::CodeGenModule::emitMultiVersionFunctions() (/opt/compiler-explorer/clang-trunk/bin/clang+0x40d97b5)
#10 0x00000000040db6b0 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-trunk/bin/clang+0x40db6b0)
#11 0x00000000044d8eae (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#12 0x00000000044d5edd clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x44d5edd)
#13 0x000000000604fdec clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x604fdec)
#14 0x00000000044d6835 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x44d6835)
#15 0x00000000047b1a61 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x47b1a61)
#16 0x000000000473269b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x473269b)
#17 0x000000000489ea03 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x489ea03)
#18 0x0000000000d66f81 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xd66f81)
#19 0x0000000000d5f6ed ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#20 0x0000000004523209 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#21 0x0000000003aa9433 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3aa9433)
#22 0x0000000004523429 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#23 0x00000000044e6dbd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x44e6dbd)
#24 0x00000000044e7d51 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x44e7d51)
#25 0x00000000044f210c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x44f210c)
#26 0x0000000000d63ba1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xd63ba1)
#27 0x0000000000c252e4 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xc252e4)
#28 0x000078e971e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#29 0x000078e971e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#30 0x0000000000d5f185 _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xd5f185)
clang: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to