Skip to content

Commit 815c01f

Browse files
committed
[CIR] Handle global string literals as char array initializer
This change adds the line of code needed to handle a string literal as an initializer for a character array.
1 parent 473dea9 commit 815c01f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ class ConstExprEmitter
254254
}
255255

256256
mlir::Attribute VisitStringLiteral(StringLiteral *e, QualType t) {
257-
cgm.errorNYI(e->getBeginLoc(), "ConstExprEmitter::VisitStringLiteral");
258-
return {};
257+
// This is a string literal initializing an array in an initializer.
258+
return cgm.getConstantArrayFromStringLiteral(e);
259259
}
260260

261261
mlir::Attribute VisitObjCEncodeExpr(ObjCEncodeExpr *e, QualType t) {

clang/test/CIR/CodeGen/string-literals.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -emit-llvm %s -o %t.ll
66
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
77

8+
char g_str[] = "1234";
9+
10+
// CIR: cir.global external @g_str = #cir.const_array<"1234\00" : !cir.array<!s8i x 5>> : !cir.array<!s8i x 5>
11+
812
// CIR: cir.global "private" cir_private dsolocal @[[STR1_GLOBAL:.*]] = #cir.const_array<"1\00" : !cir.array<!s8i x 2>> : !cir.array<!s8i x 2>
913
// CIR: cir.global "private" cir_private dsolocal @[[STR2_GLOBAL:.*]] = #cir.zero : !cir.array<!s8i x 1>
1014
// CIR: cir.global "private" cir_private dsolocal @[[STR3_GLOBAL:.*]] = #cir.zero : !cir.array<!s8i x 2>

0 commit comments

Comments
 (0)