Fix the case when the decl doesn't need mangling, adapt the test to the new impl.
This commit is contained in:
parent
72e1450eea
commit
64b1a77356
@ -46,16 +46,18 @@ namespace utils {
|
||||
|
||||
void Analyze::maybeMangleDeclName(const clang::GlobalDecl& GD,
|
||||
std::string& mangledName) {
|
||||
///Get the mangled name of a NamedDecl.
|
||||
///
|
||||
///D - mangle this decl's name
|
||||
///mangledName - put the mangled name in here
|
||||
// copied and adapted from clang::CodeGen::CodeGenModule::getMangledName
|
||||
|
||||
clang::NamedDecl* D
|
||||
= cast<NamedDecl>(const_cast<clang::Decl*>(GD.getDecl()));
|
||||
llvm::OwningPtr<MangleContext> mangleCtx;
|
||||
mangleCtx.reset(D->getASTContext().createMangleContext());
|
||||
assert(mangleCtx->shouldMangleDeclName(D) || D->getIdentifier()
|
||||
&& "Attempting to mangle unnamed decl.");
|
||||
if (!mangleCtx->shouldMangleDeclName(D)) {
|
||||
IdentifierInfo *II = D->getIdentifier();
|
||||
assert(II && "Attempt to mangle unnamed decl.");
|
||||
mangledName = II->getName();
|
||||
return;
|
||||
}
|
||||
|
||||
llvm::raw_string_ostream RawStr(mangledName);
|
||||
switch(D->getKind()) {
|
||||
|
@ -5,6 +5,7 @@ extern "C" int printf(const char*,...);
|
||||
#include "cling/Interpreter/Interpreter.h"
|
||||
#include "cling/Utils/AST.h"
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/AST/GlobalDecl.h"
|
||||
.rawInput
|
||||
const char* comp(void* A, void* B) {
|
||||
if (A == B) { return "equal"; }
|
||||
@ -18,7 +19,8 @@ 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);
|
||||
clang::VarDecl* VD = llvm::cast<clang::VarDecl>(D);
|
||||
void* addr2 = gCling->getAddressOfGlobal(clang::GlobalDecl(VD), &fromJIT);
|
||||
if (!fromJIT) printf("gMyGlobal should come from JIT!\n");
|
||||
printf("gMyGlobal: %s\n", comp(addr1, addr2)); // CHECK: gMyGlobal: equal
|
||||
|
||||
@ -31,9 +33,9 @@ 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);
|
||||
VD = llvm::cast<clang::VarDecl>(cling::utils::Lookup::Named(&sema, "gMyGlobal", ND));
|
||||
if (!VD) printf("N::gMyGlobal decl not found!\n");
|
||||
void* addrN2 = gCling->getAddressOfGlobal(clang::GlobalDecl(VD), &fromJIT);
|
||||
if (!fromJIT) printf("N::gMyGlobal should come from JIT!\n");
|
||||
printf("N::gMyGlobal: %s\n", comp(addrN1, addrN2)); //CHECK: N::gMyGlobal: equal
|
||||
|
||||
@ -41,8 +43,8 @@ printf("N::gMyGlobal: %s\n", comp(addrN1, addrN2)); //CHECK: N::gMyGlobal: equal
|
||||
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);
|
||||
VD = llvm::cast<clang::VarDecl>(cling::utils::Lookup::Named(&sema, "gLibGlobal"));
|
||||
if (!VD) printf("gLibGlobal decl not found!\n");
|
||||
void* addrL2 = gCling->getAddressOfGlobal(clang::GlobalDecl(VD), &fromJIT);
|
||||
if (fromJIT) printf("gLibGlobal should NOT come from JIT!\n");
|
||||
printf("gLibGlobal: %s\n", comp(addrL1, addrL2)); //CHECK: gLibGlobal: equal
|
||||
|
Loading…
x
Reference in New Issue
Block a user