[clang] 1706f34 - [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

Michael Buch via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 16 03:39:11 PST 2022


Author: Michael Buch
Date: 2022-12-16T11:38:51Z
New Revision: 1706f34d604ec304af58a7b95dbc127bd77e17fa

URL: https://github.com/llvm/llvm-project/commit/1706f34d604ec304af58a7b95dbc127bd77e17fa
DIFF: https://github.com/llvm/llvm-project/commit/1706f34d604ec304af58a7b95dbc127bd77e17fa.diff

LOG: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

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
`clang::isSubstitutedDefaultArgument` from the DWARF CodeGen
component.

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

Added: 
    

Modified: 
    clang/lib/AST/TypePrinter.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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index bfab41b7e4dea..5c24649044856 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2025,6 +2025,16 @@ static bool isSubstitutedTemplateArgument(ASTContext &Ctx, TemplateArgument Arg,
     }
   }
 
+  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;
 

diff  --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
index 0c555b53f95e6..51489c5eac5ad 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
@@ -15,7 +15,7 @@ eval<A<int>> eA;
 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;

diff  --git a/clang/test/CodeGenObjCXX/encode.mm b/clang/test/CodeGenObjCXX/encode.mm
index 857c5da341442..0fad2895c7175 100644
--- a/clang/test/CodeGenObjCXX/encode.mm
+++ b/clang/test/CodeGenObjCXX/encode.mm
@@ -90,8 +90,11 @@ @implementation RedBalloonHGXFormWrapper
   typedef vector< float,  fixed<4> > vector4f;
 
   // FIXME: This 
diff erence 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"
+  // @encoding for C++ is dependent on the TypePrinter implementation, which is a known issue. But since there
+  // are currently no system frameworks that vend Objective-C++ types, a potential ABI break caused by changes
+  // to the TypePrinter should not be a concern.
+  // 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);
 }
 

diff  --git a/clang/test/Misc/diag-template-
diff ing.cpp b/clang/test/Misc/diag-template-
diff ing.cpp
index dffd5715700a2..641e700a260c8 100644
--- a/clang/test/Misc/diag-template-
diff ing.cpp
+++ b/clang/test/Misc/diag-template-
diff ing.cpp
@@ -1415,8 +1415,8 @@ B<> b3 = B<const A<>>();
 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<...>>'
 }

diff  --git a/clang/test/Misc/diag-template.cpp b/clang/test/Misc/diag-template.cpp
index 5299375f65650..07cce00633cd1 100644
--- a/clang/test/Misc/diag-template.cpp
+++ b/clang/test/Misc/diag-template.cpp
@@ -26,7 +26,7 @@ namespace default_args {
     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 {};

diff  --git a/clang/test/SemaCUDA/device-use-host-var.cu b/clang/test/SemaCUDA/device-use-host-var.cu
index 66fbd552912fb..7904f654d65b3 100644
--- a/clang/test/SemaCUDA/device-use-host-var.cu
+++ b/clang/test/SemaCUDA/device-use-host-var.cu
@@ -272,7 +272,7 @@ not_a_texture<int> not_a_texture<int>::ref; // dev-note {{host variable declared
 
 __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.

diff  --git a/clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp b/clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
index df6b8a4e86b36..18541cee00145 100644
--- a/clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ b/clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@ template <class T>
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range<T> R;
   for co_await (auto i : R) {}
-  // expected-error at -1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>, false>'}}
+  // expected-error at -1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 

diff  --git a/clang/test/SemaCXX/co_await-range-for.cpp b/clang/test/SemaCXX/co_await-range-for.cpp
index a3feffab4bb27..064a35038e1c7 100644
--- a/clang/test/SemaCXX/co_await-range-for.cpp
+++ b/clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@ template <class T>
 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 at -1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>, false>'}}
+  // expected-error at -1 {{no member named 'await_ready' in 'CoawaitTag<Iter<int>>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 

diff  --git a/clang/test/SemaCXX/coroutines-exp-namespace.cpp b/clang/test/SemaCXX/coroutines-exp-namespace.cpp
index 09eca2be744bf..5c6f8e0bf0ed0 100644
--- a/clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ b/clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@ struct NoCopy {
 };
 template <class T, class U>
 void test_dependent_param(T t, U) {
-  // expected-error at -1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error at -1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error at -2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;

diff  --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp
index 7f16c1ef45f1a..3f779dd913f8f 100644
--- a/clang/test/SemaCXX/coroutines.cpp
+++ b/clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@ struct NoCopy {
 };
 template <class T, class U>
 void test_dependent_param(T t, U) {
-  // expected-error at -1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error at -1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error at -2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;

diff  --git a/clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp b/clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
index dd04345281616..aa6a805318209 100644
--- a/clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ b/clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@ void getLaplacianClosedForm()
 {
     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> &&'}}
 }
 
 }

diff  --git a/clang/test/SemaTemplate/deduction-guide.cpp b/clang/test/SemaTemplate/deduction-guide.cpp
index 0630f4d02c4b7..3beccd3566678 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@ F s(0);
 // 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'

diff  --git a/clang/test/SemaTemplate/dependent-names.cpp b/clang/test/SemaTemplate/dependent-names.cpp
index f9f9c8e6e940b..641ec950054f5 100644
--- a/clang/test/SemaTemplate/dependent-names.cpp
+++ b/clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@ template < unsigned > struct X {
   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 {


        


More information about the cfe-commits mailing list