From: Nuno Lopes Date: Mon, 1 Sep 2008 11:33:04 +0000 (+0000) Subject: codegen constant data as such. add QualType::isConstant() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b381aac9bae6d608c72267dd0ed08ec6369e94e4;p=clang codegen constant data as such. add QualType::isConstant() git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55603 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 2921132bec..b3fefb265e 100644 --- a/include/clang/AST/Type.h +++ b/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/lib/AST/Type.cpp b/lib/AST/Type.cpp index 2c5a3f41bf..41cd828f01 100644 --- a/lib/AST/Type.cpp +++ b/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 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/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 27dd600f0a..5b784aada3 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/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;