Bug 288352 - clang crash on devel/hpx while building tests
Summary: clang crash on devel/hpx while building tests
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.3-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-20 17:27 UTC by Yuri Victorovich
Modified: 2025-07-24 07:46 UTC (History)
2 users (show)

See Also:
dim: mfc-stable14+
dim: mfc-stable13+


Attachments
x.log (335.47 KB, text/plain)
2025-07-20 17:27 UTC, Yuri Victorovich
no flags Details
x.sh (47.30 KB, application/x-shellscript)
2025-07-20 17:27 UTC, Yuri Victorovich
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2025-07-20 17:27:24 UTC
Created attachment 262306 [details]
x.log

Clang clashed while building tests for devel/hpx version 1.11.0.

See attached files:
* x.log - build log with crash
* x.cpp - testcase that clang saved as all_of-514fd4.cpp by clang
* x.sh - testcase saved as all_of-514fd4.sh by clang


FreeBSD 14.3
Comment 1 Yuri Victorovich freebsd_committer freebsd_triage 2025-07-20 17:27:51 UTC
Created attachment 262307 [details]
x.sh
Comment 2 Yuri Victorovich freebsd_committer freebsd_triage 2025-07-20 17:31:42 UTC
The cpp file is here: https://freebsd.org/~yuri/clang-crash-on-hpx.cpp
Comment 3 commit-hook freebsd_committer freebsd_triage 2025-07-21 16:56:10 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ffc5ee0f57d56459df93f4107b9835ae78a546b5

