[PATCH] D130800: [clang][Headers] Avoid compiler warnings in builtin headers

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 11:32:06 PDT 2022

aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

These changes look reasonable to me, thanks!

Comment at: clang/lib/Headers/stdint.h:99-100
 typedef __UINT64_TYPE__ uint64_t;
+# undef __int_least64_t
 # define __int_least64_t int64_t
+# undef __uint_least64_t
ddcc wrote:
> iana wrote:
> > iana wrote:
> > > What are you seeing that's defining `__int_least64_t` and all these other ones by the time you get here? It's surprising to me that so much preprocessor state exists when you hit this point considering that this file doesn't include anything else. Is this some kind of artifact with how the OS module map is making a module for stdint.h?
> > Oh I see, it's not these ones that are the problem, it's the redefinitions below. I guess it's a bigger change, but I wonder if flipping the order would be cleaner? e.g.
> > ```
> > #ifdef __INT32_TYPE__
> > # define __int_least32_t int32_t
> > #endif
> > 
> > #ifdef __INT64_TYPE__
> > # ifndef __int_least32_t
> > #  define __int_least32_t int64_t
> > # endif
> > #endif
> > ```
> > 
> > I guess it's an extra line per type doing it that way, but maybe it's more obvious? (Maybe I just don't do a lot of preprocessor programming, but `#undef` feels like a code smell to me)
> I'm a little reluctant to change this file too much since it's tedious and error-prone, but yeah if we can agree on a solution, I can go ahead and make the change.
I'm not toooooo sad about the `#undef` though this does make preprocessing this file do more work. However, rearranging the macros in this file might be a challenge given how much these macros interact with one another. From the comments just above:
 * These macros are defined using the same successive-shrinking approach as
 * the type definitions above. It is likewise important that macros are defined
 * in order of decending width.

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list