LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 8406 - ASSERT: "Alignment must be power of 2" when using precompiled headers
Summary: ASSERT: "Alignment must be power of 2" when using precompiled headers
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks: 5881
  Show dependency tree
 
Reported: 2010-10-18 09:02 PDT by Tor Arne Vestbø
Modified: 2010-10-18 14:21 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tor Arne Vestbø 2010-10-18 09:02:12 PDT
The following testcase will cause clang to assert when using precompiled headers:

foo.cpp:

void foo() {
    Bar bar;
}

foo.h:

struct Bar
{
    int buffer[123] __attribute__((__aligned__(4)));
};

http://gist.github.com/632128

Assertion failed: (Align && (Align & (Align-1)) == 0 && "Alignment must be power of 2"), function getTypeInfo, file /Users/torarne/dev/llvm/clang/lib/AST/ASTContext.cpp, line 845.
0  clang             0x00000001013aee62 PrintStackTrace(void*) + 34
1  clang             0x00000001013afcb3 SignalHandler(int) + 707
2  libSystem.B.dylib 0x00007fff8013135a _sigtramp + 26
3  libSystem.B.dylib 0x0000000102119ec8 _sigtramp + 2180942728
4  clang             0x000000010001cca2 __assert_rtn + 66
5  clang             0x000000010071cf1f clang::ASTContext::getTypeInfo(clang::Type const*) + 319
6  clang             0x000000010071dc88 clang::ASTContext::getPreferredTypeAlign(clang::Type const*) + 24
7  clang             0x000000010071e229 clang::ASTContext::getDeclAlign(clang::Decl const*, bool) + 1161
8  clang             0x00000001001b9a13 clang::CodeGen::CodeGenFunction::EmitLocalBlockVarDecl(clang::VarDecl const&, void (*)(clang::CodeGen::CodeGenFunction&, clang::VarDecl const&, llvm::Value*)) + 67
9  clang             0x00000001001bc6ef clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) + 191
10 clang             0x0000000100269dbb clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) + 171
11 clang             0x000000010026d5f7 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*) + 167
12 clang             0x000000010026a3f0 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) + 48
13 clang             0x000000010026d36b clang::CodeGen::CodeGenFunction::EmitCompoundStmt(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) + 283
14 clang             0x000000010026d712 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*) + 450
15 clang             0x000000010026a3f0 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) + 48
16 clang             0x0000000100293c98 clang::CodeGen::CodeGenFunction::GenerateCode(clang::CodeGen::GlobalDecl, llvm::Function*) + 1160
17 clang             0x000000010029e72b clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::CodeGen::GlobalDecl) + 715
18 clang             0x00000001002a257b clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::CodeGen::GlobalDecl) + 395
19 clang             0x00000001002a26f6 clang::CodeGen::CodeGenModule::EmitGlobal(clang::CodeGen::GlobalDecl) + 150
20 clang             0x00000001002a332f clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 895
21 clang             0x00000001002c3f1c (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 60
22 clang             0x000000010028c4ab (anonymous namespace)::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 155
23 clang             0x00000001002d0476 clang::ParseAST(clang::Sema&, bool) + 182
24 clang             0x000000010028cd2c clang::CodeGenAction::ExecuteAction() + 60
25 clang             0x00000001000525f9 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 393
26 clang             0x00000001000264fe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1614
27 clang             0x000000010001e53e cc1_main(char const**, char const**, char const*, void*) + 510
28 clang             0x0000000100025074 main + 4884
29 clang             0x000000010001cf78 start + 52
Stack dump:
0.      Program arguments: /Users/torarne/build/llvm/Release+Asserts/bin/clang -cc1 -triple x86_64-apple-darwin10.0.0 -emit-obj -mrelax-all -disable-free -main-file-name foo.cpp -pic-level 1 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 97.14 -resource-dir /Users/torarne/build/llvm/Release+Asserts/lib/clang/2.9 -include-pch foo.h.pch -ferror-limit 19 -fmessage-length 266 -stack-protector 1 -fblocks -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o foo.clang.o -x c++ foo.cpp 
1.      <eof> parser at end of file
2.      foo.cpp:2:6: LLVM IR generation of declaration 'foo'
3.      foo.cpp:2:6: Generating code for declaration 'foo'
4.      foo.cpp:2:12: LLVM IR generation of compound statement ('{}')
clang: error: clang frontend command failed due to signal 4 (use -v to see invocation)

Looking briefly at the code in a debugger it seems it thinks the alignement is 123, the size of the buffer, not 4, what's passed to __aligned__()

clang version 2.9 (git://repo.or.cz/clang.git 4449662e4b0482d42bcdae68cd767559879d762d)
Target: x86_64-apple-darwin10
Thread model: posix

Reproducible on both OSX and Linux.
Comment 1 Argyrios Kyrtzidis 2010-10-18 12:00:24 PDT
I can't reproduce it, could you try latest clang ?
Comment 2 Argyrios Kyrtzidis 2010-10-18 12:02:40 PDT
Oops, scratch that, I see it. On it...
Comment 3 Tor Arne Vestbø 2010-10-18 12:07:11 PDT
(In reply to comment #2)
> Oops, scratch that, I see it. On it...

Thanks!
Comment 4 Argyrios Kyrtzidis 2010-10-18 14:21:35 PDT
Fixed at r116737.