[clang] 336530b - CGOpenMPRuntime::emitDeclareTargetVarDefinition - fix static analyzer null dereference warning. NFCI.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 12 11:53:30 PDT 2020


Author: Simon Pilgrim
Date: 2020-03-12T18:52:57Z
New Revision: 336530be07256728e2f4e7ae3d332f2e8939dbad

URL: https://github.com/llvm/llvm-project/commit/336530be07256728e2f4e7ae3d332f2e8939dbad
DIFF: https://github.com/llvm/llvm-project/commit/336530be07256728e2f4e7ae3d332f2e8939dbad.diff

LOG: CGOpenMPRuntime::emitDeclareTargetVarDefinition - fix static analyzer null dereference warning. NFCI.

All paths test for or dereference the VD pointer, so just assert that its not null.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGOpenMPRuntime.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index d769691ba26e..9e88b6ef9315 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2933,12 +2933,14 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
        HasRequiresUnifiedSharedMemory))
     return CGM.getLangOpts().OpenMPIsDevice;
   VD = VD->getDefinition(CGM.getContext());
-  if (VD && !DeclareTargetWithDefinition.insert(CGM.getMangledName(VD)).second)
+  assert(VD && "Unknown VarDecl");
+
+  if (!DeclareTargetWithDefinition.insert(CGM.getMangledName(VD)).second)
     return CGM.getLangOpts().OpenMPIsDevice;
 
   QualType ASTTy = VD->getType();
-
   SourceLocation Loc = VD->getCanonicalDecl()->getBeginLoc();
+
   // Produce the unique prefix to identify the new target regions. We use
   // the source location of the variable declaration which we know to not
   // conflict with any target region.


        


More information about the cfe-commits mailing list