[PATCH] D68055: Add -fgnuc-version= to control __GNUC__ and other GCC macros

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 25 15:01:17 PDT 2019


rnk created this revision.
rnk added reviewers: rjmccall, rsmith, hans.
Herald added subscribers: s.egerton, simoncook, fedor.sergeev, aheejin.
Herald added a project: clang.

I noticed that compiling on Windows with -fno-ms-compatibility had the
side effect of defining __GNUC__, along with __EXCEPTIONS, __GXX_RTTI__,
and a number of other macros for GCC compatibility. This is undesirable
and causes Chromium to do things like mix __attribute__ and __declspec,
which doesn't work. We should have a positive language option to enable
GCC compatibility features so that we can experiment with
-fno-ms-compatibility on Windows. I propose that -fgnuc-version= can be
that option.

My issue aside, users have, for a long time, reported that __GNUC__
doesn't match their expectations in one way or another. We have
encouraged users to migrate code away from this macro, but new code
continues to be written assuming a GCC-only environment. There's really
nothing we can do to stop that. By adding this flag, we can allow them
to choose their own adventure with __GNUC__.

This overlaps a bit with the "GNUMode" language option from -std=gnu*.
I'm not sure how to reconcile them. The gnu language mode tends to
enable non-conforming behaviors that we'd rather not enable by default,
but these feature macros, like __EXCEPTIONS, are pretty benign.

Helps address PR42817


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68055

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/CodeGenCXX/nrvo.cpp
  clang/test/Driver/fgnuc-version.c
  clang/test/Driver/rewrite-legacy-objc.m
  clang/test/Driver/rewrite-objc.m
  clang/test/Frontend/gnu-inline.c
  clang/test/Headers/stdbool.cpp
  clang/test/Preprocessor/init.c
  clang/test/Preprocessor/predefined-exceptions.m
  clang/test/Sema/atomic-ops.c
  clang/test/SemaCXX/cxx2a-destroying-delete.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68055.221841.patch
Type: text/x-patch
Size: 42103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190925/62c86043/attachment-0001.bin>


More information about the cfe-commits mailing list