Issue 241856
Summary Clang crashes, with modules and auto.
Labels clang
Assignees
Reporter DenisYaroshevskiy
    Reproduction on godbolt: 
https://godbolt.org/z/Kr1YdG5dd

Below is the explanation from AI

# Clang crash in CodeGen with C++20 modules: `auto` member function of a class template

Clang segfaults during IR generation on valid code. CodeGen emits a call to
`Inner<unsigned long>::size()`, but on the declaration it uses, the `auto` return type
was never deduced. Clang then reads a null type while classifying the return type.

Godbolt: [<link>](https://godbolt.org/z/Kr1YdG5dd)

## Reproducer

### CMakeLists.txt
```cmake
cmake_minimum_required(VERSION 3.28)
project(repro CXX)
set(CMAKE_CXX_STANDARD 20)
add_library(repro OBJECT main.cpp)
target_sources(repro PUBLIC FILE_SET CXX_MODULES FILES
 table.cppm use_size.cppm holder.cppm user.cppm)
```

### table.cppm
```cpp
export module table;
export template <class> struct Inner {
  auto size() { return 0; }
};
export template <class T> struct Table {
  Inner<decltype(sizeof(T))> inner;
  constexpr Table() { size(); }
  void size() { inner.size(); }
};
```

### use_size.cppm
```cpp
export module use_size;
import table;
export inline void useSize(Table<int>& t) { t.size(); }
```

### holder.cppm
```cpp
export module holder;
export import table;
export struct Holder { Table<int> t; };
```

### user.cppm
```cpp
export module user;
import use_size;
import holder;
export struct A { Table<char> t{}; };
```

### main.cpp
```cpp
import holder;
struct B { Table<char> t{}; };
import user;
void f() { B b; }
```

## Crash
```
Per-file LLVM IR generation
table.cppm:8:8: Generating code for declaration 'Table<char>::size'
 clang::QualType::getTypePtr() const
 clang::CodeGen::isAggregateTypeForABI(clang::QualType)
 X86_64ABIInfo::classifyReturnType(clang::QualType) const
 clang::CodeGen::CodeGenTypes::arrangeCXXMethodDeclaration(clang::CXXMethodDecl const*)
 clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(...)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to