[cfe-dev] creating a warning with options in tablegen

Seth Cantrell seth.cantrell at gmail.com
Sat Apr 21 16:57:22 PDT 2012


On Apr 21, 2012, at 6:29 PM, Chandler Carruth wrote:

> On Sat, Apr 21, 2012 at 1:58 PM, Seth Cantrell <seth.cantrell at gmail.com> wrote:
> Can a warning with options be created entirely in a .td warning file? I want a warning that can be enabled in three different ways, e.g. -Wfoobar, -Wfoobar=yes, and -Wfoobar=no, however the only examples of warnings that take options that I know of are all done specially in the command line parsing. Will I be able to create such a warning in tablegen, and are there any examples I missed that do this?
> 
> I would really rather avoid this complexity in our warning options. Can you explain what you're actually trying to do?

Yes, but I don't think I'll persuade you that it's a good idea...

The specific warning I'm thinking about deals with the so called 'UTF-8 signature'. It has two modes, and additionally can be enabled without selecting a mode, which selects a default based on the platform.

 - Produce a warning for any file that has a signature: -Wutf8-signature=no or maybe 'never'
 - Produce a warning for any file that does not have a signature: -Wutf8-siganture=yes or maybe 'always'

 - Produce a warning for any file that does not conform the the platform's conventions, i.e. a warning on Windows for files missing a signature and a warning on other platforms for files where a signature has snuck in: -Wutf8-signature

A hopefully motivating reason to warn about utf-8 signatures:

Code developed for Windows may depend on cl.exe's behavior where the source code encoding is set to be the system locale encoding unless a 'UTF-8 signature' is found. Code intended to use the system locale encoding will compile on clang (which assumes UTF-8 source code encoding always), but may behave incorrectly, possibly in subtle ways.

The above case could be easily handled with a simple warning flag without options, but it's not actually the case I care about. (And come to think of it, that warning would encourage Windows users to put utf-8 signatures in their code which isn't what I want!) IMO a compiler parsing a source file that begins with a UTF-8 signature should see that the file begins with U+FEFF (ZERO WIDTH NO BREAK SPACE), consult the C++ grammar, determine that C++ does not allow this character in this location and produce a fatal error. Unfortunately I don't think anyone else finds this behavior desirable. However, combining -Werror with the warning -Wutf8-signature=no would be almost as good.


Another thing that occurs to me is that if I wanted to introduce a warning that handles my first 'motivating' example but without all the false positives, the warning would only occur when a file contains bytes outside the ascii range and the file doesn't have a utf-8 signature. And the warning would point directly at any non-ascii bytes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120421/138eb1b3/attachment.html>


More information about the cfe-dev mailing list