Add tests for Interpreter::getAddressOfGlobal().
Fix it for the JIT case. git-svn-id: http://root.cern.ch/svn/root/trunk@46146 27541ba8-7e3a-0410-8455-c3a389f83636
This commit is contained in:
parent
a23e654580
commit
fe430cd40d
@ -285,7 +285,7 @@ void* ExecutionContext::getAddressOfGlobal(llvm::Module* m,
|
||||
if (fromJIT) *fromJIT = true;
|
||||
llvm::GlobalVariable* gvar
|
||||
= m->getGlobalVariable(symbolName, true);
|
||||
address = m_engine->getPointerToGlobalIfAvailable(gvar);
|
||||
address = m_engine->getPointerToGlobal(gvar);
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
49
test/Interfaces/address.C
Normal file
49
test/Interfaces/address.C
Normal file
@ -0,0 +1,49 @@
|
||||
// RUN: clang -shared %S/address_lib.c -olibaddress_lib%shlibext
|
||||
// RUN: cat %s | %cling | FileCheck %s
|
||||
extern "C" int printf(const char*,...);
|
||||
|
||||
#include "cling/Interpreter/Interpreter.h"
|
||||
#include "cling/Utils/AST.h"
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
.rawInput
|
||||
const char* comp(void* A, void* B) {
|
||||
if (A == B) { return "equal"; }
|
||||
else { printf("[%p %p] ", A, B); return "DIFFER!"; }
|
||||
}
|
||||
.rawInput
|
||||
|
||||
bool fromJIT = false;
|
||||
clang::Sema& sema = gCling->getCI()->getSema();
|
||||
int gMyGlobal = 12;
|
||||
void* addr1 = &gMyGlobal;
|
||||
clang::NamedDecl* D = cling::utils::Lookup::Named(&sema, "gMyGlobal");
|
||||
if (!D) printf("gMyGlobal decl not found!\n");
|
||||
void* addr2 = gCling->getAddressOfGlobal(D, &fromJIT);
|
||||
if (!fromJIT) printf("gMyGlobal should come from JIT!\n");
|
||||
printf("gMyGlobal: %s\n", comp(addr1, addr2)); // CHECK: gMyGlobal: equal
|
||||
|
||||
.rawInput
|
||||
namespace N {
|
||||
int gMyGlobal = 13;
|
||||
}
|
||||
.rawInput
|
||||
void* addrN1 = &N::gMyGlobal;
|
||||
clang::NamespaceDecl* ND = cling::utils::Lookup::Namespace(&sema, "N");
|
||||
if (!ND) printf("namespace N decl not found!\n");
|
||||
fromJIT = false;
|
||||
clang::NamedDecl* NDD = cling::utils::Lookup::Named(&sema, "gMyGlobal", ND);
|
||||
if (!NDD) printf("N::gMyGlobal decl not found!\n");
|
||||
void* addrN2 = gCling->getAddressOfGlobal(NDD, &fromJIT);
|
||||
if (!fromJIT) printf("N::gMyGlobal should come from JIT!\n");
|
||||
printf("N::gMyGlobal: %s\n", comp(addrN1, addrN2)); //CHECK: N::gMyGlobal: equal
|
||||
|
||||
.L address_lib
|
||||
extern "C" int gLibGlobal;
|
||||
void* addrL1 = &gLibGlobal;
|
||||
fromJIT = true;
|
||||
clang::NamedDecl* LD = cling::utils::Lookup::Named(&sema, "gLibGlobal");
|
||||
if (!LD) printf("gLibGlobal decl not found!\n");
|
||||
void* addrL2 = gCling->getAddressOfGlobal(LD, &fromJIT);
|
||||
if (fromJIT) printf("gLibGlobal should NOT come from JIT!\n");
|
||||
printf("gLibGlobal: %s\n", comp(addrL1, addrL2)); //CHECK: gLibGlobal: equal
|
3
test/Interfaces/address_lib.c
Normal file
3
test/Interfaces/address_lib.c
Normal file
@ -0,0 +1,3 @@
|
||||
// RUN: true
|
||||
// Used as library source by address.C
|
||||
int gLibGlobal = 14;
|
Loading…
x
Reference in New Issue
Block a user