From 04a106f3db96ce8339e7fcfb2c4bb1219f16b7a8 Mon Sep 17 00:00:00 2001 From: Anthony Cowley Date: Tue, 23 Oct 2018 20:34:16 -0400 Subject: [PATCH] Ensure FlatWGS attribute is not null before inspecting --- lib/CodeGen/TargetInfo.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 11ebc44a9ac..ba18911b385 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -7757,11 +7757,15 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes( const auto *FlatWGS = FD->getAttr(); if (ReqdWGS || FlatWGS) { - llvm::APSInt min = getConstexprInt(FlatWGS->getMin(), FD->getASTContext()); - llvm::APSInt max = getConstexprInt(FlatWGS->getMax(), FD->getASTContext()); + unsigned Min = 0, Max = 0; + if (FlatWGS != nullptr) { + llvm::APSInt min = getConstexprInt(FlatWGS->getMin(), FD->getASTContext()); + llvm::APSInt max = getConstexprInt(FlatWGS->getMax(), FD->getASTContext()); + + Min = min.getZExtValue(); + Max = std::max(min, max).getZExtValue(); + } - unsigned Min = min.getZExtValue(); - unsigned Max = std::max(min, max).getZExtValue(); if (ReqdWGS && Min == 0 && Max == 0) Min = Max = ReqdWGS->getXDim() * ReqdWGS->getYDim() * ReqdWGS->getZDim();