tra created this revision.
tra added reviewers: jlebar, jordan_rose.
tra added a subscriber: cfe-commits.
GetOrCreateLLVMGlobal() accepts nullptr D, but in some cases we end up
dereferencing it without checking if it's non-null.
Fixes PR15492.
http://reviews.llvm.org/D20141
Files:
lib/CodeGen/CodeGenModule.cpp
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2080,7 +2080,7 @@
// Check that D is not yet in DiagnosedConflictingDefinitions is required
// to make sure that we issue an error only once.
- if (lookupRepresentativeDecl(MangledName, OtherGD) &&
+ if (D && lookupRepresentativeDecl(MangledName, OtherGD) &&
(D->getCanonicalDecl() != OtherGD.getCanonicalDecl().getDecl()) &&
(OtherD = dyn_cast<VarDecl>(OtherGD.getDecl())) &&
OtherD->hasInit() &&
@@ -2299,7 +2299,7 @@
unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
unsigned AddrSpace) {
- if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
+ if (D && LangOpts.CUDA && LangOpts.CUDAIsDevice) {
if (D->hasAttr<CUDAConstantAttr>())
AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
else if (D->hasAttr<CUDASharedAttr>())
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2080,7 +2080,7 @@
// Check that D is not yet in DiagnosedConflictingDefinitions is required
// to make sure that we issue an error only once.
- if (lookupRepresentativeDecl(MangledName, OtherGD) &&
+ if (D && lookupRepresentativeDecl(MangledName, OtherGD) &&
(D->getCanonicalDecl() != OtherGD.getCanonicalDecl().getDecl()) &&
(OtherD = dyn_cast<VarDecl>(OtherGD.getDecl())) &&
OtherD->hasInit() &&
@@ -2299,7 +2299,7 @@
unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
unsigned AddrSpace) {
- if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
+ if (D && LangOpts.CUDA && LangOpts.CUDAIsDevice) {
if (D->hasAttr<CUDAConstantAttr>())
AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
else if (D->hasAttr<CUDASharedAttr>())
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits