-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CIR] [Lowering] care trailing zero for lowering constant array #976
Conversation
@@ -2229,7 +2229,10 @@ class CIRGlobalOpLowering | |||
if (auto constArr = | |||
mlir::dyn_cast<mlir::cir::ConstArrayAttr>(init.value())) { | |||
if (auto attr = mlir::dyn_cast<mlir::StringAttr>(constArr.getElts())) { | |||
init = rewriter.getStringAttr(attr.getValue()); | |||
llvm::SmallString<256> literal(attr.getValue()); | |||
if (constArr.getTrailingZerosNum()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. For regular strings we just emit the string directly (https://godbolt.org/z/a6xWGx3hf), but for trailing NUL bytes we use trailing zeros (https://godbolt.org/z/r54vvKPb7). Maybe we shouldn't be generating the trailing zeroes instead (assuming there's no technical limitation around that)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM will generate the trailing zero: https://godbolt.org/z/4G75e4P1o . I feel better if we can get align with LLVM in the traditional pipeline. (this is LowerToLLVM.cpp and it shouldn't affect how we generate cir)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps OG should be fixed too? Anyways, in the meantime I'm sold on keeping it consistent with OG
@@ -2229,7 +2229,10 @@ class CIRGlobalOpLowering | |||
if (auto constArr = | |||
mlir::dyn_cast<mlir::cir::ConstArrayAttr>(init.value())) { | |||
if (auto attr = mlir::dyn_cast<mlir::StringAttr>(constArr.getElts())) { | |||
init = rewriter.getStringAttr(attr.getValue()); | |||
llvm::SmallString<256> literal(attr.getValue()); | |||
if (constArr.getTrailingZerosNum()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps OG should be fixed too? Anyways, in the meantime I'm sold on keeping it consistent with OG
Close #975 See the attached test case for example
Close #975
See the attached test case for example