[cfe-commits] r55603 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/Type.cpp lib/CodeGen/CodeGenModule.cpp

Nuno Lopes nunoplopes at sapo.pt
Mon Sep 1 04:33:05 PDT 2008


Author: nlopes
Date: Mon Sep  1 06:33:04 2008
New Revision: 55603

URL: http://llvm.org/viewvc/llvm-project?rev=55603&view=rev
Log:
codegen constant data as such. add QualType::isConstant()

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=55603&r1=55602&r2=55603&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Sep  1 06:33:04 2008
@@ -131,6 +131,8 @@
   bool isRestrictQualified() const {
     return (ThePtr & Restrict) ? true : false;
   }
+
+  bool isConstant(ASTContext& Ctx) const;
   
   /// addConst/addVolatile/addRestrict - add the specified type qual to this
   /// QualType.

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=55603&r1=55602&r2=55603&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Mon Sep  1 06:33:04 2008
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
@@ -19,6 +20,16 @@
 #include <sstream>
 using namespace clang;
 
+bool QualType::isConstant(ASTContext& Ctx) const {
+  if (isConstQualified())
+    return true;
+
+  if (getTypePtr()->isArrayType())
+    return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx);
+
+  return false;
+}
+
 void Type::Destroy(ASTContext& C) { delete this; }
 
 void FunctionTypeProto::Destroy(ASTContext& C) {

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Sep  1 06:33:04 2008
@@ -449,6 +449,7 @@
   }
 
   GV->setInitializer(Init);
+  GV->setConstant(D->getType().isConstant(Context));
 
   // FIXME: This is silly; getTypeAlign should just work for incomplete arrays
   unsigned Align;





More information about the cfe-commits mailing list