Michael137 created this revision. Michael137 added a reviewer: aprantl. Herald added a project: All. Michael137 updated this revision to Diff 483168. Michael137 added a comment. Michael137 updated this revision to Diff 483184. Michael137 published this revision for review. Michael137 added a subscriber: rsmith. Herald added a project: clang. Herald added a subscriber: cfe-commits.
- Simplify Michael137 added a comment. - Fix another test ================ Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94 // FIXME: This difference is due to D76801. It was probably an unintentional change. Maybe we want to undo it? - // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] c"{vector<float, rdar9357400::fixed<4, -1> >=[4f]}\00" - // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] c"{vector<float, rdar9357400::fixed<4, -1>>=[4f]}\00" + // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] c"{vector<float, rdar9357400::fixed<4> >=[4f]}\00" + // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] c"{vector<float, rdar9357400::fixed<4>>=[4f]}\00" extern const char gg[] = @encode(vector4f); ---------------- @aprantl any idea if this is good/OK? (I guess it probably is - but maybe these strings were never meant to ignore/suppress default arguments of any kind? or maybe this is an ABI sort of thing where it suppressing some but not others is now unchangeable?) ================ Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94 // FIXME: This difference is due to D76801. It was probably an unintentional change. Maybe we want to undo it? - // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] c"{vector<float, rdar9357400::fixed<4, -1> >=[4f]}\00" - // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] c"{vector<float, rdar9357400::fixed<4, -1>>=[4f]}\00" + // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] c"{vector<float, rdar9357400::fixed<4> >=[4f]}\00" + // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] c"{vector<float, rdar9357400::fixed<4>>=[4f]}\00" extern const char gg[] = @encode(vector4f); ---------------- dblaikie wrote: > @aprantl any idea if this is good/OK? (I guess it probably is - but maybe > these strings were never meant to ignore/suppress default arguments of any > kind? or maybe this is an ABI sort of thing where it suppressing some but not > others is now unchangeable?) Good point. There was a thread on the cfe mailing list a while ago about the last time this broke: https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html This was @rsmith's stance: ``` I think some of the other recent TypePrinter changes might also risk changing the @encode output. Generally it seems unwise for @encode to be using the type pretty-printer if it wants to be ABI-stable; I don't think it's reasonable to expect any guarantees as to the stability of pretty-printed type names. I think USR generation suffers from similar problems; it too uses the type pretty-printer to generate supposedly-ABI-stable keys in at least some cases. ``` This patch handles default integral non-type template parameters. After this patch the clang TypePrinter will omit default integral template arguments when the `PrintingPolicy::SuppressDefaultTemplateArgs` option is specified and sets us up to be able to re-use `TemplateUtils` from with the DWARF CodeGen component. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D139986 Files: clang/lib/AST/TemplateUtils.cpp clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp clang/test/CodeGenObjCXX/encode.mm clang/test/Misc/diag-template-diffing.cpp clang/test/Misc/diag-template.cpp clang/test/SemaCUDA/device-use-host-var.cu clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp clang/test/SemaCXX/co_await-range-for.cpp clang/test/SemaCXX/coroutines-exp-namespace.cpp clang/test/SemaCXX/coroutines.cpp clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp clang/test/SemaTemplate/deduction-guide.cpp clang/test/SemaTemplate/dependent-names.cpp
Index: clang/test/SemaTemplate/dependent-names.cpp =================================================================== --- clang/test/SemaTemplate/dependent-names.cpp +++ clang/test/SemaTemplate/dependent-names.cpp @@ -338,7 +338,7 @@ struct Y: Y<dim> { }; // expected-error{{circular inheritance between 'Y<dim>' and 'Y<dim>'}} }; typedef X<3> X3; -X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}} +X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}} } namespace rdar12629723 { Index: clang/test/SemaTemplate/deduction-guide.cpp =================================================================== --- clang/test/SemaTemplate/deduction-guide.cpp +++ clang/test/SemaTemplate/deduction-guide.cpp @@ -232,7 +232,7 @@ // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (type-parameter-0-1) -> F<>' // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1' -// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (int) -> F<'x'>' +// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (int) -> F<>' // CHECK: |-TemplateArgument integral 120 // CHECK: |-TemplateArgument type 'int' // CHECK: | `-BuiltinType {{.*}} 'int' Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp =================================================================== --- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp +++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp @@ -34,7 +34,7 @@ { Matrix<double> winI(0, 3); RGBFValue* inputPreL; - winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix<double, 0, 0> &&'}} + winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix<double> &&'}} } } Index: clang/test/SemaCXX/coroutines.cpp =================================================================== --- clang/test/SemaCXX/coroutines.cpp +++ clang/test/SemaCXX/coroutines.cpp @@ -1067,7 +1067,7 @@ }; template <class T, class U> void test_dependent_param(T t, U) { - // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}} + // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}} // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}} ((void)t); co_return 42; Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp =================================================================== --- clang/test/SemaCXX/coroutines-exp-namespace.cpp +++ clang/test/SemaCXX/coroutines-exp-namespace.cpp @@ -1046,7 +1046,7 @@ }; template <class T, class U> void test_dependent_param(T t, U) { - // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}} + // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}} // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}} ((void)t); co_return 42; Index: clang/test/SemaCXX/co_await-range-for.cpp =================================================================== --- clang/test/SemaCXX/co_await-range-for.cpp +++ clang/test/SemaCXX/co_await-range-for.cpp @@ -150,7 +150,7 @@ ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) { Range<T> R; for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}} - // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>, false>'}} + // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>>'}} } template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}} Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp =================================================================== --- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp +++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp @@ -151,7 +151,7 @@ ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) { Range<T> R; for co_await (auto i : R) {} - // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>, false>'}} + // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>>'}} } template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}} Index: clang/test/SemaCUDA/device-use-host-var.cu =================================================================== --- clang/test/SemaCUDA/device-use-host-var.cu +++ clang/test/SemaCUDA/device-use-host-var.cu @@ -272,7 +272,7 @@ __device__ void test_not_a_texture() { not_a_texture<int> inst; - inst.c(); // dev-note {{in instantiation of member function 'not_a_texture<int, 1, 1>::c' requested here}} + inst.c(); // dev-note {{in instantiation of member function 'not_a_texture<int>::c' requested here}} } // Test static variable in host function used by device function. Index: clang/test/Misc/diag-template.cpp =================================================================== --- clang/test/Misc/diag-template.cpp +++ clang/test/Misc/diag-template.cpp @@ -26,7 +26,7 @@ f(ups).f(); // expected-note {{in instantiation of member function 'default_args::unique_ptr<default_args::basic_string<char>>::f' requested here}} } - template<int A, int B = A> struct Z { int error[B]; }; // expected-error {{negative size}} + template<int A, int B = A, int C = 42> struct Z { int error[B]; }; // expected-error {{negative size}} Z<-1> z; // expected-note {{in instantiation of template class 'default_args::Z<-1>' requested here}} template<template<typename> class A = allocator, template<typename> class B = A> struct Q {}; Index: clang/test/Misc/diag-template-diffing.cpp =================================================================== --- clang/test/Misc/diag-template-diffing.cpp +++ clang/test/Misc/diag-template-diffing.cpp @@ -1415,8 +1415,8 @@ B<const A<>> b4 = B<>(); // CHECK-ELIDE-NOTREE: error: no viable conversion from 'A<(default) 0>' to 'A<1>' // CHECK-ELIDE-NOTREE: error: no viable conversion from 'A<1>' to 'A<(default) 0>' -// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<int>' to 'B<(default) ZeroArgs::A<0>>' -// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<(default) ZeroArgs::A<0>>' to 'B<int>' +// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<int>' to 'B<(default) ZeroArgs::A<>>' +// CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<(default) ZeroArgs::A<>>' to 'B<int>' // CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<const A<...>>' to 'B<A<...>>' // CHECK-ELIDE-NOTREE: error: no viable conversion from 'B<A<...>>' to 'B<const A<...>>' } Index: clang/test/CodeGenObjCXX/encode.mm =================================================================== --- clang/test/CodeGenObjCXX/encode.mm +++ clang/test/CodeGenObjCXX/encode.mm @@ -90,8 +90,8 @@ typedef vector< float, fixed<4> > vector4f; // FIXME: This difference is due to D76801. It was probably an unintentional change. Maybe we want to undo it? - // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] c"{vector<float, rdar9357400::fixed<4, -1> >=[4f]}\00" - // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] c"{vector<float, rdar9357400::fixed<4, -1>>=[4f]}\00" + // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] c"{vector<float, rdar9357400::fixed<4> >=[4f]}\00" + // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] c"{vector<float, rdar9357400::fixed<4>>=[4f]}\00" extern const char gg[] = @encode(vector4f); } Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp =================================================================== --- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp +++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp @@ -15,7 +15,7 @@ eval<B<int, float>> eB; eval<C<17>> eC; // expected-error{{implicit instantiation of undefined template 'eval<C<17>>'}} eval<D<int, 17>> eD; // expected-error{{implicit instantiation of undefined template 'eval<D<int, 17>>'}} -eval<E<int, float>> eE; // expected-error{{implicit instantiation of undefined template 'eval<E<int, float, 17>>}} +eval<E<int, float>> eE; // expected-error{{implicit instantiation of undefined template 'eval<E<int, float>>}} template<template <int ...N> class TT> struct X0 { }; // expected-note{{previous non-type template parameter with type 'int' is here}} template<int I, int J, int ...Rest> struct X0a; Index: clang/lib/AST/TemplateUtils.cpp =================================================================== --- clang/lib/AST/TemplateUtils.cpp +++ clang/lib/AST/TemplateUtils.cpp @@ -105,6 +105,16 @@ } } + if (Arg.getKind() == TemplateArgument::Integral && + Pattern.getKind() == TemplateArgument::Expression) { + Expr const *expr = Pattern.getAsExpr(); + + if (!expr->isValueDependent() && expr->isIntegerConstantExpr(Ctx)) { + return llvm::APSInt::isSameValue(expr->EvaluateKnownConstInt(Ctx), + Arg.getAsIntegral()); + } + } + if (Arg.getKind() != Pattern.getKind()) return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits