Skip to content

Clang crashes, with modules and auto. #241856

Open

Description

@DenisYaroshevskiy

Reproduction on godbolt:
trunk https://godbolt.org/z/Kr1YdG5dd
23.1.0: https://godbolt.org/z/z9vr9PW4v

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:

Reproducer

CMakeLists.txt

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

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

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

holder.cppm

export module holder;
export import table;
export struct Holder { Table<int> t; };

user.cppm

export module user;
import use_size;
import holder;
export struct A { Table<char> t{}; };

main.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(...)

Activity

  1. added
    clang:modulesC++20 modules and Clang Header Modules
    and removed
    clangClang issues not falling into any other category
    on Nov 12, 2026
  2. llvmorg-github-actions commented on Nov 12, 2026

    @llvmorg-github-actions

    @llvm/issue-subscribers-clang-modules

    Author: Denis Yaroshevskiy (DenisYaroshevskiy)

    Details Reproduction on godbolt: trunk https://godbolt.org/z/Kr1YdG5dd 23.1.0: https://godbolt.org/z/z9vr9PW4v

    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&lt;unsigned long&gt;::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>

    Reproducer

    CMakeLists.txt

    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

    export module table;
    export template &lt;class&gt; struct Inner {
      auto size() { return 0; }
    };
    export template &lt;class T&gt; struct Table {
      Inner&lt;decltype(sizeof(T))&gt; inner;
      constexpr Table() { size(); }
      void size() { inner.size(); }
    };

    use_size.cppm

    export module use_size;
    import table;
    export inline void useSize(Table&lt;int&gt;&amp; t) { t.size(); }

    holder.cppm

    export module holder;
    export import table;
    export struct Holder { Table&lt;int&gt; t; };

    user.cppm

    export module user;
    import use_size;
    import holder;
    export struct A { Table&lt;char&gt; t{}; };

    main.cpp

    import holder;
    struct B { Table&lt;char&gt; t{}; };
    import user;
    void f() { B b; }

    Crash

    Per-file LLVM IR generation
    table.cppm:8:8: Generating code for declaration 'Table&lt;char&gt;::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(...)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions