GCC supports power-of-2 size structures for the arguments. Clang supports fewer than GCC. But Clang always crashes for the unsupported cases.
This patch adds sema checks to do the diagnosts to solve these crashes.
Differential D107141
[Inline-asm] Add diagnosts for unsupported inline assembly arguments pengfei on Jul 30 2021, 2:36 AM. Authored by
Details GCC supports power-of-2 size structures for the arguments. Clang supports fewer than GCC. But Clang always crashes for the unsupported cases. This patch adds sema checks to do the diagnosts to solve these crashes.
Diff Detail
Event TimelineComment Actions
code doesn't make much sense to me. Besides, if we change "=rm" to "=r" Here is gcc document: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#OutputOperands To me it is defined behavior. Or I may missing some thing here. constraint: Output constraints must begin with either ‘=’ (a variable overwriting an existing value) or ‘+’ (when reading and writing). When using ‘=’, do not assume the location contains the existing value on entry to the asm, except when the operand is tied to an input; see Input Operands. After the prefix, there must be one or more additional constraints (see Constraints) that describe where the value resides. Common constraints include ‘r’ for register and ‘m’ for memory. When you list more than one possible location (for example, "=rm"), the compiler chooses the most efficient one based on the current context. If you list as many alternates as the asm statement allows, you permit the optimizers to produce the best possible code. If you must use a specific register, but your Machine Constraints do not provide sufficient control to select the specific register you want, local register variables may provide a solution (see Local Register Variables). Comment Actions @jyu2, Thanks for the detailed information.
Sorry, I didn't describe it clearly. I meant it's ub when they are used together with structure type. E.g., https://godbolt.org/z/ssY5K4xEP
This patch doesn't change any functionality of Clang. We just adding more sema checks to avoid the ugly crash. This is required from our user. Comment Actions First I did not say "code doesn't make much sense to me". This is copy form your description. Okay, thank for explanation. So if I understand right, both gcc and icc generated code is not making sense to you. So instead, you want clang give error for this when output size greater than input size.
Comment Actions
Oop, my bad understanding. :)
Yes. Unless there's document to specify the behavior clearly.
Giving error only when output size greater than input size and output type is not one of the 3 cases in CGStmt.cpp:2480. I.e.: OutputDomain != AD_Other || OutSize <= InSize. Otherwise, Clang will crash there.
Sema emits error when 1) InputDomain != AD_Other 2) Output is mentioned and OutSize < InSize. So input size is allow to be greater than output size only when output is not mentioned. I don't fully understand the code in CGStmt.cpp, but according to comment in line 2463, it seems only larger output result needs to be handled.
Comment Actions Address review comment.
Comment Actions Address review comment.
|
Are you sure you want to change the Input/output Domain? Since you changed this, could you add both codegen and sema check tests for struct type(you already has sema check for struct type, but I don't see any array type) and array type.
Thanks.
Jennifer