Skip to content

Commit cb6a623

Browse files
authored
Add AddNull argument to CreateGlobalString. (llvm#93036)
There's currently no way to control whether a null terminator should be appended to the string created in `CreateGlobalString` / `CreateGlobalStringPtr`, since the methods don't expose an additional argument. This change adds an additional argument to the methods that has the same default value, `true`, as in `ConstantDataArray::getString`, and passes it down to this internal method.
1 parent 2bde13c commit cb6a623

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ class IRBuilderBase {
455455
/// block.
456456
GlobalVariable *CreateGlobalString(StringRef Str, const Twine &Name = "",
457457
unsigned AddressSpace = 0,
458-
Module *M = nullptr);
458+
Module *M = nullptr, bool AddNull = true);
459459

460460
/// Get a constant value representing either true or false.
461461
ConstantInt *getInt1(bool V) {
@@ -1992,8 +1992,9 @@ class IRBuilderBase {
19921992
/// block.
19931993
Constant *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "",
19941994
unsigned AddressSpace = 0,
1995-
Module *M = nullptr) {
1996-
GlobalVariable *GV = CreateGlobalString(Str, Name, AddressSpace, M);
1995+
Module *M = nullptr, bool AddNull = true) {
1996+
GlobalVariable *GV =
1997+
CreateGlobalString(Str, Name, AddressSpace, M, AddNull);
19971998
Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
19981999
Constant *Indices[] = {Zero, Zero};
19992000
return ConstantExpr::getInBoundsGetElementPtr(GV->getValueType(), GV,

llvm/lib/IR/IRBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ using namespace llvm;
4343
GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str,
4444
const Twine &Name,
4545
unsigned AddressSpace,
46-
Module *M) {
47-
Constant *StrConstant = ConstantDataArray::getString(Context, Str);
46+
Module *M, bool AddNull) {
47+
Constant *StrConstant = ConstantDataArray::getString(Context, Str, AddNull);
4848
if (!M)
4949
M = BB->getParent()->getParent();
5050
auto *GV = new GlobalVariable(

0 commit comments

Comments
 (0)