<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62868>62868</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] __builtin_assume_aligned causes clang crash
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yronglin
      </td>
    </tr>
</table>

<pre>
    https://godbolt.org/z/Wse93MM6d

```
struct A { int n; };
struct B { int n; };
struct C : A, B {};

void *f(C *c) {
  return __builtin_assume_aligned((B*)c, 8);
}

extern "C" int printf(const char *, ...);

int main() {
    C c;
 printf("%p\n", f(&c));
    return 0;
}
```

```
clang-17: /root/llvm-project/llvm/lib/IR/Instructions.cpp:1624: void llvm::StoreInst::AssertOK(): Assertion `cast<PointerType>(getOperand(1)->getType()) ->isOpaqueOrPointeeTypeMatches(getOperand(0)->getType()) && "Ptr must be a pointer to Val type!"' 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: /opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20230522/lib/clang/17 -D FOO -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0/backward -internal-isystem /opt/compiler-explorer/clang-assertions-trunk-20230522/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/app -ferror-limit 19 -fsanitize=alignment -fsanitize-recover=alignment -fno-sanitize-memory-param-retval -fno-sanitize-address-use-odr-indicator -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -no-opaque-pointers -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-076b96.o -x c++ <source>
1.      <source>:9:1: current parser token 'extern'
2.      <source>:5:7: LLVM IR generation of declaration 'f'
3.      <source>:5:7: Generating code for declaration 'f'
 #0 0x000055f17324d6ff llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3baa6ff)
 #1 0x000055f17324ae54 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fcea04b2420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007fce9ff7f00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007fce9ff5e859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007fce9ff5e729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007fce9ff6ffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x000055f172b6fff0 llvm::StoreInst::AssertOK() (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x34ccff0)
 #8 0x000055f172b701e7 llvm::StoreInst::StoreInst(llvm::Value*, llvm::Value*, bool, llvm::Align, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x34cd1e7)
 #9 0x000055f173565def clang::CodeGen::CGBuilderTy::CreateStore(llvm::Value*, clang::CodeGen::Address, bool) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3ec2def)
#10 0x000055f17356fdb8 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3eccdb8)
#11 0x000055f1735775ab clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3ed45ab)
#12 0x000055f17357e044 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3edb044)
#13 0x000055f1735de00a clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3f3b00a)
#14 0x000055f1735f1dff clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3f4edff)
#15 0x000055f1736521c9 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3faf1c9)
#16 0x000055f17364d155 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3faa155)
#17 0x000055f17364dd28 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x3faad28)
#18 0x000055f173656c33 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#19 0x000055f174488de9 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#20 0x000055f1744792c0 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x4dd62c0)
#21 0x000055f17597ef84 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x62dbf84)
#22 0x000055f174485b58 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x4de2b58)
#23 0x000055f173ce1049 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x463e049)
#24 0x000055f173c65ef6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x45c2ef6)
#25 0x000055f173dc3a96 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x4720a96)
#26 0x000055f170726dfc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x1083dfc)
#27 0x000055f170722b1a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x000055f1707240fc clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x10810fc)
#29 0x000055f17062c2a5 main (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0xf892a5)
#30 0x00007fce9ff60083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x000055f17071d8fe _start (/opt/compiler-explorer/clang-assertions-trunk-20230522/bin/clang-17+0x107a8fe)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
x86-64 clang (assertions trunk) - 1707ms
LLVM IR Viewer x86-64 clang (assertio
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWl1v2zyy_jXMDUFDoj59kQvHjrvFadGiKfpeGhQ5UriVSB2SSp399Qek5NhynbbZs168QOpaY-rhPDPDmaFEZq1sFMAtyu5Qtrlhg3vU5vbZaNW0Ut1UWjzfPjrXW5SsEN0ium20qHTrFto0iG7_hej2LwvL5OPHXKBog6LV9JlH01-4tM4M3OEVRsUdlsphhZI7jIoNSu5mI-5-O2KNUbLCK0TX4-DTIePnk5YCI7qqES3X_gtHdBmGhp8xNuAGo_BuVw2ydVLtmLVDBzvWemsIREtEyztEV4guuZ-oRHR5nKTYnM4GewdGYUTpGlEaVO-NVM7PzrWyDvNHZnBAW-PFYjHDCp_-no5JFSaeaYrxGvOX0UdgRCmiWY-ytQpf13iU5p7q6QQeYqIbXWAw99JFIW-ZakhceKsjujVaO0S3bfvUkd7ofwI_XPr_ZIXo9v0X_6FGf0mt7IL3PUpWcU5TjxL8E-5IVihZPThtwA8fL1fWgnGf_mc0RvB1kEitMMojzvzA9WctlQPz9bkHlNwjWjbgPvVgmPLuixFdEpTcN-DCiBGKLrEXSvupZ_87wCczgoAf8pE5_gj2HCh6DQjRHNHce_2zM7gbrMMVYIb7US_sNP7GWuzCTXHwUYFrJlsQi9Gunz_crx7usR2qTjrMcDU02ECvjfM3ny066R6HasF1d2LruQektYPXf4uZElgq3g4CsHsEzA2zj7hi_LszjIMPlt5AbzQHa0Fgqwcziv2dzFrNJXMgsBkUttzI3k0qPzjGv2MxdN6boyhaoGj52ejGsA4z0wwdKGenWNG914zrrp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