[clang] 46446bb - [clang][bytecode][NFC] Diagnose non-constexpr builtin strcmp calls (#118442)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 00:49:30 PST 2024
Author: Timm Baeder
Date: 2024-12-03T09:49:26+01:00
New Revision: 46446bb2d31a7e3b2f857613b190150d41734696
URL: https://github.com/llvm/llvm-project/commit/46446bb2d31a7e3b2f857613b190150d41734696
DIFF: https://github.com/llvm/llvm-project/commit/46446bb2d31a7e3b2f857613b190150d41734696.diff
LOG: [clang][bytecode][NFC] Diagnose non-constexpr builtin strcmp calls (#118442)
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index f3024dc3e26fe1..8ff0fad0aa5a79 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -148,6 +148,17 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC,
#undef RET_CASE
}
+static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
+ unsigned ID) {
+ auto Loc = S.Current->getSource(OpPC);
+ if (S.getLangOpts().CPlusPlus11)
+ S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
+ << /*isConstexpr=*/0 << /*isConstructor=*/0
+ << ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
+ else
+ S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
+}
+
static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const CallExpr *Call) {
@@ -181,10 +192,14 @@ static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
- const CallExpr *Call) {
+ const Function *Func, const CallExpr *Call) {
+ unsigned ID = Func->getBuiltinID();
const Pointer &A = getParam<Pointer>(Frame, 0);
const Pointer &B = getParam<Pointer>(Frame, 1);
+ if (ID == Builtin::BIstrcmp)
+ diagnoseNonConstexprBuiltin(S, OpPC, ID);
+
if (!CheckLive(S, OpPC, A, AK_Read) || !CheckLive(S, OpPC, B, AK_Read))
return false;
@@ -222,16 +237,6 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
return true;
}
-static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
- unsigned ID) {
- auto Loc = S.Current->getSource(OpPC);
- if (S.getLangOpts().CPlusPlus11)
- S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
- << /*isConstexpr=*/0 << /*isConstructor=*/0
- << ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
- else
- S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
-}
static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call) {
@@ -1846,7 +1851,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
case Builtin::BI__assume:
break;
case Builtin::BI__builtin_strcmp:
- if (!interp__builtin_strcmp(S, OpPC, Frame, Call))
+ case Builtin::BIstrcmp:
+ if (!interp__builtin_strcmp(S, OpPC, Frame, F, Call))
return false;
break;
case Builtin::BI__builtin_strlen:
More information about the cfe-commits
mailing list