commit ffc5ee0f57d56459df93f4107b9835ae78a546b5
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-07-21 16:55:23 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-07-21 16:55:23 +0000

    Merge commit 8ac140f39084 from llvm git (by Younan Zhang):

      [Clang][NFCI] Cleanup the fix for default function argument substitution (#104911)

      (This is one step towards tweaking `getTemplateInstantiationArgs()` as
      discussed in https://github.com/llvm/llvm-project/pull/102922)

      We don't always substitute into default arguments while transforming a
      function parameter. In that case, we would preserve the uninstantiated
      expression until after, e.g. building up a CXXDefaultArgExpr and
      instantiate the expression there.

      For member function instantiation, this algorithm used to cause a
      problem in that the default argument of an out-of-line member function
      specialization couldn't get properly instantiated. This is because, in
      `getTemplateInstantiationArgs()`, we would give up visiting a function's
      declaration context if the function is a specialization of a member
      template. For example,

      ```cpp
      template <class T>
      struct S {
        template <class U>
        void f(T = sizeof(T));
      };

      template <> template <class U>
      void S<int>::f(int) {}
      ```

      The default argument `sizeof(U)` that lexically appears inside the
      declaration would be copied to the function declaration in the class
      template specialization `S<int>`, as well as to the function's
      out-of-line definition. We use template arguments collected from the
      out-of-line function definition when substituting into the default
      arguments. We would therefore give up the traversal after the function,
      resulting in a single-level template argument of the `f` itself. However
      the default argument here could still reference the template parameters
      of the primary template, hence the error.

      In fact, this is similar to constraint checking in some respects: we
      actually want the "whole" template arguments relative to the primary
      template, not those relative to the function definition. So this patch
      adds another flag to indicate `getTemplateInstantiationArgs()` for that.

      This patch also consolidates the tests for default arguments and removes
      some unnecessary tests.

    This fixes a crash or assertion failure while building tests for the
    devel/hpx port.

    PR:             288352
    MFC after:      3 days

 .../llvm-project/clang/include/clang/Sema/Sema.h   |  9 ++++++++-
 .../clang/lib/Sema/SemaTemplateInstantiate.cpp     | 23 ++++++++--------------
 .../clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 10 ++++++----
 3 files changed, 22 insertions(+), 20 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-07-24 07:45:36 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ae7fdd715466490d91813179475ea103c8c8e30d

commit ae7fdd715466490d91813179475ea103c8c8e30d
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-07-21 16:55:23 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-07-24 07:44:45 +0000

    Merge commit 8ac140f39084 from llvm git (by Younan Zhang):

      [Clang][NFCI] Cleanup the fix for default function argument substitution (#104911)

      (This is one step towards tweaking `getTemplateInstantiationArgs()` as
      discussed in https://github.com/llvm/llvm-project/pull/102922)

      We don't always substitute into default arguments while transforming a
      function parameter. In that case, we would preserve the uninstantiated
      expression until after, e.g. building up a CXXDefaultArgExpr and
      instantiate the expression there.

      For member function instantiation, this algorithm used to cause a
      problem in that the default argument of an out-of-line member function
      specialization couldn't get properly instantiated. This is because, in
      `getTemplateInstantiationArgs()`, we would give up visiting a function's
      declaration context if the function is a specialization of a member
      template. For example,

      ```cpp
      template <class T>
      struct S {
        template <class U>
        void f(T = sizeof(T));
      };

      template <> template <class U>
      void S<int>::f(int) {}
      ```

      The default argument `sizeof(U)` that lexically appears inside the
      declaration would be copied to the function declaration in the class
      template specialization `S<int>`, as well as to the function's
      out-of-line definition. We use template arguments collected from the
      out-of-line function definition when substituting into the default
      arguments. We would therefore give up the traversal after the function,
      resulting in a single-level template argument of the `f` itself. However
      the default argument here could still reference the template parameters
      of the primary template, hence the error.

      In fact, this is similar to constraint checking in some respects: we
      actually want the "whole" template arguments relative to the primary
      template, not those relative to the function definition. So this patch
      adds another flag to indicate `getTemplateInstantiationArgs()` for that.

      This patch also consolidates the tests for default arguments and removes
      some unnecessary tests.

    This fixes a crash or assertion failure while building tests for the
    devel/hpx port.

    PR:             288352
    MFC after:      3 days

    (cherry picked from commit ffc5ee0f57d56459df93f4107b9835ae78a546b5)

 .../llvm-project/clang/include/clang/Sema/Sema.h   |  9 ++++++++-
 .../clang/lib/Sema/SemaTemplateInstantiate.cpp     | 23 ++++++++--------------
 .../clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 10 ++++++----
 3 files changed, 22 insertions(+), 20 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2025-07-24 07:45:37 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e5fcb8c32fbdf7208ab5e2b250bec6686141dfc7

commit e5fcb8c32fbdf7208ab5e2b250bec6686141dfc7
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-07-21 16:55:23 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-07-24 07:44:49 +0000

    Merge commit 8ac140f39084 from llvm git (by Younan Zhang):

      [Clang][NFCI] Cleanup the fix for default function argument substitution (#104911)

      (This is one step towards tweaking `getTemplateInstantiationArgs()` as
      discussed in https://github.com/llvm/llvm-project/pull/102922)

      We don't always substitute into default arguments while transforming a
      function parameter. In that case, we would preserve the uninstantiated
      expression until after, e.g. building up a CXXDefaultArgExpr and
      instantiate the expression there.

      For member function instantiation, this algorithm used to cause a
      problem in that the default argument of an out-of-line member function
      specialization couldn't get properly instantiated. This is because, in
      `getTemplateInstantiationArgs()`, we would give up visiting a function's
      declaration context if the function is a specialization of a member
      template. For example,

      ```cpp
      template <class T>
      struct S {
        template <class U>
        void f(T = sizeof(T));
      };

      template <> template <class U>
      void S<int>::f(int) {}
      ```

      The default argument `sizeof(U)` that lexically appears inside the
      declaration would be copied to the function declaration in the class
      template specialization `S<int>`, as well as to the function's
      out-of-line definition. We use template arguments collected from the
      out-of-line function definition when substituting into the default
      arguments. We would therefore give up the traversal after the function,
      resulting in a single-level template argument of the `f` itself. However
      the default argument here could still reference the template parameters
      of the primary template, hence the error.

      In fact, this is similar to constraint checking in some respects: we
      actually want the "whole" template arguments relative to the primary
      template, not those relative to the function definition. So this patch
      adds another flag to indicate `getTemplateInstantiationArgs()` for that.

      This patch also consolidates the tests for default arguments and removes
      some unnecessary tests.

    This fixes a crash or assertion failure while building tests for the
    devel/hpx port.

    PR:             288352
    MFC after:      3 days

    (cherry picked from commit ffc5ee0f57d56459df93f4107b9835ae78a546b5)

 .../llvm-project/clang/include/clang/Sema/Sema.h   |  9 ++++++++-
 .../clang/lib/Sema/SemaTemplateInstantiate.cpp     | 23 ++++++++--------------
 .../clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 10 ++++++----
 3 files changed, 22 insertions(+), 20 deletions(-)