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

Frontend segfault when a function-local static variable is used as a reference non-type template argument

Open ICSE-27 opened this issue 2 months ago • 1 comments

Environment

Clang 19.1.0 (x86-64-unknown-linux-gnu, release build without assertions)

Command

$ clang++ -c test7.cpp

Actual behavior

Segmentation fault (the front end queries constant-size-type info on a dependent type).

Additional notes

The template is instantiated with a reference to a static variable local to a function template. The test case was produced by an automated compiler-testing tool (GapSmith).

Test case (test7.cpp)

#include <iostream>
template<int& T>
void FuncTemplate() {
    std::cout << "Template instantiated with reference to int: " << T << std::endl;
}

template<int i> class A {};
template<int i> void g(A<i> &) {
    static int InternalVar = 43;
    FuncTemplate<InternalVar>();
}

int main()
{
  A<1> a;
  g(a);
}

ICSE-27 avatar Sep 26 '26 12:09 ICSE-27

@llvm/issue-subscribers-clang-frontend

Author: ICSE-27

## Environment Clang 19.1.0 (x86-64-unknown-linux-gnu, release build without assertions)

Command

clang++ -c test7.cpp

Actual behavior

Segmentation fault (the front end queries constant-size-type info on a dependent type).

Additional notes

The template is instantiated with a reference to a static variable local to a function template. The test case was produced by an automated compiler-testing tool (GapSmith).

Test case (test7.cpp)

#include &lt;iostream&gt;
template&lt;int&amp; T&gt;
void FuncTemplate() {
    std::cout &lt;&lt; "Template instantiated with reference to int: " &lt;&lt; T &lt;&lt; std::endl;
}

template&lt;int i&gt; class A {};
template&lt;int i&gt; void g(A&lt;i&gt; &amp;) {
    static int InternalVar = 43;
    FuncTemplate&lt;InternalVar&gt;();
}

int main()
{
  A&lt;1&gt; a;
  g(a);
}