diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 25d3535e5dac4..23aa14784cdaa 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2288,14 +2288,17 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx, SourceLocation Loc; const DeclContext *Context; - std::tie(Loc, - Context) = [&]() -> std::pair { - if (auto *DIE = dyn_cast_or_null(DefaultExpr)) - return {DIE->getUsedLocation(), DIE->getUsedContext()}; - if (auto *DAE = dyn_cast_or_null(DefaultExpr)) - return {DAE->getUsedLocation(), DAE->getUsedContext()}; - return {this->getLocation(), this->getParentContext()}; - }(); + if (const auto *DIE = dyn_cast_if_present(DefaultExpr)) { + Loc = DIE->getUsedLocation(); + Context = DIE->getUsedContext(); + } else if (const auto *DAE = + dyn_cast_if_present(DefaultExpr)) { + Loc = DAE->getUsedLocation(); + Context = DAE->getUsedContext(); + } else { + Loc = getLocation(); + Context = getParentContext(); + } PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc( Ctx.getSourceManager().getExpansionRange(Loc).getEnd()); @@ -2333,13 +2336,9 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx, CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string("")); } case SourceLocExpr::Line: - case SourceLocExpr::Column: { - llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy), - /*isUnsigned=*/true); - IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine() - : PLoc.getColumn(); - return APValue(IntVal); - } + return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy)); + case SourceLocExpr::Column: + return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy)); case SourceLocExpr::SourceLocStruct: { // Fill in a std::source_location::__impl structure, by creating an // artificial file-scoped CompoundLiteralExpr, and returning a pointer to @@ -2352,7 +2351,7 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx, // the ImplDecl type is as expected. APValue Value(APValue::UninitStruct(), 0, 4); - for (FieldDecl *F : ImplDecl->fields()) { + for (const FieldDecl *F : ImplDecl->fields()) { StringRef Name = F->getName(); if (Name == "_M_file_name") { SmallString<256> Path(PLoc.getFilename()); @@ -2369,16 +2368,10 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx, PredefinedExpr::PrettyFunction, CurDecl)) : ""); } else if (Name == "_M_line") { - QualType Ty = F->getType(); - llvm::APSInt IntVal(Ctx.getIntWidth(Ty), - Ty->hasUnsignedIntegerRepresentation()); - IntVal = PLoc.getLine(); + llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getLine(), F->getType()); Value.getStructField(F->getFieldIndex()) = APValue(IntVal); } else if (Name == "_M_column") { - QualType Ty = F->getType(); - llvm::APSInt IntVal(Ctx.getIntWidth(Ty), - Ty->hasUnsignedIntegerRepresentation()); - IntVal = PLoc.getColumn(); + llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getColumn(), F->getType()); Value.getStructField(F->getFieldIndex()) = APValue(IntVal); } }