[cfe-dev] Readonly variable using in output list of inline asm

Eli Friedman eli.friedman at gmail.com
Fri Jun 15 14:46:14 PDT 2012


On Fri, Jun 15, 2012 at 2:10 AM, arsen <hakobyan.ars at gmail.com> wrote:
> Hi all,
>
> I need to know why clang allows constant variable using in output list.
> e.g.:
>
> const int b = 0;
> asm(
>            "mov $10, %0\n"
>            : "=r"(b)
>            :
>       );
>
> I found that clang checks whether variable is LValue. It does in
> CheckAsmLValue() function (clang/lib/Sema/SemaStmt.cpp). but I there is not
> checking for const variables.
> So where it will be more effectively to change the implementation to deny
> the using of read-only variables in operand list?

CheckAsmLValue is probably the right place to add a check for that.
You can use Expr::isModifiableLvalue to check whether an expression
refers something like a const variable.

-Eli




More information about the cfe-dev mailing list