From 9f794ecb33cd08fb4f92b45d486d4790aeb913b9 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 31 Mar 2020 08:09:27 -0700 Subject: [PATCH 1/2] [SYCL][NFC] Move SYCL pipe metadata call to be inside the null check for D Found by a static analysis tool, maybeEmitPipeStorageMetadata immediately dereferences the "D" parameter. However, the current branch is in a situation where "D" could be nullptr. This patch moves it up into the checked section so that we don't risk this crash. Signed-off-by: Erich Keane --- clang/lib/CodeGen/CodeGenModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 37b453de9b99a..47a89fbef7d93 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3689,6 +3689,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, } } } + + if (LangOpts.SYCLIsDevice) + maybeEmitPipeStorageMetadata(D, GV, *this); } if (GV->isDeclaration()) @@ -3700,9 +3703,6 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, assert(getContext().getTargetAddressSpace(ExpectedAS) == Ty->getPointerAddressSpace()); - if (LangOpts.SYCLIsDevice) - maybeEmitPipeStorageMetadata(D, GV, *this); - if (AddrSpace != ExpectedAS) return getTargetCodeGenInfo().performAddrSpaceCast(*this, GV, AddrSpace, ExpectedAS, Ty); From a3de0f309a308644758bc58de07421b289f80c0e Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 31 Mar 2020 08:36:03 -0700 Subject: [PATCH 2/2] Fix clang-format issue Signed-off-by: Erich Keane --- clang/lib/CodeGen/CodeGenModule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 47a89fbef7d93..faeec44a7d4a7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3690,8 +3690,8 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, } } - if (LangOpts.SYCLIsDevice) - maybeEmitPipeStorageMetadata(D, GV, *this); + if (LangOpts.SYCLIsDevice) + maybeEmitPipeStorageMetadata(D, GV, *this); } if (GV->isDeclaration())