Skip to content

Commit cb6db09

Browse files
committed
[clang][bytecode][NFC] Diagnose non-constexpr builtin strcmp calls
1 parent d097070 commit cb6db09

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC,
148148
#undef RET_CASE
149149
}
150150

151+
static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
152+
unsigned ID) {
153+
auto Loc = S.Current->getSource(OpPC);
154+
if (S.getLangOpts().CPlusPlus11)
155+
S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
156+
<< /*isConstexpr=*/0 << /*isConstructor=*/0
157+
<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
158+
else
159+
S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
160+
}
161+
151162
static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
152163
const InterpFrame *Frame,
153164
const CallExpr *Call) {
@@ -181,10 +192,14 @@ static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
181192

182193
static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
183194
const InterpFrame *Frame,
184-
const CallExpr *Call) {
195+
const Function *Func, const CallExpr *Call) {
196+
unsigned ID = Func->getBuiltinID();
185197
const Pointer &A = getParam<Pointer>(Frame, 0);
186198
const Pointer &B = getParam<Pointer>(Frame, 1);
187199

200+
if (ID == Builtin::BIstrcmp)
201+
diagnoseNonConstexprBuiltin(S, OpPC, ID);
202+
188203
if (!CheckLive(S, OpPC, A, AK_Read) || !CheckLive(S, OpPC, B, AK_Read))
189204
return false;
190205

@@ -222,16 +237,6 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
222237
return true;
223238
}
224239

225-
static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
226-
unsigned ID) {
227-
auto Loc = S.Current->getSource(OpPC);
228-
if (S.getLangOpts().CPlusPlus11)
229-
S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
230-
<< /*isConstexpr=*/0 << /*isConstructor=*/0
231-
<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
232-
else
233-
S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
234-
}
235240
static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
236241
const InterpFrame *Frame,
237242
const Function *Func, const CallExpr *Call) {
@@ -1846,7 +1851,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
18461851
case Builtin::BI__assume:
18471852
break;
18481853
case Builtin::BI__builtin_strcmp:
1849-
if (!interp__builtin_strcmp(S, OpPC, Frame, Call))
1854+
case Builtin::BIstrcmp:
1855+
if (!interp__builtin_strcmp(S, OpPC, Frame, F, Call))
18501856
return false;
18511857
break;
18521858
case Builtin::BI__builtin_strlen:

0 commit comments

Comments
 (0)