diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2008-09-01 11:33:04 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2008-09-01 11:33:04 +0000 |
commit | f380a0de07881404633095f16efe921b98b8986c (patch) | |
tree | 5c3dd0696519cfb7eb271415bd544beb392e586b | |
parent | fa558788e76cfcbdf06e3b7f9a2bc3b9825066e3 (diff) | |
download | bcm5719-llvm-f380a0de07881404633095f16efe921b98b8986c.tar.gz bcm5719-llvm-f380a0de07881404633095f16efe921b98b8986c.zip |
codegen constant data as such. add QualType::isConstant()
llvm-svn: 55603
-rw-r--r-- | clang/include/clang/AST/Type.h | 2 | ||||
-rw-r--r-- | clang/lib/AST/Type.cpp | 11 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 1 |
3 files changed, 14 insertions, 0 deletions
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 2921132becb..b3fefb265e9 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -131,6 +131,8 @@ public: bool isRestrictQualified() const { return (ThePtr & Restrict) ? true : false; } + + bool isConstant(ASTContext& Ctx) const; /// addConst/addVolatile/addRestrict - add the specified type qual to this /// QualType. diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 2c5a3f41bf9..41cd828f01c 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -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) { diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 27dd600f0a2..5b784aada3f 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -449,6 +449,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { } GV->setInitializer(Init); + GV->setConstant(D->getType().isConstant(Context)); // FIXME: This is silly; getTypeAlign should just work for incomplete arrays unsigned Align; |