mirror of
https://github.com/intel/llvm.git
synced 2026-02-04 11:38:04 +08:00
[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
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -90,8 +90,11 @@ namespace rdar9357400 {
|
||||
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"
|
||||
// @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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<...>>'
|
||||
}
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -151,7 +151,7 @@ template <class T>
|
||||
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}}
|
||||
|
||||
|
||||
@@ -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@-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}}
|
||||
|
||||
|
||||
@@ -1046,7 +1046,7 @@ struct NoCopy {
|
||||
};
|
||||
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;
|
||||
|
||||
@@ -1067,7 +1067,7 @@ struct NoCopy {
|
||||
};
|
||||
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;
|
||||
|
||||
@@ -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> &&'}}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user