Skip to content

Commit 28f95bb

Browse files
[clang-offload-bundler] Fix global constants cleanup in clang-offload-bundler (intel#4356)
1 parent 2e08d0e commit 28f95bb

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/test/Driver/clang-offload-bundler-tgtsym.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525

2626
const __attribute__((opencl_constant)) char const_as[] = "abc";
2727

28+
extern void my_printf(__attribute__((opencl_constant)) const char *fmt);
29+
2830
extern void undefined_func(void);
2931

3032
void foo(void) {
33+
// We aim to create a gep operator in LLVM IR to have a use of const_as
34+
my_printf(&const_as[1]);
3135
undefined_func();
3236
}
3337

clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ class ObjectFileHandler final : public FileHandler {
653653
// Do not add globals with constant address space to the tgtsym.
654654
if (!GV.isDeclaration() && !GV.hasLocalLinkage() &&
655655
GV.getAddressSpace() == 2) {
656+
GV.replaceAllUsesWith(UndefValue::get(GV.getType()));
656657
GV.dropAllReferences();
657658
GV.eraseFromParent();
658659
UpdateBuf = true;

0 commit comments

Comments
 (0)