Skip to content

Commit 56fd34e

Browse files
committed
Address review comments
1 parent 6270821 commit 56fd34e

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class Interpreter {
189189
// clang::Values.
190190
mutable llvm::DenseMap<CXXRecordDecl *, llvm::orc::ExecutorAddr> Dtors;
191191

192-
std::array<Expr *, 4> ValuePrintingInfo;
192+
std::array<Expr *, 4> ValuePrintingInfo = {0};
193193

194194
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder;
195195

clang/include/clang/Interpreter/Value.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535

3636
#include "llvm/Config/llvm-config.h" // for LLVM_BUILD_LLVM_DYLIB, LLVM_BUILD_SHARED_LIBS
3737
#include "llvm/Support/Compiler.h"
38+
#include <cassert>
3839
#include <cstdint>
3940

4041
// NOTE: Since the REPL itself could also include this runtime, extreme caution
4142
// should be taken when MAKING CHANGES to this file, especially when INCLUDE NEW
4243
// HEADERS, like <string>, <memory> and etc. (That pulls a large number of
4344
// tokens and will impact the runtime performance of the REPL)
4445

46+
extern "C" void *memcpy(void *dest, const void *src, size_t n);
47+
4548
namespace llvm {
4649
class raw_ostream;
4750

@@ -97,6 +100,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
97100
REPL_BUILTIN_TYPES
98101
#undef X
99102
void *m_Ptr;
103+
unsigned char m_RawBits[sizeof(long double) * 8]; // widest type
100104
};
101105

102106
public:
@@ -138,6 +142,10 @@ class REPL_EXTERNAL_VISIBILITY Value {
138142

139143
void *getPtr() const;
140144
void setPtr(void *Ptr) { Data.m_Ptr = Ptr; }
145+
void setRawBits(void *Ptr, unsigned NBits = sizeof(Storage)) {
146+
assert(NBits <= sizeof(Storage) && "Greater than the total size");
147+
memcpy(/*dest=*/Data.m_RawBits, /*src=*/Ptr, /*nbytes=*/NBits / 8);
148+
}
141149

142150
#define X(type, name) \
143151
void set##name(type Val) { Data.m_##name = Val; } \

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ Interpreter::GenModule(IncrementalAction *Action) {
815815
// of the module which does not map well to CodeGen's design. To work this
816816
// around we created an empty module to make CodeGen happy. We should make
817817
// sure it always stays empty.
818-
assert((!CachedInCodeGenModule ||
819-
!getCompilerInstance()->getPreprocessorOpts().Includes.empty()) ||
820-
((CachedInCodeGenModule->empty() &&
821-
CachedInCodeGenModule->global_empty() &&
822-
CachedInCodeGenModule->alias_empty() &&
823-
CachedInCodeGenModule->ifunc_empty())) &&
824-
"CodeGen wrote to a readonly module");
818+
assert(((!CachedInCodeGenModule ||
819+
!getCompilerInstance()->getPreprocessorOpts().Includes.empty()) ||
820+
((CachedInCodeGenModule->empty() &&
821+
CachedInCodeGenModule->global_empty() &&
822+
CachedInCodeGenModule->alias_empty() &&
823+
CachedInCodeGenModule->ifunc_empty()))) &&
824+
"CodeGen wrote to a readonly module");
825825
std::unique_ptr<llvm::Module> M(CG->ReleaseModule());
826826
CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());
827827
return M;

clang/lib/Interpreter/InterpreterValuePrinter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ struct ValueRef : public Value {
184184
// Tell the base class to not try to deallocate if it manages the value.
185185
IsManuallyAlloc = false;
186186
}
187-
void setData(long double D) { Data.m_LongDouble = D; }
188187
};
189188

190189
std::string Interpreter::ValueDataToString(const Value &V) const {
@@ -212,7 +211,7 @@ std::string Interpreter::ValueDataToString(const Value &V) const {
212211
if (ElemTy->isBuiltinType()) {
213212
// Single dim arrays, advancing.
214213
uintptr_t Offset = (uintptr_t)V.getPtr() + Idx * ElemSize;
215-
InnerV.setData(*(long double *)Offset);
214+
InnerV.setRawBits((void *)Offset, ElemSize * 8);
216215
} else {
217216
// Multi dim arrays, position to the next dimension.
218217
size_t Stride = ElemCount / N;

clang/test/Interpreter/pretty-print.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ float farr[2][1] = { {0}, {3.14}}; farr
7070
0.00001f
7171
// CHECK-NEXT: (float) 1.00000e-05f
7272

73-
73+
// TODO: _Bool, _Complex, _Atomic, and _BitInt
74+
// union U { int I; float F; } u; u.I = 12; u.I
75+
// TODO-CHECK-NEXT: (int) 12
7476
// struct S1{} s1; s1
7577
// TODO-CHECK-NEXT: (S1 &) @0x{{[0-9a-f]+}}
7678

clang/test/Interpreter/pretty-print.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ s3
2626
struct S4 { ~S4() { printf("~S4()\n"); }};
2727
S4{}
2828
// CHECK-NEXT: (S4) @0x{{[0-9a-f]+}}
29+
// TODO-CHECK-NEXT: ~S4()
2930

3031
enum Enum{ e1 = -12, e2, e3=33, e4, e5 = 33};
3132
e2

0 commit comments

Comments
 (0)