Skip to content

Commit e05ffbd

Browse files
committed
Review commnents handled, code refactoring
1 parent f937af4 commit e05ffbd

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"
@@ -220,7 +222,23 @@ RValue CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
220222
auto PFK = CGM.getTarget().getTargetOpts().AMDGPUPrintfKindVal;
221223
bool isBuffered =
222224
(PFK == clang::TargetOptions::AMDGPUPrintfKind::Buffered);
223-
auto Printf = llvm::emitAMDGPUPrintfCall(IRB, Args, isBuffered);
225+
226+
StringRef FmtStr;
227+
if (llvm::getConstantStringInfo(Args[0], FmtStr)) {
228+
if (FmtStr.empty())
229+
FmtStr = StringRef("", 1);
230+
} else {
231+
if (CGM.getLangOpts().OpenCL) {
232+
llvm::DiagnosticInfoUnsupported UnsupportedFormatStr(
233+
*IRB.GetInsertBlock()->getParent(),
234+
"printf format string must be a trivially resolved constant string "
235+
"global variable",
236+
IRB.getCurrentDebugLocation());
237+
IRB.getContext().diagnose(UnsupportedFormatStr);
238+
}
239+
}
240+
241+
auto Printf = llvm::emitAMDGPUPrintfCall(IRB, Args, FmtStr, isBuffered);
224242
Builder.SetInsertPoint(IRB.GetInsertBlock(), IRB.GetInsertPoint());
225243
return RValue::get(Printf);
226244
}

0 commit comments

Comments
 (0)