aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2025-01-03 19:23:42 -0800
committerGitHub <noreply@github.com>2025-01-03 19:23:42 -0800
commitdc3cd2e95ee56cdb75f4d0d0742626f912b5c6f3 (patch)
treeddd21d1a955986273c89477d07fed5da55e3e2d6 /clang/lib
parenta2b9058c392995660956e56c2ac8695a44dc2e4e (diff)
downloadllvm-dc3cd2e95ee56cdb75f4d0d0742626f912b5c6f3.zip
llvm-dc3cd2e95ee56cdb75f4d0d0742626f912b5c6f3.tar.gz
llvm-dc3cd2e95ee56cdb75f4d0d0742626f912b5c6f3.tar.bz2
Factor common code for quoting a builtin name (#120835)
This shows up in several places in order to match the quoting of other uses of the same diagnostic. Handling it centrally simplifies the code and reduces changes if the storage for builtin names changes. This refactoring is extracted out of #120534 as requested in code review.
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ByteCode/InterpBuiltin.cpp4
-rw-r--r--clang/lib/AST/ExprConstant.cpp15
-rw-r--r--clang/lib/Basic/Builtins.cpp4
3 files changed, 13 insertions, 10 deletions
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 731c929..0d52083 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -155,7 +155,7 @@ static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
if (S.getLangOpts().CPlusPlus11)
S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
<< /*isConstexpr=*/0 << /*isConstructor=*/0
- << ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
+ << S.getASTContext().BuiltinInfo.getQuotedName(ID);
else
S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
}
@@ -1977,7 +1977,7 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
!isOneByteCharacterType(PtrB.getType()))) {
S.FFDiag(S.Current->getSource(OpPC),
diag::note_constexpr_memcmp_unsupported)
- << ("'" + ASTCtx.BuiltinInfo.getName(ID) + "'").str() << PtrA.getType()
+ << ASTCtx.BuiltinInfo.getQuotedName(ID) << PtrA.getType()
<< PtrB.getType();
return false;
}
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index dd75dca..e220f69 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9858,7 +9858,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
if (Info.getLangOpts().CPlusPlus11)
Info.CCEDiag(E, diag::note_constexpr_invalid_function)
<< /*isConstexpr*/ 0 << /*isConstructor*/ 0
- << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+ << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
else
Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
[[fallthrough]];
@@ -9903,8 +9903,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
// FIXME: We can compare the bytes in the correct order.
if (IsRawByte && !isOneByteCharacterType(CharTy)) {
Info.FFDiag(E, diag::note_constexpr_memchr_unsupported)
- << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str()
- << CharTy;
+ << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp) << CharTy;
return false;
}
// Figure out what value we're actually looking for (after converting to
@@ -9966,7 +9965,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
if (Info.getLangOpts().CPlusPlus11)
Info.CCEDiag(E, diag::note_constexpr_invalid_function)
<< /*isConstexpr*/ 0 << /*isConstructor*/ 0
- << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+ << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
else
Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
[[fallthrough]];
@@ -13241,7 +13240,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
if (Info.getLangOpts().CPlusPlus11)
Info.CCEDiag(E, diag::note_constexpr_invalid_function)
<< /*isConstexpr*/ 0 << /*isConstructor*/ 0
- << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+ << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
else
Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
[[fallthrough]];
@@ -13266,7 +13265,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
if (Info.getLangOpts().CPlusPlus11)
Info.CCEDiag(E, diag::note_constexpr_invalid_function)
<< /*isConstexpr*/ 0 << /*isConstructor*/ 0
- << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+ << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
else
Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
[[fallthrough]];
@@ -13321,8 +13320,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!(isOneByteCharacterType(CharTy1) && isOneByteCharacterType(CharTy2))) {
// FIXME: Consider using our bit_cast implementation to support this.
Info.FFDiag(E, diag::note_constexpr_memcmp_unsupported)
- << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str()
- << CharTy1 << CharTy2;
+ << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp) << CharTy1
+ << CharTy2;
return false;
}
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index 8dd1888..5881837 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -163,6 +163,10 @@ void Builtin::Context::initializeBuiltins(IdentifierTable &Table,
}
}
+std::string Builtin::Context::getQuotedName(unsigned ID) const {
+ return (llvm::Twine("'") + getName(ID) + "'").str();
+}
+
unsigned Builtin::Context::getRequiredVectorWidth(unsigned ID) const {
const char *WidthPos = ::strchr(getRecord(ID).Attributes, 'V');
if (!WidthPos)