[llvm-commits] [dragonegg] r85443 - in /dragonegg/trunk: llvm-backend.cpp llvm-convert.cpp llvm-internal.h

Duncan Sands baldrick at free.fr
Wed Oct 28 15:24:06 PDT 2009


Author: baldrick
Date: Wed Oct 28 17:24:05 2009
New Revision: 85443

URL: http://llvm.org/viewvc/llvm-project?rev=85443&view=rev
Log:
Arrange for global constructors and destructors to be run.
This may explain why a lot of C++ code wasn't being compiled
correctly!

Modified:
    dragonegg/trunk/llvm-backend.cpp
    dragonegg/trunk/llvm-convert.cpp
    dragonegg/trunk/llvm-internal.h

Modified: dragonegg/trunk/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-backend.cpp?rev=85443&r1=85442&r2=85443&view=diff

==============================================================================
--- dragonegg/trunk/llvm-backend.cpp (original)
+++ dragonegg/trunk/llvm-backend.cpp Wed Oct 28 17:24:05 2009
@@ -1539,16 +1539,11 @@
   }
 }
 
-/// llvm_emit_ctor_dtor - Called to emit static ctors/dtors to LLVM code.
-/// fndecl is a 'void()' FUNCTION_DECL for the code, initprio is the init
+/// register_ctor_dtor - Called to register static ctors/dtors with LLVM.
+/// Fn is a 'void()' ctor/dtor function to be run, initprio is the init
 /// priority, and isCtor indicates whether this is a ctor or dtor.
-void llvm_emit_ctor_dtor(tree FnDecl, int InitPrio, int isCtor) {
-  mark_decl_referenced(FnDecl);  // Inform cgraph that we used the global.
-
-  if (errorcount || sorrycount) return;
-
-  Constant *C = cast<Constant>(DECL_LLVM(FnDecl));
-  (isCtor ? &StaticCtors:&StaticDtors)->push_back(std::make_pair(C, InitPrio));
+void register_ctor_dtor(Function *Fn, int InitPrio, bool isCtor) {
+  (isCtor ? &StaticCtors:&StaticDtors)->push_back(std::make_pair(Fn, InitPrio));
 }
 
 void llvm_emit_typedef(tree decl) {

Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=85443&r1=85442&r2=85443&view=diff

==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Wed Oct 28 17:24:05 2009
@@ -618,6 +618,12 @@
   // Handle visibility style
   handleVisibility(FnDecl, Fn);
 
+  // Register constructors and destructors.
+  if (DECL_STATIC_CONSTRUCTOR(FnDecl))
+    register_ctor_dtor(Fn, DECL_INIT_PRIORITY(FnDecl), true);
+  if (DECL_STATIC_DESTRUCTOR(FnDecl))
+    register_ctor_dtor(Fn, DECL_FINI_PRIORITY(FnDecl), false);
+
   // Handle attribute "aligned".
   if (DECL_ALIGN (FnDecl) != FUNCTION_BOUNDARY)
     Fn->setAlignment(DECL_ALIGN (FnDecl) / 8);

Modified: dragonegg/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-internal.h?rev=85443&r1=85442&r2=85443&view=diff

==============================================================================
--- dragonegg/trunk/llvm-internal.h (original)
+++ dragonegg/trunk/llvm-internal.h Wed Oct 28 17:24:05 2009
@@ -119,6 +119,7 @@
 #define DECL_LLVM_SET_P(NODE) (DECL_LLVM_IF_SET(NODE) != NULL)
 
 void changeLLVMConstant(Constant *Old, Constant *New);
+void register_ctor_dtor(Function *, int, bool);
 void readLLVMTypesStringTable();
 void writeLLVMTypesStringTable();
 void readLLVMValues();





More information about the llvm-commits mailing list