@@ -35,6 +35,7 @@ const void *Program::getNativePointer(unsigned Idx) {
35
35
unsigned Program::createGlobalString (const StringLiteral *S, const Expr *Base) {
36
36
const size_t CharWidth = S->getCharByteWidth ();
37
37
const size_t BitWidth = CharWidth * Ctx.getCharBit ();
38
+ unsigned StringLength = S->getLength ();
38
39
39
40
PrimType CharType;
40
41
switch (CharWidth) {
@@ -55,15 +56,15 @@ unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
55
56
Base = S;
56
57
57
58
// Create a descriptor for the string.
58
- Descriptor *Desc = allocateDescriptor (Base, CharType, Descriptor::GlobalMD,
59
- S-> getLength () + 1 ,
60
- /* isConst=*/ true ,
61
- /* isTemporary=*/ false ,
62
- /* isMutable=*/ false );
59
+ Descriptor *Desc =
60
+ allocateDescriptor (Base, CharType, Descriptor::GlobalMD, StringLength + 1 ,
61
+ /* isConst=*/ true ,
62
+ /* isTemporary=*/ false ,
63
+ /* isMutable=*/ false );
63
64
64
65
// Allocate storage for the string.
65
66
// The byte length does not include the null terminator.
66
- unsigned I = Globals.size ();
67
+ unsigned GlobalIndex = Globals.size ();
67
68
unsigned Sz = Desc->getAllocSize ();
68
69
auto *G = new (Allocator, Sz) Global (Ctx.getEvalID (), Desc, /* isStatic=*/ true ,
69
70
/* isExtern=*/ false );
@@ -74,33 +75,32 @@ unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
74
75
75
76
// Construct the string in storage.
76
77
const Pointer Ptr (G->block ());
77
- for (unsigned I = 0 , N = S-> getLength () ; I <= N ; ++I) {
78
- Pointer Field = Ptr.atIndex (I). narrow () ;
79
- const uint32_t CodePoint = I == N ? 0 : S->getCodeUnit (I);
78
+ for (unsigned I = 0 ; I <= StringLength ; ++I) {
79
+ Pointer Field = Ptr.atIndex (I);
80
+ const uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit (I);
80
81
switch (CharType) {
81
82
case PT_Sint8: {
82
83
using T = PrimConv<PT_Sint8>::T;
83
84
Field.deref <T>() = T::from (CodePoint, BitWidth);
84
- Field.initialize ();
85
85
break ;
86
86
}
87
87
case PT_Uint16: {
88
88
using T = PrimConv<PT_Uint16>::T;
89
89
Field.deref <T>() = T::from (CodePoint, BitWidth);
90
- Field.initialize ();
91
90
break ;
92
91
}
93
92
case PT_Uint32: {
94
93
using T = PrimConv<PT_Uint32>::T;
95
94
Field.deref <T>() = T::from (CodePoint, BitWidth);
96
- Field.initialize ();
97
95
break ;
98
96
}
99
97
default :
100
98
llvm_unreachable (" unsupported character type" );
101
99
}
102
100
}
103
- return I;
101
+ Ptr.initialize ();
102
+
103
+ return GlobalIndex;
104
104
}
105
105
106
106
Pointer Program::getPtrGlobal (unsigned Idx) const {
0 commit comments