This is an archive of the discontinued LLVM Phabricator instance.

Clang codegen, fixes issue with emitting partially initialized constant arrays larger than 2^32
AbandonedPublic

Authored by OfekShochat on Sep 9 2022, 5:38 AM.

Details

Summary

fixes issue with emitting partially initialized constant arrays larger than 2^32.
issue #57353 on github.

Diff Detail

Event Timeline

OfekShochat created this revision.Sep 9 2022, 5:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 5:38 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
OfekShochat requested review of this revision.Sep 9 2022, 5:38 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 9 2022, 5:38 AM
OfekShochat retitled this revision from [Clang] changing behavior of constant array emission [AsmPrinter] changing Size from unsigned to uint64_t to [Clang] changing behavior of constant array emission[AsmPrinter] changing Size from unsigned to uint64_t.Sep 9 2022, 5:40 AM
OfekShochat added a reviewer: mehdi_amini.
OfekShochat retitled this revision from [Clang] changing behavior of constant array emission[AsmPrinter] changing Size from unsigned to uint64_t to #57353 on github.
OfekShochat added a comment.EditedSep 9 2022, 5:42 AM

its my first time contributing. this is probably very bad and goes against a lot of guidelines, but I wouldnt resist to fix this

trying to fix the problem. probably going to split this into two patches

aaron.ballman added a subscriber: aaron.ballman.

its my first time contributing. this is probably very bad and goes against a lot of guidelines, but I wouldnt resist to fix this

Welcome, and thank you for the patch! I'm going to add a few more reviewers who typically look at codegen changes, but I do have some high-level suggestions. Can you edit the title of the review (there's an "edit revision" link in the upper-right of the review) so that there's a short description of what is being fixed in the title? The title is what most reviewers see in our inbox/review list, so knowing what the patch is about helps reviewers immensely (also, we use the title of the review as the title of the commit message). Also, we ask that all changes to the code base come with test coverage showing what has been fixed, so please add some test coverage (most likely to clang/test/CodeGen/). Finally, we like to add information to our release notes about bug fixes so users know about the improvements, so please add a short release note (to clang/docs/ReleaseNotes.rst).

OfekShochat added a comment.EditedSep 9 2022, 6:51 AM

hello! thank you so much, Ill do that now, thanks! just a question, what are your guidelines when it comes to commit naming/number etc?

OfekShochat retitled this revision from #57353 on github to Clang codegen, fixes issue with emitting partially initialized constant arrays larger than 2^32.Sep 9 2022, 6:51 AM

hmm, one problem, seems like nor clang and nor gcc can compile the example in the github issue fully, only to assembly. is there something like c -> llir, llir -> asm checks? in the issue, it did succeed to compile to either llir and asm, just not correctly

hello! thank you so much, Ill do that now, thanks! just a question, what are your guidelines when it comes to commit naming/number etc?

Thanks, the new title is great! I'm not certain I understand your question, but our full developer policy can be found at: https://llvm.org/docs/DeveloperPolicy.html which may help.

hello again, I added two tests, one for llvm and one for clang. how do I run those specifically so I see I didnt do something wrong?

hello again, I added two tests, one for llvm and one for clang. how do I run those specifically so I see I didnt do something wrong?

The short answer is: you can run the check-all to run the LLVM and Clang tests together. For more details, our testing documentation can be found at: https://llvm.org/docs/TestingGuide.html though we also have some details at: https://clang.llvm.org/hacking.html#testing as well.

efriedma added inline comments.Sep 9 2022, 10:40 AM
clang/lib/CodeGen/CGExprConstant.cpp
1225

Note that getNumInits() itself is returning "unsigned". (Looks easy to fix, though.)

1265

Need to be careful here: in general, you can't just fill everything with zero. Need to check how getArrayFiller() is lowered. (For example, consider class X; int X::*a[10] = { 0 };.)

OfekShochat added a subscriber: eli.friedman.EditedSep 9 2022, 10:46 AM

yep @eli.friedman. probably gonna scratch this idea, makes more sense to actually tackle the problem itself, which is that getArrayFiller doesnt return anything. trying to actually get to the problem, but its quite hard, Visit's are thrown everywhere, and I cant really look at the problem. tryEmitPrivateForVarInit is called, and then it calls a Visit, which somehow transfers it to VisitInitListExpr. that thing worked just because it worked around that problem, even if not intentionally. though, I think Im closing in onto the problem

FYI, the "Visit" method comes from the base class StmtVisitor; it just forwards to the relevant method. (For example, if you call "Visit" with an InitListExpr, it calls VisitInitListExpr.)

Yeah. But it's really not clear how it does that, as it gets all the functions from the generated file

hello, solved the issue. it was, quite expectedly, a u64/unsigned problem in parsing, not codegen. no need to refactor this function. I will close this, thanks for the feedback and sorry for the hassle

OfekShochat abandoned this revision.Sep 10 2022, 9:03 AM