[cfe-commits] r81480 - in /cfe/trunk/lib/CodeGen: CodeGenModule.cpp CodeGenModule.h

Anders Carlsson andersca at mac.com
Thu Sep 10 16:38:47 PDT 2009


Author: andersca
Date: Thu Sep 10 18:38:47 2009
New Revision: 81480

URL: http://llvm.org/viewvc/llvm-project?rev=81480&view=rev
Log:
Add stricter GlobalDecl constructors.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=81480&r1=81479&r2=81480&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Sep 10 18:38:47 2009
@@ -141,7 +141,7 @@
 }
 
 const char *CodeGenModule::getMangledName(const GlobalDecl &GD) {
-  const NamedDecl *ND = GD.getDecl();
+  const NamedDecl *ND = cast<NamedDecl>(GD.getDecl());
 
   if (const CXXConstructorDecl *D = dyn_cast<CXXConstructorDecl>(ND))
     return getMangledCXXCtorName(D, GD.getCtorType());
@@ -545,7 +545,7 @@
 }
 
 void CodeGenModule::EmitGlobal(GlobalDecl GD) {
-  const ValueDecl *Global = GD.getDecl();
+  const ValueDecl *Global = cast<ValueDecl>(GD.getDecl());
 
   // If this is an alias definition (which otherwise looks like a declaration)
   // emit it now.
@@ -594,7 +594,7 @@
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) {
-  const ValueDecl *D = GD.getDecl();
+  const ValueDecl *D = cast<ValueDecl>(GD.getDecl());
 
   if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D))
     EmitCXXConstructor(CD, GD.getCtorType());
@@ -810,7 +810,7 @@
                                                  const llvm::Type *Ty) {
   // If there was no specific requested type, just convert it now.
   if (!Ty)
-    Ty = getTypes().ConvertType(GD.getDecl()->getType());
+    Ty = getTypes().ConvertType(cast<ValueDecl>(GD.getDecl())->getType());
   return GetOrCreateLLVMFunction(getMangledName(GD), Ty, GD);
 }
 
@@ -1643,7 +1643,7 @@
     // Fall through
 
   case Decl::Var:
-    EmitGlobal(GlobalDecl(cast<ValueDecl>(D)));
+    EmitGlobal(GlobalDecl(cast<VarDecl>(D)));
     break;
 
   // C++ Decls

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=81480&r1=81479&r2=81480&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Sep 10 18:38:47 2009
@@ -70,23 +70,31 @@
 /// GlobalDecl - represents a global declaration. This can either be a
 /// CXXConstructorDecl and the constructor type (Base, Complete).
 /// a CXXDestructorDecl and the destructor type (Base, Complete) or
-// a regular VarDecl or a FunctionDecl.
+/// a VarDecl, a FunctionDecl or a BlockDecl.
 class GlobalDecl {
-  llvm::PointerIntPair<const ValueDecl*, 2> Value;
+  llvm::PointerIntPair<const Decl*, 2> Value;
 
+  void init(const Decl *D) {
+    assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
+    assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
+    assert(isa<VarDecl>(D) || isa<FunctionDecl>(D)
+           && "Invalid decl type passed to GlobalDecl ctor!");
+
+    Value.setPointer(D);
+  }
+  
 public:
   GlobalDecl() {}
 
-  explicit GlobalDecl(const ValueDecl *VD) : Value(VD, 0) {
-    assert(!isa<CXXConstructorDecl>(VD) && "Use other ctor with ctor decls!");
-    assert(!isa<CXXDestructorDecl>(VD) && "Use other ctor with dtor decls!");
-  }
+  GlobalDecl(const VarDecl *D) { init(D);}
+  GlobalDecl(const FunctionDecl *D) { init(D); }
+  
   GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
   : Value(D, Type) {}
   GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
   : Value(D, Type) {}
 
-  const ValueDecl *getDecl() const { return Value.getPointer(); }
+  const Decl *getDecl() const { return Value.getPointer(); }
 
   CXXCtorType getCtorType() const {
     assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");





More information about the cfe-commits mailing list