[LLVMdev] RFC: Patch

Bill Wendling isanbard at gmail.com
Fri Sep 21 17:11:44 PDT 2007


Hi all,

I have a patch that would potentially help Objective-C 2. In the
"make_decl_llvm()" in llvm-backend.cpp, there is code to search
through the already generated global variables. Objective-C goes
through this code twice with the same identifier. The first time, is
to create meta-data for a "property". The second time is to add a
reference to that property into the correct ASM section.

Okay. so, the first time through, the variable's created and all is
good. It has "internal global" linkage, which is correct. The second
time through, it tries to look up that variable in the module, but
because it has "internal global" (and not "external global") linkage,
the "getGlobalVariable()" method returns null.

This patch uses the "getNamedGlobal" method, which ignores whether
it's internally or externally global.

My question is, is this liable to break something else down the line?
Should it be modified to call the getNamedGlobal method only if it's
an Objective-C property? Is this even the correct method for an
Objective-C property?

Thanks!
-bw

Index: llvm-backend.cpp
===================================================================
--- llvm-backend.cpp	(revision 42205)
+++ llvm-backend.cpp	(working copy)
@@ -1059,7 +1059,7 @@
     } else {
       // If the global has a name, prevent multiple vars with the
same name from
       // being created.
-      GlobalVariable *GVE = TheModule->getGlobalVariable(Name);
+      GlobalVariable *GVE = TheModule->getNamedGlobal(Name);

       if (GVE == 0) {
         GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage,0,



More information about the llvm-dev mailing list