[pkg-d-commits] [ldc] 137/211: Consider string literals as constant in isConstLiteral.
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:17 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.1.0
in repository ldc.
commit 557a8bd7560fa030972c837cb265dd40cd453e2c
Author: LemonBoy <thatlemon at gmail.com>
Date: Tue Oct 18 22:44:48 2016 +0200
Consider string literals as constant in isConstLiteral.
---
gen/arrays.cpp | 4 ++++
tests/codegen/const_struct.d | 23 ++++++++++++++++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/gen/arrays.cpp b/gen/arrays.cpp
index d154144..da87788 100644
--- a/gen/arrays.cpp
+++ b/gen/arrays.cpp
@@ -522,6 +522,10 @@ bool isConstLiteral(Expression *e) {
}
} break;
+ // isConst also returns 0 for string literals that are obviously constant.
+ case TOKstring:
+ return true;
+
default:
if (e->isConst() != 1)
return false;
diff --git a/tests/codegen/const_struct.d b/tests/codegen/const_struct.d
index 7d310b4..b73e7d1 100644
--- a/tests/codegen/const_struct.d
+++ b/tests/codegen/const_struct.d
@@ -16,12 +16,25 @@ void testNested() {
assert(x == 3);
}
-// CHECK: @.immutablearray = internal constant [1 x %const_struct.S2] [%const_struct.S2 { [3 x %const_struct.S1] [%const_struct.S1 { %const_struct.S0 { i32 42 } }, %const_struct.S1 { %const_struct.S0 { i32 43 } }, %const_struct.S1 { %const_struct.S0 { i32 44 } }] }] ;
+// CHECK: @.immutablearray{{.*}} = internal constant [4 x i32]
+// CHECK: @.immutablearray{{.*}} = internal constant [2 x float]
+// CHECK: @.immutablearray{{.*}} = internal constant [2 x double]
+// CHECK: @.immutablearray{{.*}} = internal constant [2 x { i{{32|64}}, i8* }]
+// CHECK: @.immutablearray{{.*}} = internal constant [1 x %const_struct.S2]
+
void main () {
- // CHECK: store %const_struct.S2* getelementptr inbounds ({{.*}}[1 x %const_struct.S2]* @.immutablearray, i32 0, i32 0), %const_struct.S2** %2
- immutable S2[] xyz = [ { [ { { 42 } }, { { 43 } }, { { 44 } } ] } ];
- // CHECK: %.gc_mem = call {{{.*}}} @_d_newarrayU(%object.TypeInfo* bitcast (%"typeid(immutable(C0[]))"* @{{.*}} to %object.TypeInfo*), i{{32|64}} 3)
- immutable C0[] zyx = [ { new int(42) }, { null }, { null } ];
+ // Simple types
+ immutable int[] aA = [ 1, 2, 3, 4 ];
+ immutable float[] aB = [ 3.14, 3.33 ];
+ immutable double[] aC = [ 3.14, 3.33 ];
+ immutable string[] aD = [ "one", "two" ];
+
+ // Complex type
+ immutable S2[] aE = [ { [ { { 42 } }, { { 43 } }, { { 44 } } ] } ];
+ // Complex type with non-constant initializer
+ // CHECK: %.gc_mem = call { i{{32|64}}, i8* } @_d_newarrayU
+ // CHECK-SAME: @_D29TypeInfo_yAS12const_struct2C06__initZ
+ immutable C0[] aF = [ { new int(42) }, { new int(24) } ];
testNested();
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list