[all-commits] [llvm/llvm-project] e58251: [clang] fix frontend crash when evaluating type trait

inclyc via All-commits all-commits at lists.llvm.org
Fri Aug 12 09:03:43 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e5825190b8ad7ac8fe762fe4101cd4af04f4c057
      https://github.com/llvm/llvm-project/commit/e5825190b8ad7ac8fe762fe4101cd4af04f4c057
  Author: YingChi Long <me at inclyc.cn>
  Date:   2022-08-13 (Sat, 13 Aug 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/TypeTraits.h
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Basic/TypeTraits.cpp
    M clang/lib/Parse/ParseExprCXX.cpp
    M clang/lib/Sema/SemaExprCXX.cpp
    A clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp

  Log Message:
  -----------
  [clang] fix frontend crash when evaluating type trait

Before this patch type traits are checked in Parser, so use type traits
directly did not cause assertion faults. However if type traits are initialized
from a template, we didn't perform arity checks before evaluating. This
patch moves arity checks from Parser to Sema, and performing arity
checks in Sema actions, so type traits get checked corretly.

Crash input:

```
template<class... Ts> bool b = __is_constructible(Ts...);
bool x = b<>;
```

After this patch:

```
clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp:5:32: error: type trait requires 1 or more arguments; have 0 arguments
template<class... Ts> bool b = __is_constructible(Ts...);
                               ^~~~~~~~~~~~~~~~~~
clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp:6:10: note: in instantiation of variable template specialization 'b<>' requested here
bool x = b<>;
         ^
1 error generated.
```

See https://godbolt.org/z/q39W78hsK.

Fixes https://github.com/llvm/llvm-project/issues/57008

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131423




More information about the All-commits mailing list