Skip to content

Commit 73e2715

Browse files
committed
Review commnents handled, code refactoring
1 parent 2fc0601 commit 73e2715

File tree

4 files changed

+629
-59
lines changed

4 files changed

+629
-59
lines changed

clang/lib/CodeGen/CGGPUBuiltin.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include "CodeGenFunction.h"
1515
#include "clang/Basic/Builtins.h"
1616
#include "clang/Basic/TargetBuiltins.h"
17+
#include "llvm/Analysis/ValueTracking.h"
1718
#include "llvm/IR/DataLayout.h"
19+
#include "llvm/IR/DiagnosticInfo.h"
1820
#include "llvm/IR/Instruction.h"
1921
#include "llvm/Support/MathExtras.h"
2022
#include "llvm/Transforms/Utils/AMDGPUEmitPrintf.h"
@@ -219,7 +221,23 @@ RValue CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
219221
auto PFK = CGM.getTarget().getTargetOpts().AMDGPUPrintfKindVal;
220222
bool isBuffered =
221223
(PFK == clang::TargetOptions::AMDGPUPrintfKind::Buffered);
222-
auto Printf = llvm::emitAMDGPUPrintfCall(IRB, Args, isBuffered);
224+
225+
StringRef FmtStr;
226+
if (llvm::getConstantStringInfo(Args[0], FmtStr)) {
227+
if (FmtStr.empty())
228+
FmtStr = StringRef("", 1);
229+
} else {
230+
if (CGM.getLangOpts().OpenCL) {
231+
llvm::DiagnosticInfoUnsupported UnsupportedFormatStr(
232+
*IRB.GetInsertBlock()->getParent(),
233+
"printf format string must be a trivially resolved constant string "
234+
"global variable",
235+
IRB.getCurrentDebugLocation());
236+
IRB.getContext().diagnose(UnsupportedFormatStr);
237+
}
238+
}
239+
240+
auto Printf = llvm::emitAMDGPUPrintfCall(IRB, Args, FmtStr, isBuffered);
223241
Builder.SetInsertPoint(IRB.GetInsertBlock(), IRB.GetInsertPoint());
224242
return RValue::get(Printf);
225243
}

0 commit comments

Comments
 (0)