2012-09-24 19:16:36 +04:00
// RUN: clang -shared %S/address_lib.c -olibaddress_lib%shlibext
2013-04-25 20:22:23 +04:00
// RUN: cat %s | %cling -L. | FileCheck %s
2012-09-24 19:16:36 +04:00
extern " C " int printf ( const char * , . . . ) ;
# include "cling/Interpreter/Interpreter.h"
# include "cling/Utils/AST.h"
# include "clang/AST/Decl.h"
2013-10-25 20:41:14 +04:00
# include "clang/AST/GlobalDecl.h"
2012-09-24 19:16:36 +04:00
. 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 ;
2012-10-03 16:57:48 +04:00
clang : : Sema & sema = gCling - > getSema ( ) ;
2012-09-24 19:16:36 +04:00
int gMyGlobal = 12 ;
void * addr1 = & gMyGlobal ;
clang : : NamedDecl * D = cling : : utils : : Lookup : : Named ( & sema , " gMyGlobal " ) ;
if ( ! D ) printf ( " gMyGlobal decl not found! \n " ) ;
2013-10-25 20:41:14 +04:00
clang : : VarDecl * VD = llvm : : cast < clang : : VarDecl > ( D ) ;
void * addr2 = gCling - > getAddressOfGlobal ( clang : : GlobalDecl ( VD ) , & fromJIT ) ;
2012-09-24 19:16:36 +04:00
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 ;
2013-10-25 20:41:14 +04:00
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 ) ;
2012-09-24 19:16:36 +04:00
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 ;
2013-10-25 20:41:14 +04:00
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 ) ;
2012-09-24 19:16:36 +04:00
if ( fromJIT ) printf ( " gLibGlobal should NOT come from JIT! \n " ) ;
printf ( " gLibGlobal: %s \n " , comp ( addrL1 , addrL2 ) ) ; //CHECK: gLibGlobal: equal