This is an archive of the discontinued LLVM Phabricator instance.

[clang][CGStmt] fix crash on invalid asm statement
ClosedPublic

Authored by ztong0001 on Feb 25 2022, 3:43 PM.

Details

Summary

Clang is crashing on the following statement

char var[9];
__asm__ ("" : "=r" (var) : "0" (var));

This is similar to existing test: crbug_999160_regtest

The issue happens when EmitAsmStmt is trying to convert input to match
output type length. However, that is not guaranteed to be successful all the
time and if the statement itself is invalid like having an array type in
the example, we should give a regular error message here instead of
using assert().

Diff Detail

Event Timeline

ztong0001 created this revision.Feb 25 2022, 3:43 PM
ztong0001 requested review of this revision.Feb 25 2022, 3:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2022, 3:43 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ztong0001 updated this revision to Diff 411542.Feb 25 2022, 3:53 PM

reformat test code

ztong0001 updated this revision to Diff 411577.Feb 25 2022, 9:44 PM

reformat code

Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 10:54 AM
MaskRay added inline comments.
clang/lib/CodeGen/CGStmt.cpp
2517

Shall we keep the assert (in a new else branch) just in case there are other cases which cannot be handled?

ztong0001 added inline comments.Mar 2 2022, 11:08 AM
clang/lib/CodeGen/CGStmt.cpp
2517

IMO adding assert() in else branch still has the same issue with the inline asm in description.

This portion of the code is to extend argument to a longer type, if it cannot do so the patch will simply skip and let it fall back to old behavior and print out

impossible constraint in asm: can't store value into a register

MaskRay accepted this revision.Mar 2 2022, 11:10 AM

Thanks!

This revision is now accepted and ready to land.Mar 2 2022, 11:10 AM

Hi Fangrui @MaskRay,
Thanks for your review. Could you please also help me landing it since I don't have write permission to the repo.
Please use Tong Zhang<ztong0001@gmail.com>
Thanks and have a good one!

  • Tong
This revision was landed with ongoing or failed builds.Mar 2 2022, 11:19 AM
This revision was automatically updated to reflect the committed changes.
This comment was removed by pengfei.