forked from OSchip/llvm-project
local static vars are globals also. This fixes a testcase
reported by Seo. llvm-svn: 45156
This commit is contained in:
parent
d4fc27e937
commit
37bd2ecb11
|
@ -273,7 +273,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
|
|||
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
||||
return LValue::MakeAddr(CGM.GetAddrOfFunctionDecl(FD, false));
|
||||
} else if (const FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
|
||||
return LValue::MakeAddr(CGM.GetAddrOfFileVarDecl(FVD, false));
|
||||
return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(FVD, false));
|
||||
}
|
||||
assert(0 && "Unimp declref");
|
||||
//an invalid LValue, but the assert will
|
||||
|
|
|
@ -113,8 +113,10 @@ llvm::Constant *CodeGenModule::GetAddrOfFunctionDecl(const FunctionDecl *D,
|
|||
return Entry = NewFn;
|
||||
}
|
||||
|
||||
llvm::Constant *CodeGenModule::GetAddrOfFileVarDecl(const FileVarDecl *D,
|
||||
bool isDefinition) {
|
||||
llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
|
||||
bool isDefinition) {
|
||||
assert(D->hasGlobalStorage() && "Not a global variable");
|
||||
|
||||
// See if it is already in the map.
|
||||
llvm::Constant *&Entry = GlobalDeclMap[D];
|
||||
if (Entry) return Entry;
|
||||
|
@ -433,8 +435,8 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression,
|
|||
// The only thing that can have array type like this is a
|
||||
// DeclRefExpr(FileVarDecl)?
|
||||
const DeclRefExpr *DRE = cast<DeclRefExpr>(ICExpr->getSubExpr());
|
||||
const FileVarDecl *FVD = cast<FileVarDecl>(DRE->getDecl());
|
||||
llvm::Constant *C = CGM.GetAddrOfFileVarDecl(FVD, false);
|
||||
const VarDecl *VD = cast<VarDecl>(DRE->getDecl());
|
||||
llvm::Constant *C = CGM.GetAddrOfGlobalVar(VD, false);
|
||||
assert(isa<llvm::PointerType>(C->getType()) &&
|
||||
isa<llvm::ArrayType>(cast<llvm::PointerType>(C->getType())
|
||||
->getElementType()));
|
||||
|
@ -486,7 +488,7 @@ void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
|
|||
|
||||
// Get the global, forcing it to be a direct reference.
|
||||
llvm::GlobalVariable *GV =
|
||||
cast<llvm::GlobalVariable>(GetAddrOfFileVarDecl(D, true));
|
||||
cast<llvm::GlobalVariable>(GetAddrOfGlobalVar(D, true));
|
||||
|
||||
// Convert the initializer, or use zero if appropriate.
|
||||
llvm::Constant *Init = 0;
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace clang {
|
|||
class Expr;
|
||||
class Stmt;
|
||||
class ValueDecl;
|
||||
class VarDecl;
|
||||
class FileVarDecl;
|
||||
struct LangOptions;
|
||||
class Diagnostic;
|
||||
|
@ -69,8 +70,7 @@ public:
|
|||
|
||||
llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D,
|
||||
bool isDefinition);
|
||||
llvm::Constant *GetAddrOfFileVarDecl(const FileVarDecl *D,
|
||||
bool isDefinition);
|
||||
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition);
|
||||
|
||||
|
||||
/// getBuiltinLibFunction - Given a builtin id for a function like
|
||||
|
|
|
@ -19,3 +19,10 @@ int (*mb_ptr2len) (char *p) = latin_ptr2len;
|
|||
char string[8] = "string"; // extend init
|
||||
char string2[4] = "string"; // truncate init
|
||||
|
||||
char *test(int c) {
|
||||
static char buf[10];
|
||||
static char *bufptr = buf;
|
||||
|
||||
return c ? buf : bufptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue