From 51ea81fcc640f5f24c543371e087f6680629e968 Mon Sep 17 00:00:00 2001 From: Greg Roth Date: Tue, 6 Oct 2020 14:29:48 -0600 Subject: [PATCH] Correct GV error message crash (#3161) When reporting a globalvariable associated error message without -Zi, an attempt is made to report the associated function, but there was no check to see if that function existed, so it crashed. Fixes #2989 --- tools/clang/lib/CodeGen/CodeGenAction.cpp | 6 ++++-- .../hlsl/objects/Texture/assign_texture_error.hlsl | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/assign_texture_error.hlsl diff --git a/tools/clang/lib/CodeGen/CodeGenAction.cpp b/tools/clang/lib/CodeGen/CodeGenAction.cpp index 8e8f1a569..76b687b70 100644 --- a/tools/clang/lib/CodeGen/CodeGenAction.cpp +++ b/tools/clang/lib/CodeGen/CodeGenAction.cpp @@ -560,8 +560,10 @@ BackendConsumer::DxilDiagHandler(const llvm::DiagnosticInfoDxil &D) { // and add function name to give some information if (Loc.isInvalid()) { Message += " Use /Zi for source location."; - if (auto *DiagClient = dynamic_cast(Diags.getClient())) - DiagClient->setPrefix("Function: " + D.getFunction()->getName().str()); + auto *DiagClient = dynamic_cast(Diags.getClient()); + auto *func = D.getFunction(); + if (DiagClient && func) + DiagClient->setPrefix("Function: " + func->getName().str()); } Diags.Report(Loc, DiagID).AddString(Message); diff --git a/tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/assign_texture_error.hlsl b/tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/assign_texture_error.hlsl new file mode 100644 index 000000000..1b64e577b --- /dev/null +++ b/tools/clang/test/HLSLFileCheck/hlsl/objects/Texture/assign_texture_error.hlsl @@ -0,0 +1,14 @@ +// RUN: %dxc -T ps_6_0 %s | FileCheck %s + +// CHECK: error: resource MyTexture could not be allocated + +Texture2D Textures[]; +Texture2D MyTexture; + +sampler samp : register(s0); + +float4 main() : SV_Target +{ + MyTexture = Textures[0]; + return MyTexture.Sample(samp, 0.0); +}