llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-cl] Cannot compile a nested struct with member named `std::string Name;`

Open Nemirtingas opened this issue 1 year ago • 8 comments

Hi,

I encountered an issue where clang-cl and clang couldn't compile some code, I Attached reproductible source. If I remove std::string name; from Struct2_t, it compiles, or you could place the std::string in a struct outside Struct1_t and it will also work.

You can compile this code using my docker image: nemirtingas/windowscross_vcpkg:msvc2022_14.40.33807_win10.0.18362.0_clang18, this issue is about clang 19 but I first discovered it in clang 18 and the issue seems to be the same.

main.zip

Nemirtingas avatar Apr 21 '25 20:04 Nemirtingas

@llvm/issue-subscribers-clang-frontend

Author: Nemirtingas (Nemirtingas)

Hi,

I encountered an issue where clang-cl and clang couldn't compile some code, I Attached reproductible source. If I remove std::string name; from Struct2_t, it compiles, or you could place the std::string in a struct outside Struct1_t and it will also work.

You can compile this code using my docker image: nemirtingas/windowscross_vcpkg:msvc2022_14.40.33807_win10.0.18362.0_clang18, this issue is about clang 19 but I first discovered it in clang 18 and the issue seems to be the same.

main.zip

llvmbot avatar Apr 21 '25 21:04 llvmbot

Test case asserts here:

clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ASTContext.cpp:2424: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type*) const: Assertion `!A->getDeducedType().isNull() && "cannot request the size of an undeduced or dependent auto 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/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 -target i686-unknown-windows-msvc19.11.0 -D_MT -DNDEBUG -O3 -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++17 -D_CRT_SECURE_NO_WARNINGS <source>
1.	<eof> parser at end of file
2.	/tmp/main.cpp:25:5: LLVM IR generation of declaration 'main'
3.	/tmp/main.cpp:25:5: Generating code for declaration 'main'
4.	/tmp/main.cpp:30:5: LLVM IR generation of compound statement ('{}')
 #0 0x0000000003ef1228 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ef1228)
 #1 0x0000000003eeeeb4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3eeeeb4)
 #2 0x0000000003e339e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000076020cc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000076020cc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000076020cc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000076020cc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000076020cc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000076020cc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000007464ead clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7464ead)
#10 0x000000000744dec7 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x744dec7)
#11 0x000000000746697b clang::ASTContext::getPreferredTypeAlign(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x746697b)
#12 0x000000000746748b clang::ASTContext::getDeclAlign(clang::Decl const*, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x746748b)
#13 0x00000000047e8dae clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47e8dae)
#14 0x00000000047ed5eb clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#15 0x00000000047eddf7 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47eddf7)
#16 0x00000000043b993c clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43b993c)
#17 0x00000000043cf752 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf752)
#18 0x00000000043c7205 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43c7205)
#19 0x00000000043cf1ec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf1ec)
#20 0x00000000043cf5fd clang::CodeGen::CodeGenFunction::EmitCompoundStmt(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf5fd)
#21 0x00000000043cf7c5 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf7c5)
#22 0x00000000043c7205 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43c7205)
#23 0x00000000043ce925 clang::CodeGen::CodeGenFunction::EmitIfStmt(clang::IfStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43ce925)
#24 0x00000000043c74c0 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43c74c0)
#25 0x00000000043cf1ec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf1ec)
#26 0x00000000044350a2 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44350a2)
#27 0x0000000004448455 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4448455)

zygoloid avatar Apr 21 '25 22:04 zygoloid

Substantially reduced testcase. (I'm done looking at this for now, if someone wants to take over.)

zygoloid avatar Apr 21 '25 22:04 zygoloid

@llvm/issue-subscribers-clang-codegen

Author: Nemirtingas (Nemirtingas)

Hi,

I encountered an issue where clang-cl and clang couldn't compile some code, I Attached reproductible source. If I remove std::string name; from Struct2_t, it compiles, or you could place the std::string in a struct outside Struct1_t and it will also work.

You can compile this code using my docker image: nemirtingas/windowscross_vcpkg:msvc2022_14.40.33807_win10.0.18362.0_clang18, this issue is about clang 19 but I first discovered it in clang 18 and the issue seems to be the same.

main.zip

llvmbot avatar Apr 22 '25 14:04 llvmbot

@llvm/issue-subscribers-c-20

Author: Nemirtingas (Nemirtingas)

Hi,

I encountered an issue where clang-cl and clang couldn't compile some code, I Attached reproductible source. If I remove std::string name; from Struct2_t, it compiles, or you could place the std::string in a struct outside Struct1_t and it will also work.

You can compile this code using my docker image: nemirtingas/windowscross_vcpkg:msvc2022_14.40.33807_win10.0.18362.0_clang18, this issue is about clang 19 but I first discovered it in clang 18 and the issue seems to be the same.

main.zip

llvmbot avatar Apr 22 '25 14:04 llvmbot

#include <iostream>
int main()
{
    auto a = new auto(cin.get());
    *a=' ';
    delete a;
    return 0;
}

Also get same Assertion and stack

mariete1223 avatar May 10 '25 15:05 mariete1223

Smaller repro. Dates back to clang 11.0.0, not reproducible in 10.0.0.

struct Outer {
    template<class T> struct Stat { int Value = 0; };
    static constexpr bool b = std::is_constructible<Stat<void>>::value;
};

Outer::Stat<void> *f();

int main() { return f()->Value; }

timofey256 avatar Jun 16 '26 21:06 timofey256

Fixed in trunk

shafik avatar Oct 23 '26 01:10 shafik