|
14 | 14 | #include "CodeGenFunction.h"
|
15 | 15 | #include "clang/Basic/Builtins.h"
|
16 | 16 | #include "clang/Basic/TargetBuiltins.h"
|
| 17 | +#include "llvm/Analysis/ValueTracking.h" |
17 | 18 | #include "llvm/IR/DataLayout.h"
|
| 19 | +#include "llvm/IR/DiagnosticInfo.h" |
18 | 20 | #include "llvm/IR/Instruction.h"
|
19 | 21 | #include "llvm/Support/MathExtras.h"
|
20 | 22 | #include "llvm/Transforms/Utils/AMDGPUEmitPrintf.h"
|
@@ -219,7 +221,23 @@ RValue CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
|
219 | 221 | auto PFK = CGM.getTarget().getTargetOpts().AMDGPUPrintfKindVal;
|
220 | 222 | bool isBuffered =
|
221 | 223 | (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); |
223 | 241 | Builder.SetInsertPoint(IRB.GetInsertBlock(), IRB.GetInsertPoint());
|
224 | 242 | return RValue::get(Printf);
|
225 | 243 | }
|
|
0 commit comments