From 2e1eac5919a56fd15a7c79281d6544c4958d6874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= Date: Thu, 27 Jun 2024 14:28:03 +0200 Subject: [PATCH] [clang-repl] Fix unboxing of va_args Value on 32-bit ARM --- clang/include/clang/Interpreter/Value.h | 2 ++ clang/lib/Interpreter/Interpreter.cpp | 31 ++++++++++++++++++- .../unittests/Interpreter/InterpreterTest.cpp | 2 -- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Interpreter/Value.h b/clang/include/clang/Interpreter/Value.h index d70e8f8719026..f1dcae2d672c0 100644 --- a/clang/include/clang/Interpreter/Value.h +++ b/clang/include/clang/Interpreter/Value.h @@ -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, diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 7a95278914276..11f3273dff45f 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -877,7 +877,36 @@ extern "C" void REPL_EXTERNAL_VISIBILITY __clang_Interpreter_SetValueNoAlloc( } else { if (const auto *ET = QT->getAs()) QT = ET->getDecl()->getIntegerType(); - switch (QT->castAs()->getKind()) { + + BuiltinType::Kind K = QT->castAs()->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; diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index bbd854149d5f5..37978b09adad2 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -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 Args = {"-fno-sized-deallocation"}; std::unique_ptr Interp = createInterpreter(Args); @@ -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