Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-repl] Fix unboxing of va_args Value on 32-bit ARM (#94994) #96900

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Interpreter/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
void *m_Ptr;
};

static_assert(sizeof(Storage) <= 2 * sizeof(void *), "va_args");

public:
enum Kind {
#define X(type, name) K_##name,
Expand Down
31 changes: 30 additions & 1 deletion clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,36 @@ extern "C" void REPL_EXTERNAL_VISIBILITY __clang_Interpreter_SetValueNoAlloc(
} else {
if (const auto *ET = QT->getAs<EnumType>())
QT = ET->getDecl()->getIntegerType();
switch (QT->castAs<BuiltinType>()->getKind()) {

BuiltinType::Kind K = QT->castAs<BuiltinType>()->getKind();
#ifdef __arm__
switch (K) {
default:
llvm_unreachable("unknown type kind!");
case BuiltinType::Bool:
case BuiltinType::SChar:
case BuiltinType::Char_S:
case BuiltinType::Char_U:
case BuiltinType::UChar:
case BuiltinType::Short:
case BuiltinType::UShort:
case BuiltinType::Int:
case BuiltinType::UInt:
case BuiltinType::Long:
case BuiltinType::ULong:
case BuiltinType::LongLong:
case BuiltinType::ULongLong:
case BuiltinType::Float:
case BuiltinType::Double:
// Consume unused leading 32-bit of storage
va_arg(args, int);

case BuiltinType::LongDouble:
break;
}
#endif

switch (K) {
default:
llvm_unreachable("unknown type kind!");
break;
Expand Down
2 changes: 0 additions & 2 deletions clang/unittests/Interpreter/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ TEST_F(InterpreterTest, InstantiateTemplate) {

// This test exposes an ARM specific problem in the interpreter, see
// https://github.com/llvm/llvm-project/issues/94994.
#ifndef __arm__
TEST_F(InterpreterTest, Value) {
std::vector<const char *> Args = {"-fno-sized-deallocation"};
std::unique_ptr<Interpreter> Interp = createInterpreter(Args);
Expand Down Expand Up @@ -383,6 +382,5 @@ TEST_F(InterpreterTest, Value) {
EXPECT_EQ(V9.getKind(), Value::K_PtrOrObj);
EXPECT_TRUE(V9.isManuallyAlloc());
}
#endif /* ifndef __arm__ */

} // end anonymous namespace
Loading