Skip to content

Commit 0bf200d

Browse files
committed
Add default argument values
1 parent eb5064e commit 0bf200d

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12760,7 +12760,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1276012760
if (BuiltinOp == Builtin::BI__c11_atomic_is_lock_free ||
1276112761
Size == CharUnits::One() ||
1276212762
E->getArg(1)->isNullPointerConstant(Info.Ctx,
12763-
Expr::NPC_NeverValueDependent))
12763+
Expr::NPC_ValueDependentIsNull))
1276412764
// OK, we will inline appropriately-aligned operations of this size,
1276512765
// and _Atomic(T) is appropriately-aligned.
1276612766
return Success(1, E);

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,24 +1339,51 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
13391339
// being substituted into a parameter pack. We can find out if that's
13401340
// the case now by inspecting the TypeAliasTemplateDecl template
13411341
// parameters. Insert Ty's template args into SpecArgs, bundling args
1342-
// passed to a parameter pack into a TemplateArgument::Pack.
1342+
// passed to a parameter pack into a TemplateArgument::Pack. It also
1343+
// doesn't know the value of any defaulted args, so collect those now
1344+
// too.
13431345
SmallVector<TemplateArgument> SpecArgs;
13441346
{
13451347
ArrayRef SubstArgs = Ty->template_arguments();
1346-
for (const NamedDecl *P : TD->getTemplateParameters()->asArray()) {
1347-
if (P->isParameterPack()) {
1348+
for (const NamedDecl *Param : TD->getTemplateParameters()->asArray()) {
1349+
// If Param is a parameter pack, pack the remaining arguments.
1350+
if (Param->isParameterPack()) {
13481351
SpecArgs.push_back(TemplateArgument(SubstArgs));
13491352
break;
13501353
}
1351-
// Skip defaulted args.
1352-
if (SubstArgs.empty()) {
1353-
// If SubstArgs is now empty (we're taking from it each iteration) and
1354-
// this template parameter isn't a pack, then that should mean we're
1355-
// using default values for the remaining template parameters.
1354+
1355+
// Take the next argument.
1356+
if (!SubstArgs.empty()) {
1357+
SpecArgs.push_back(SubstArgs.front());
1358+
SubstArgs = SubstArgs.drop_front();
1359+
continue;
1360+
}
1361+
1362+
// If SubstArgs is now empty (we're taking from it each iteration) and
1363+
// this template parameter isn't a pack, then that should mean we're
1364+
// using default values for the remaining template parameters. Push the
1365+
// default value for each parameter.
1366+
if (auto *P = dyn_cast<TemplateTypeParmDecl>(Param)) {
1367+
assert(P->hasDefaultArgument() &&
1368+
"expected defaulted template type parameter");
1369+
SpecArgs.push_back(TemplateArgument(P->getDefaultArgument(),
1370+
/*IsNullPtr=*/false,
1371+
/*IsDefaulted=*/true));
1372+
} else if (auto *P = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1373+
assert(P->hasDefaultArgument() &&
1374+
"expected defaulted template non-type parameter");
1375+
SpecArgs.push_back(TemplateArgument(P->getDefaultArgument(),
1376+
/*IsDefaulted=*/true));
1377+
} else if (auto *P = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1378+
assert(P->hasDefaultArgument() &&
1379+
"expected defaulted template template parameter");
1380+
SpecArgs.push_back(TemplateArgument(
1381+
P->getDefaultArgument().getArgument().getAsTemplate(),
1382+
/*IsDefaulted=*/true));
1383+
} else {
1384+
llvm_unreachable("Unexpected template parameter kind");
13561385
break;
13571386
}
1358-
SpecArgs.push_back(SubstArgs.front());
1359-
SubstArgs = SubstArgs.drop_front();
13601387
}
13611388
}
13621389
TemplateArgs Args = {TD->getTemplateParameters(), SpecArgs};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -gtemplate-alias %s -gsimple-template-names=simple \
2+
// RUN: | FileCheck %s
3+
4+
//// Check that -gtemplate-alias causes DW_TAG_template_alias emission for
5+
//// template aliases with default parameter values. See template-alias.cpp for
6+
//// more template alias tests.
7+
8+
template<typename T>
9+
struct X {
10+
char m;
11+
};
12+
13+
template<typename T>
14+
struct Y {
15+
char n;
16+
};
17+
18+
template <typename NonDefault, template <typename C> class T = Y, int I = 5, typename... Ts>
19+
using A = X<NonDefault>;
20+
21+
//// We should be able to emit type alias metadata which describes all the
22+
//// values, including the defaulted parameters and empty parameter pack.
23+
A<int> a;
24+
25+
// CHECK: !DIDerivedType(tag: DW_TAG_template_alias, name: "A", file: ![[#]], line: [[#]], baseType: ![[baseType:[0-9]+]], extraData: ![[extraData:[0-9]+]])
26+
// CHECK: ![[baseType]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X",
27+
// CHECK: ![[int:[0-9]+]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
28+
// CHECK: ![[extraData]] = !{![[NonDefault:[0-9]+]], ![[T:[0-9]+]], ![[I:[0-9]+]], ![[Ts:[0-9]+]]}
29+
// CHECK: ![[NonDefault]] = !DITemplateTypeParameter(name: "NonDefault", type: ![[int]])
30+
// CHECK: ![[T]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "T", defaulted: true, value: !"Y")
31+
// CHECK: ![[I]] = !DITemplateValueParameter(name: "I", type: ![[int]], defaulted: true, value: i32 5)
32+
// CHECK: ![[Ts]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_parameter_pack, name: "Ts", value: ![[types:[0-9]+]])
33+
// CHECK: ![[types]] = !{}

0 commit comments

Comments
 (0)