[clang][bytecode] Guard strcmp against differing element types (#154777)
This can happen when casts are involved. Fixes #154006
This commit is contained in:
parent
dacabc1fee
commit
3923adfa3f
@ -205,6 +205,8 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
|
|||||||
|
|
||||||
if (A.isDummy() || B.isDummy())
|
if (A.isDummy() || B.isDummy())
|
||||||
return false;
|
return false;
|
||||||
|
if (!A.isBlockPointer() || !B.isBlockPointer())
|
||||||
|
return false;
|
||||||
|
|
||||||
bool IsWide = ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp ||
|
bool IsWide = ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp ||
|
||||||
ID == Builtin::BI__builtin_wcscmp ||
|
ID == Builtin::BI__builtin_wcscmp ||
|
||||||
@ -212,7 +214,10 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
|
|||||||
assert(A.getFieldDesc()->isPrimitiveArray());
|
assert(A.getFieldDesc()->isPrimitiveArray());
|
||||||
assert(B.getFieldDesc()->isPrimitiveArray());
|
assert(B.getFieldDesc()->isPrimitiveArray());
|
||||||
|
|
||||||
assert(getElemType(A).getTypePtr() == getElemType(B).getTypePtr());
|
// Different element types shouldn't happen, but with casts they can.
|
||||||
|
if (!S.getASTContext().hasSameUnqualifiedType(getElemType(A), getElemType(B)))
|
||||||
|
return false;
|
||||||
|
|
||||||
PrimType ElemT = *S.getContext().classify(getElemType(A));
|
PrimType ElemT = *S.getContext().classify(getElemType(A));
|
||||||
|
|
||||||
auto returnResult = [&](int V) -> bool {
|
auto returnResult = [&](int V) -> bool {
|
||||||
|
@ -338,3 +338,12 @@ static void *FooTable[1] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int strcmp(const char *, const char *); // all-note {{passing argument to parameter here}}
|
||||||
|
#define S "\x01\x02\x03\x04\x05\x06\x07\x08"
|
||||||
|
const char _str[] = {S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7]};
|
||||||
|
const unsigned char _str2[] = {S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7]};
|
||||||
|
const int compared = strcmp(_str, (const char *)_str2); // all-error {{initializer element is not a compile-time constant}}
|
||||||
|
|
||||||
|
|
||||||
|
const int compared2 = strcmp(strcmp, _str); // all-warning {{incompatible pointer types}} \
|
||||||
|
// all-error {{initializer element is not a compile-time constant}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user