[clang][bytecode] Diagnose integral source/dest in memcpy (#132715)
Like the current interpreter does.
This commit is contained in:
@@ -1792,6 +1792,17 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Diagnose integral src/dest pointers specially.
|
||||
if (SrcPtr.isIntegralPointer() || DestPtr.isIntegralPointer()) {
|
||||
std::string DiagVal = "(void *)";
|
||||
DiagVal += SrcPtr.isIntegralPointer()
|
||||
? std::to_string(SrcPtr.getIntegerRepresentation())
|
||||
: std::to_string(DestPtr.getIntegerRepresentation());
|
||||
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_memcpy_null)
|
||||
<< Move << false << DestPtr.isIntegralPointer() << DiagVal;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Can't read from dummy pointers.
|
||||
if (DestPtr.isDummy() || SrcPtr.isDummy())
|
||||
return false;
|
||||
|
||||
@@ -1290,6 +1290,12 @@ namespace BuiltinMemcpy {
|
||||
return Result1 && Result2;
|
||||
}
|
||||
static_assert(memmoveOverlapping());
|
||||
|
||||
#define fold(x) (__builtin_constant_p(0) ? (x) : (x))
|
||||
static_assert(__builtin_memcpy(&global, fold((wchar_t*)123), sizeof(wchar_t))); // both-error {{not an integral constant expression}} \
|
||||
// both-note {{source of 'memcpy' is (void *)123}}
|
||||
static_assert(__builtin_memcpy(fold(reinterpret_cast<wchar_t*>(123)), &global, sizeof(wchar_t))); // both-error {{not an integral constant expression}} \
|
||||
// both-note {{destination of 'memcpy' is (void *)123}}
|
||||
}
|
||||
|
||||
namespace Memcmp {
|
||||
|
||||
Reference in New Issue
Block a user