@@ -2288,14 +2288,17 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
2288
2288
SourceLocation Loc;
2289
2289
const DeclContext *Context;
2290
2290
2291
- std::tie (Loc,
2292
- Context) = [&]() -> std::pair<SourceLocation, const DeclContext *> {
2293
- if (auto *DIE = dyn_cast_or_null<CXXDefaultInitExpr>(DefaultExpr))
2294
- return {DIE->getUsedLocation (), DIE->getUsedContext ()};
2295
- if (auto *DAE = dyn_cast_or_null<CXXDefaultArgExpr>(DefaultExpr))
2296
- return {DAE->getUsedLocation (), DAE->getUsedContext ()};
2297
- return {this ->getLocation (), this ->getParentContext ()};
2298
- }();
2291
+ if (const auto *DIE = dyn_cast_if_present<CXXDefaultInitExpr>(DefaultExpr)) {
2292
+ Loc = DIE->getUsedLocation ();
2293
+ Context = DIE->getUsedContext ();
2294
+ } else if (const auto *DAE =
2295
+ dyn_cast_if_present<CXXDefaultArgExpr>(DefaultExpr)) {
2296
+ Loc = DAE->getUsedLocation ();
2297
+ Context = DAE->getUsedContext ();
2298
+ } else {
2299
+ Loc = getLocation ();
2300
+ Context = getParentContext ();
2301
+ }
2299
2302
2300
2303
PresumedLoc PLoc = Ctx.getSourceManager ().getPresumedLoc (
2301
2304
Ctx.getSourceManager ().getExpansionRange (Loc).getEnd ());
@@ -2333,13 +2336,9 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
2333
2336
CurDecl ? PredefinedExpr::ComputeName (Kind, CurDecl) : std::string (" " ));
2334
2337
}
2335
2338
case SourceLocExpr::Line:
2336
- case SourceLocExpr::Column: {
2337
- llvm::APSInt IntVal (Ctx.getIntWidth (Ctx.UnsignedIntTy ),
2338
- /* isUnsigned=*/ true );
2339
- IntVal = getIdentKind () == SourceLocExpr::Line ? PLoc.getLine ()
2340
- : PLoc.getColumn ();
2341
- return APValue (IntVal);
2342
- }
2339
+ return APValue (Ctx.MakeIntValue (PLoc.getLine (), Ctx.UnsignedIntTy ));
2340
+ case SourceLocExpr::Column:
2341
+ return APValue (Ctx.MakeIntValue (PLoc.getColumn (), Ctx.UnsignedIntTy ));
2343
2342
case SourceLocExpr::SourceLocStruct: {
2344
2343
// Fill in a std::source_location::__impl structure, by creating an
2345
2344
// artificial file-scoped CompoundLiteralExpr, and returning a pointer to
@@ -2352,7 +2351,7 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
2352
2351
// the ImplDecl type is as expected.
2353
2352
2354
2353
APValue Value (APValue::UninitStruct (), 0 , 4 );
2355
- for (FieldDecl *F : ImplDecl->fields ()) {
2354
+ for (const FieldDecl *F : ImplDecl->fields ()) {
2356
2355
StringRef Name = F->getName ();
2357
2356
if (Name == " _M_file_name" ) {
2358
2357
SmallString<256 > Path (PLoc.getFilename ());
@@ -2369,16 +2368,10 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
2369
2368
PredefinedExpr::PrettyFunction, CurDecl))
2370
2369
: " " );
2371
2370
} else if (Name == " _M_line" ) {
2372
- QualType Ty = F->getType ();
2373
- llvm::APSInt IntVal (Ctx.getIntWidth (Ty),
2374
- Ty->hasUnsignedIntegerRepresentation ());
2375
- IntVal = PLoc.getLine ();
2371
+ llvm::APSInt IntVal = Ctx.MakeIntValue (PLoc.getLine (), F->getType ());
2376
2372
Value.getStructField (F->getFieldIndex ()) = APValue (IntVal);
2377
2373
} else if (Name == " _M_column" ) {
2378
- QualType Ty = F->getType ();
2379
- llvm::APSInt IntVal (Ctx.getIntWidth (Ty),
2380
- Ty->hasUnsignedIntegerRepresentation ());
2381
- IntVal = PLoc.getColumn ();
2374
+ llvm::APSInt IntVal = Ctx.MakeIntValue (PLoc.getColumn (), F->getType ());
2382
2375
Value.getStructField (F->getFieldIndex ()) = APValue (IntVal);
2383
2376
}
2384
2377
}
0 commit comments