[PATCH] [clang] add support for -W{no-,}inline-asm-syntax

Chandler Carruth chandlerc at google.com
Thu Feb 20 03:25:35 PST 2014


On Thu, Feb 20, 2014 at 3:14 AM, David Woodhouse <dwmw2 at infradead.org>wrote:

> On Thu, 2014-02-20 at 02:02 -0800, Chandler Carruth wrote:
> >
> > This really doesn't make sense. So, we've not disabled the inline
> > assembler, so we will eventually produce an error, but we don't ask it to
> > validate the assembly about to be fed to itself (and errored on) while we
> > have the full context of the source code to go with it? How is this
> > reasonable behavior?
> >
> > Very fundamentally, LLVM's integrated assembler *is* going to assemble
> the
> > program.
>
> No. It isn't.
>
> Absolutely *nothing* is going to assemble this program.
>
> We invoke the compiler with the '-S' option. It's going to *compile* the
> program, and spit out a .s file for us.
>
> Hence my comparison with a pre-processor. It makes as much sense for the
> compiler in this case to be prodding and poking at the contents of
> asm("") statements, as it does for a C preprocessor to barf because
> "that's not valid C" when we use it for X keymap files.


Do you expect it to validate the C code it compiles? Should it produce any
warnings at all? Any errors? What is the limit?

Compiling the program, for Clang (and by extension LLVM when dealing with C
programs), involves validating that the program fits Clang's semantic model
for a C program. Inline assembly is an extension, but the idea is that it
too should have a semantic model. I'm not very fussed about how *strict*
that model is, and am quite happy for it to allow all manner of oddities
that are useful to you or others, but I think it is important that it *has*
a semantic model and that it is checked.

As an example, I don't want adding -S to change the set of syntax errors
produced by my program. If it *does*, I don't see how -fsyntax-only doesn't
*also* change the set of syntax errors. It too is not going to generate an
object file, and thus needn't assemble anything. With either of these, my
mental model for how the compiler works, and what I can or cannot do to
test my code and my compiler is broken.


That said, I can imagine other design principles, and I'm not really trying
to rule them out. However, the design of Clang w.r.t. inline assembly is
very much that it *must* conform to the semantic model of the integrated
assembler much as the C code must conform to the (extended) semantic model
of C.

And I don't think that this precludes the interesting use cases here.
Talking to Renato, it sounds much more like the validation is being
entirely too pedantic and restrictive, not that we need to cease all
validation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140220/43145c34/attachment.html>


More information about the cfe-commits mailing list