aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2025-03-20 11:07:54 -0700
committerGitHub <noreply@github.com>2025-03-20 11:07:54 -0700
commit882082ae405d086b61588169fe31102c58b7d74e (patch)
tree948d8733c159a5ca9db05f5071b0165b4fca91f8 /clang/lib/CodeGen
parentdd3addf954ac7e704fccc7d011217ba10461c883 (diff)
downloadllvm-882082ae405d086b61588169fe31102c58b7d74e.zip
llvm-882082ae405d086b61588169fe31102c58b7d74e.tar.gz
llvm-882082ae405d086b61588169fe31102c58b7d74e.tar.bz2
[HLSL] Buffer handle globals should not be constants (#130231)
If these are constants their initializers will be removed by InstCombine. Change them to not be constants and initialize them with poison.
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGHLSLRuntime.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index a273f1e..e3e3102 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -31,7 +31,6 @@
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Alignment.h"
-
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
@@ -245,12 +244,12 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
llvm::TargetExtType *TargetTy =
cast<llvm::TargetExtType>(convertHLSLSpecificType(
ResHandleTy, BufDecl->hasValidPackoffset() ? &Layout : nullptr));
- llvm::GlobalVariable *BufGV =
- new GlobalVariable(TargetTy, /*isConstant*/ true,
- GlobalValue::LinkageTypes::ExternalLinkage, nullptr,
- llvm::formatv("{0}{1}", BufDecl->getName(),
- BufDecl->isCBuffer() ? ".cb" : ".tb"),
- GlobalValue::NotThreadLocal);
+ llvm::GlobalVariable *BufGV = new GlobalVariable(
+ TargetTy, /*isConstant*/ false,
+ GlobalValue::LinkageTypes::ExternalLinkage, PoisonValue::get(TargetTy),
+ llvm::formatv("{0}{1}", BufDecl->getName(),
+ BufDecl->isCBuffer() ? ".cb" : ".tb"),
+ GlobalValue::NotThreadLocal);
CGM.getModule().insertGlobalVariable(BufGV);
// Add globals for constant buffer elements and create metadata nodes