Skip to content

[clang] PCH generation fails with pragma pack inside templated function #60543

@DHowett

Description

@DHowett

During PCH generation/the compilation of a C++ header, a pragma pack inside a templated function will cause an assertion failure.

Assertion failed: !isAnnotation() && "Annotation tokens have no length field", file \antares\ephemeral\llvm-project\clang\include\clang/Lex/Token.h, line 129

Repro File (mr.hh)

template<int v> // must be templated
void func()
{
#pragma pack(push, 1)
    // anything, nothing
#pragma pack(pop)
}

Repro Steps

> clang++ mr.hh

Output

Assertion failed: !isAnnotation() && "Annotation tokens have no length field", file \antares\ephemeral\llvm-project\clang\include\clang/Lex/Token.h, line 129
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: C:\\Users\\Dustin\\AppData\\Local\\Temp\\c\\bin\\clang-cl.exe mr.hh
1.      <eof> parser at end of file
Exception Code: 0x80000003
 #0 0x00007ff6d1f6c55c HandleAbort \\antares\ephemeral\llvm-project\llvm\lib\Support\Windows\Signals.inc:414:0
 #1 0x00007fff78a290ed (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa90ed)
 #2 0x00007fff78a2ae49 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xaae49)
 #3 0x00007fff78a31345 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb1345)
 #4 0x00007fff78a30bd7 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb0bd7)
 #5 0x00007fff78a2eba1 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xaeba1)
 #6 0x00007fff78a318af (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb18af)
 #7 0x00007ff6d39669c1 clang::Token::getLength(void) const \\antares\ephemeral\llvm-project\clang\include\clang\Lex\Token.h:129:0
 #8 0x00007ff6d3b1cc71 clang::ASTWriter::AddToken(class clang::Token const &, class llvm::SmallVectorImpl<unsigned __int64> &) \\antares\ephemeral\llvm-project\clang\lib\Serialization\ASTWriter.cpp:4378:0
 #9 0x00007ff6d3b1835b clang::ASTWriter::WriteLateParsedTemplates(class clang::Sema &) \\antares\ephemeral\llvm-project\clang\lib\Serialization\ASTWriter.cpp:4240:0
#10 0x00007ff6d3b1b250 clang::ASTWriter::WriteASTCore(class clang::Sema &, class llvm::StringRef, class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> const &, class clang::Module *) \\antares\ephemeral\llvm-project\clang\lib\Serialization\ASTWriter.cpp:4911:0
#11 0x00007ff6d3b1ca85 clang::ASTWriter::WriteAST(class clang::Sema &, class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> const &, class clang::Module *, class llvm::StringRef, bool, bool) \\antares\ephemeral\llvm-project\clang\lib\Serialization\ASTWriter.cpp:4506:0
#12 0x00007ff6d3af4edd clang::PCHGenerator::HandleTranslationUnit(class clang::ASTContext &) \\antares\ephemeral\llvm-project\clang\lib\Serialization\GeneratePCH.cpp:68:0

Real-world applicability

Windows' <TraceLoggingActivity.h> emits code that looks like this. This minimal repro was generated from that case.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crashPrefer [crash-on-valid] or [crash-on-invalid]

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions