File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
lib/CIR/Lowering/DirectToLLVM Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -2281,8 +2281,12 @@ class CIRGlobalOpLowering
22812281 // Initializer is a constant array: convert it to a compatible llvm init.
22822282 if (auto constArr = mlir::dyn_cast<mlir::cir::ConstArrayAttr>(init.value ())) {
22832283 if (auto attr = mlir::dyn_cast<mlir::StringAttr>(constArr.getElts ())) {
2284- init = rewriter.getStringAttr (attr.getValue ());
2285- } else if (auto attr = mlir::dyn_cast<mlir::ArrayAttr>(constArr.getElts ())) {
2284+ llvm::SmallString<256 > literal (attr.getValue ());
2285+ if (constArr.getTrailingZerosNum ())
2286+ literal.append (constArr.getTrailingZerosNum (), ' \0 ' );
2287+ init = rewriter.getStringAttr (literal);
2288+ } else if (auto attr =
2289+ mlir::dyn_cast<mlir::ArrayAttr>(constArr.getElts ())) {
22862290 // Failed to use a compact attribute as an initializer:
22872291 // initialize elements individually.
22882292 if (!(init = lowerConstArrayAttr (constArr, getTypeConverter ()))) {
Original file line number Diff line number Diff line change 1+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
2+ // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
3+
4+ void f (char * fmt , ...);
5+ void test () {
6+ f ("test\0" );
7+ }
8+
9+ // LLVM: @.str = {{.*}}[6 x i8] c"test\00\00"
You can’t perform that action at this time.
0 commit comments