[PATCH] D81794: [clang] Don't emit warn_cxx_ms_struct when MSBitfields is enabled globally

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 13 14:25:48 PDT 2020


mstorsjo updated this revision to Diff 270587.
mstorsjo added a comment.

Fixed the formatting


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81794/new/

https://reviews.llvm.org/D81794

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/ms_struct.cpp


Index: clang/test/SemaCXX/ms_struct.cpp
===================================================================
--- clang/test/SemaCXX/ms_struct.cpp
+++ clang/test/SemaCXX/ms_struct.cpp
@@ -1,8 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple i686-apple-darwin9 -std=c++11 %s
-// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple armv7-apple-darwin9 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_WARNING -Wno-error=incompatible-ms-struct -verify -triple i686-apple-darwin9 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_WARNING -Wno-error=incompatible-ms-struct -verify -triple armv7-apple-darwin9 -std=c++11 %s
 // RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_ERROR -verify -triple armv7-apple-darwin9 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -DNO_PRAGMA -mms-bitfields -verify -triple armv7-apple-darwin9 -std=c++11 %s
 
+#ifndef NO_PRAGMA
 #pragma ms_struct on
+#endif
 
 struct A {
   unsigned long a:4;
@@ -12,7 +15,7 @@
 struct B : public A {
 #ifdef TEST_FOR_ERROR
   // expected-error at -2 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
-#else
+#elif defined(TEST_FOR_WARNING)
   // expected-warning at -4 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
 #endif
   unsigned long c:16;
@@ -27,7 +30,7 @@
 struct C {
 #ifdef TEST_FOR_ERROR
   // expected-error at -2 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
-#else
+#elif defined(TEST_FOR_WARNING)
   // expected-warning at -4 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
 #endif
   virtual void foo();
@@ -36,3 +39,6 @@
 
 static_assert(__builtin_offsetof(C, n) == 8,
               "long long field in ms_struct should be 8-byte aligned");
+#if !defined(TEST_FOR_ERROR) && !defined(TEST_FOR_WARNING)
+// expected-no-diagnostics
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -6753,7 +6753,11 @@
   // headers, sweeping up a bunch of types that the project doesn't
   // really rely on MSVC-compatible layout for.  We must therefore
   // support "ms_struct except for C++ stuff" as a secondary ABI.
-  if (Record->isMsStruct(Context) &&
+  // Don't emit this diagnostic if the feature was enabled as a
+  // language option (as opposed to via a pragma or attribute), as
+  // the option -mms-bitfields otherwise essentially makes it impossible
+  // to build C++ code, unless this diagnostic is turned off.
+  if (Record->isMsStruct(Context) && !Context.getLangOpts().MSBitfields &&
       (Record->isPolymorphic() || Record->getNumBases())) {
     Diag(Record->getLocation(), diag::warn_cxx_ms_struct);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81794.270587.patch
Type: text/x-patch
Size: 2953 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200613/e3bdd7bd/attachment-0001.bin>


More information about the cfe-commits mailing list