hazohelet created this revision. hazohelet added reviewers: aaron.ballman, tbaeder, cjdb, shafik. Herald added a project: All. hazohelet requested review of this revision. Herald added a project: clang.
This patch adds additional printing of template argument list when the described function is a template specialization. This can be useful when handling complex template functions in constexpr evaluator. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D154366 Files: clang/docs/ReleaseNotes.rst clang/lib/AST/ExprConstant.cpp clang/test/AST/Interp/literals.cpp clang/test/SemaCXX/builtin-align-cxx.cpp clang/test/SemaCXX/constant-expression-cxx11.cpp clang/test/SemaCXX/constant-expression-cxx14.cpp clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp =================================================================== --- clang/test/SemaCXX/cxx2b-consteval-propagate.cpp +++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp @@ -45,7 +45,7 @@ } int i = hh<int>(); // expected-error {{call to immediate function 'examples::hh<int>' is not a constant expression}} \ - // expected-note {{in call to 'hh()'}} + // expected-note {{in call to 'hh<int>()'}} struct A { int x; Index: clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp =================================================================== --- clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp +++ clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp @@ -117,11 +117,11 @@ constexpr pad pir{4, 4}; // expected-error@+2 {{constexpr variable 'piw' must be initialized by a constant expression}} - // expected-note@+1 {{in call to 'bit_cast(pir)'}} + // expected-note@+1 {{in call to 'bit_cast<no_pad, pad>(pir)'}} constexpr int piw = bit_cast<no_pad>(pir).x; // expected-error@+2 {{constexpr variable 'bad' must be initialized by a constant expression}} - // expected-note@+1 {{in call to 'bit_cast(pir)'}} + // expected-note@+1 {{in call to 'bit_cast<no_pad, pad>(pir)'}} constexpr no_pad bad = bit_cast<no_pad>(pir); constexpr pad fine = bit_cast<pad>(no_pad{1, 2, 3, 4, 5}); Index: clang/test/SemaCXX/constant-expression-cxx14.cpp =================================================================== --- clang/test/SemaCXX/constant-expression-cxx14.cpp +++ clang/test/SemaCXX/constant-expression-cxx14.cpp @@ -1038,7 +1038,7 @@ void foo() __attribute__((enable_if(sum(Cs) == 'a' + 'b', ""))); void run() { foo(); } -static_assert(sum(Cs) == 'a' + 'b', ""); // expected-error{{not an integral constant expression}} expected-note{{in call to 'sum(Cs)'}} +static_assert(sum(Cs) == 'a' + 'b', ""); // expected-error{{not an integral constant expression}} expected-note{{in call to 'sum<2>(Cs)'}} constexpr int S = sum(Cs); // expected-error{{must be initialized by a constant expression}} expected-note{{in call}} } Index: clang/test/SemaCXX/constant-expression-cxx11.cpp =================================================================== --- clang/test/SemaCXX/constant-expression-cxx11.cpp +++ clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1781,7 +1781,7 @@ static_assert(get(arr, 1) == 1, ""); static_assert(get(arr, 4) == 4, ""); static_assert(get(arr, 0) == 4, ""); // expected-error{{not an integral constant expression}} \ - // expected-note{{in call to 'get(arr, 0)'}} + // expected-note{{in call to 'get<const int, 5>(arr, 0)'}} } namespace std { struct type_info; } Index: clang/test/SemaCXX/builtin-align-cxx.cpp =================================================================== --- clang/test/SemaCXX/builtin-align-cxx.cpp +++ clang/test/SemaCXX/builtin-align-cxx.cpp @@ -137,26 +137,26 @@ constexpr long const_value(long l) { return l; } // Check some invalid values during constant-evaluation static_assert(wrap_align_down(1, const_value(-1)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_align_down(1, -1)'}} +// expected-note@-1{{in call to 'wrap_align_down<int>(1, -1)'}} static_assert(wrap_align_up(1, const_value(-2)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_align_up(1, -2)'}} +// expected-note@-1{{in call to 'wrap_align_up<int>(1, -2)'}} static_assert(wrap_is_aligned(1, const_value(-3)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_is_aligned(1, -3)'}} +// expected-note@-1{{in call to 'wrap_is_aligned<int>(1, -3)'}} static_assert(wrap_align_down(1, const_value(17)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_align_down(1, 17)'}} +// expected-note@-1{{in call to 'wrap_align_down<int>(1, 17)'}} static_assert(wrap_align_up(1, const_value(18)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_align_up(1, 18)'}} +// expected-note@-1{{in call to 'wrap_align_up<int>(1, 18)'}} static_assert(wrap_is_aligned(1, const_value(19)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_is_aligned(1, 19)'}} +// expected-note@-1{{in call to 'wrap_is_aligned<int>(1, 19)'}} // Check invalid values for smaller types: static_assert(wrap_align_down(static_cast<short>(1), const_value(1 << 20)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_align_down(1, 1048576)'}} +// expected-note@-1{{in call to 'wrap_align_down<short>(1, 1048576)'}} // Check invalid boolean type static_assert(wrap_align_up(static_cast<int>(1), const_value(1ull << 33)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_align_up(1, 8589934592)'}} +// expected-note@-1{{in call to 'wrap_align_up<int>(1, 8589934592)'}} static_assert(wrap_is_aligned(static_cast<char>(1), const_value(1 << 22)), ""); // expected-error{{not an integral constant expression}} -// expected-note@-1{{in call to 'wrap_is_aligned(1, 4194304)'}} +// expected-note@-1{{in call to 'wrap_is_aligned<char>(1, 4194304)'}} // Check invalid boolean type static_assert(wrap_align_up(static_cast<bool>(1), const_value(1 << 21)), ""); // expected-error{{not an integral constant expression}} Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -474,22 +474,22 @@ return 1; } static_assert(uninit<int, true>(), ""); // ref-error {{not an integral constant expression}} \ - // ref-note {{in call to 'uninit()'}} \ + // ref-note {{in call to 'uninit<int, true>()'}} \ // expected-error {{not an integral constant expression}} \ // expected-note {{in call to 'uninit()'}} static_assert(uninit<int, false>(), ""); // ref-error {{not an integral constant expression}} \ - // ref-note {{in call to 'uninit()'}} \ + // ref-note {{in call to 'uninit<int, false>()'}} \ // expected-error {{not an integral constant expression}} \ // expected-note {{in call to 'uninit()'}} static_assert(uninit<float, true>(), ""); // ref-error {{not an integral constant expression}} \ - // ref-note {{in call to 'uninit()'}} \ + // ref-note {{in call to 'uninit<float, true>()'}} \ // expected-error {{not an integral constant expression}} \ // expected-note {{in call to 'uninit()'}} static_assert(uninit<float, false>(), ""); // ref-error {{not an integral constant expression}} \ - // ref-note {{in call to 'uninit()'}} \ + // ref-note {{in call to 'uninit<float, false>()'}} \ // expected-error {{not an integral constant expression}} \ // expected-note {{in call to 'uninit()'}} Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -1921,7 +1921,7 @@ cast<CXXMethodDecl>(Callee)->isInstance(); if (!IsMemberCall) - Out << *Callee << '('; + Out << *Callee; if (This && IsMemberCall) { if (const auto *MCE = dyn_cast_if_present<CXXMemberCallExpr>(CallExpr)) { @@ -1946,10 +1946,23 @@ Info.Ctx.getLValueReferenceType(This->Designator.MostDerivedType)); Out << "."; } - Out << *Callee << '('; + Out << *Callee; IsMemberCall = false; } + if (const TemplateArgumentList *TAL = + Callee->getTemplateSpecializationArgs()) { + Out << '<'; + for (const auto &Arg : TAL->asArray()) { + Arg.print(Info.Ctx.getPrintingPolicy(), Out, /*IncludeType=*/false); + if (&Arg != &TAL->asArray().back()) + Out << ", "; + } + Out << '>'; + } + + Out << '('; + for (FunctionDecl::param_const_iterator I = Callee->param_begin(), E = Callee->param_end(); I != E; ++I, ++ArgIndex) { if (ArgIndex > (unsigned)IsMemberCall) Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -379,6 +379,8 @@ (`#57081: <https://github.com/llvm/llvm-project/issues/57081>`_) - Clang no longer emits inappropriate notes about the loss of ``__unaligned`` qualifier on overload resolution, when the actual reason for the failure is loss of other qualifiers. +- Clang constexpr evaluator now prints template arguments when displaying + template-specialization function calls. Bug Fixes in This Version -------------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits