[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-12 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan created this revision.
ubsan added a reviewer: rsmith.
Herald added a subscriber: cfe-commits.

- Add `UETT_PreferredAlignOf` to account for the difference between `__alignof` 
and `alignof`
- `AlignOfType` now returns ABI alignment instead of preferred alignment iff 
clang-abi-compat > 7, and one uses _Alignof or alignof

bug link: https://bugs.llvm.org/show_bug.cgi?id=26547


Repository:
  rC Clang

https://reviews.llvm.org/D53207

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TypeTraits.h
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp

Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -3596,7 +3596,8 @@
 
   // C99 6.5.3.4p1:
   if (T->isFunctionType() &&
-  (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf)) {
+  (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
+   TraitKind == UETT_PreferredAlignOf)) {
 // sizeof(function)/alignof(function) is allowed as an extension.
 S.Diag(Loc, diag::ext_sizeof_alignof_function_type)
   << TraitKind << ArgRange;
@@ -3674,7 +3675,7 @@
   // the expression to be complete. 'sizeof' requires the expression's type to
   // be complete (and will attempt to complete it if it's an array of unknown
   // bound).
-  if (ExprKind == UETT_AlignOf) {
+  if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
 if (RequireCompleteType(E->getExprLoc(),
 Context.getBaseElementType(E->getType()),
 diag::err_sizeof_alignof_incomplete_type, ExprKind,
@@ -3698,7 +3699,8 @@
 
   // The operand for sizeof and alignof is in an unevaluated expression context,
   // so side effects could result in unintended consequences.
-  if ((ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf) &&
+  if ((ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf ||
+   ExprKind == UETT_PreferredAlignOf) &&
   !inTemplateInstantiation() && E->HasSideEffects(Context, false))
 Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context);
 
@@ -3767,7 +3769,8 @@
   // C11 6.5.3.4/3, C++11 [expr.alignof]p3:
   //   When alignof or _Alignof is applied to an array type, the result
   //   is the alignment of the element type.
-  if (ExprKind == UETT_AlignOf || ExprKind == UETT_OpenMPRequiredSimdAlign)
+  if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
+  ExprKind == UETT_OpenMPRequiredSimdAlign)
 ExprType = Context.getBaseElementType(ExprType);
 
   if (ExprKind == UETT_VecStep)
@@ -4046,14 +4049,14 @@
   bool isInvalid = false;
   if (E->isTypeDependent()) {
 // Delay type-checking for type-dependent expressions.
-  } else if (ExprKind == UETT_AlignOf) {
+  } else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
 isInvalid = CheckAlignOfExpr(*this, E);
   } else if (ExprKind == UETT_VecStep) {
 isInvalid = CheckVecStepExpr(E);
   } else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
-  Diag(E->getExprLoc(), diag::err_openmp_default_simd_align_expr);
-  isInvalid = true;
-  } else if (E->refersToBitField()) {  // C99 6.5.3.4p1.
+Diag(E->getExprLoc(), diag::err_openmp_default_simd_align_expr);
+isInvalid = true;
+  } else if (E->refersToBitField()) { // C99 6.5.3.4p1.
 Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0;
 isInvalid = true;
   } else {
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -5695,7 +5695,8 @@
   if (!Arg->isTypeDependent() && !Arg->isValueDependent()) {
 if (const auto *UE =
 dyn_cast(Arg->IgnoreParenImpCasts()))
-  if (UE->getKind() == UETT_AlignOf)
+  if (UE->getKind() == UETT_AlignOf ||
+  UE->getKind() == UETT_PreferredAlignOf)
 Diag(TheCall->getBeginLoc(), diag::warn_alloca_align_alignof)
 << Arg->getSourceRange();
 
@@ -10313,7 +10314,7 @@
   }
 
   AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
-  
+
   // Diagnose implicitly sequentially-consistent atomic assignment.
   if (E->getLHS()->getType()->isAtomicType())
 S.Diag(E->getRHS()->getBeginLoc(), diag::warn_atomic_implicit_seq_cst);
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -2022,7 +2022,9 @@
   CastRange);
 
   UnaryExprOrTypeTrait ExprKind = UETT_SizeOf;
-  if (OpTok.isOneOf(tok::kw_alignof, tok::kw___alignof, tok::kw__Alignof))
+  if (OpTok.is(tok::kw___alignof))
+ExprKind = UETT_PreferredAlignOf;
+  else if (OpTok.isOneOf(to

[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-12 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan updated this revision to Diff 169503.
ubsan added a comment.

add tests

fix nits


Repository:
  rC Clang

https://reviews.llvm.org/D53207

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TypeTraits.h
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  test/Sema/align-x86.c
  test/SemaCXX/align-x86.cpp

Index: test/SemaCXX/align-x86.cpp
===
--- /dev/null
+++ test/SemaCXX/align-x86.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+#include 
+#include 
+
+template 
+struct check_alignment {
+  using type = T;
+  static type value;
+
+  static_assert(__alignof__(value) == Preferred, "__alignof__(value) != Preferred");
+  static_assert(__alignof__(type) == Preferred, "__alignof__(type) != Preferred");
+  static_assert(alignof(type) == ABI, "alignof(type) != ABI");
+};
+
+// PR3433
+template struct check_alignment;
+template struct check_alignment;
+template struct check_alignment;
+template struct check_alignment, 4, 4>;
+
+// PR6362
+struct __attribute__((packed))
+packed_struct {
+  unsigned int a;
+} g_packedstruct;
+template struct check_alignment;
+static_assert(__alignof__(g_packedstruct.a) == 1, "__alignof__(packed_struct.member) != 1");
+
+typedef double arr3double[3];
+template struct check_alignment;
+
+enum big_enum { x = 18446744073709551615ULL };
+template struct check_alignment;
+
+// PR5637
+
+#define ALIGNED(x) __attribute__((aligned(x)))
+
+typedef ALIGNED(2) struct {
+  char a[3];
+} aligned_before_struct;
+
+static_assert(sizeof(aligned_before_struct)   == 3, "");
+static_assert(sizeof(aligned_before_struct[1])== 4, "");
+static_assert(sizeof(aligned_before_struct[2])== 6, "");
+static_assert(sizeof(aligned_before_struct[2][1]) == 8, "");
+static_assert(sizeof(aligned_before_struct[1][2]) == 6, "");
+
+typedef struct ALIGNED(2) {
+  char a[3];
+} aligned_after_struct;
+
+static_assert(sizeof(aligned_after_struct)   == 4, "");
+static_assert(sizeof(aligned_after_struct[1])== 4, "");
+static_assert(sizeof(aligned_after_struct[2])== 8, "");
+static_assert(sizeof(aligned_after_struct[2][1]) == 8, "");
+static_assert(sizeof(aligned_after_struct[1][2]) == 8, "");
Index: test/Sema/align-x86.c
===
--- test/Sema/align-x86.c
+++ test/Sema/align-x86.c
@@ -1,34 +1,33 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
 // expected-no-diagnostics
 
-// PR3433
-double g1;
-short chk1[__alignof__(g1) == 8 ? 1 : -1]; 
-short chk2[__alignof__(double) == 8 ? 1 : -1];
-
-long long g2;
-short chk1[__alignof__(g2) == 8 ? 1 : -1]; 
-short chk2[__alignof__(long long) == 8 ? 1 : -1];
+#define STATIC_ASSERT(cond) _Static_assert(cond, #cond)
 
-unsigned long long g5;
-short chk1[__alignof__(g5) == 8 ? 1 : -1]; 
-short chk2[__alignof__(unsigned long long) == 8 ? 1 : -1];
+// PR3433
+#define CHECK_ALIGNMENT(type, name, abi, pref) \
+  type name; \
+  STATIC_ASSERT(__alignof__(name) == pref); \
+  STATIC_ASSERT(__alignof__(type) == pref); \
+  STATIC_ASSERT(_Alignof(type) == abi)
 
-_Complex double g3;
-short chk1[__alignof__(g3) == 8 ? 1 : -1]; 
-short chk2[__alignof__(_Complex double) == 8 ? 1 : -1];
+CHECK_ALIGNMENT(double, g_double, 4, 8);
+CHECK_ALIGNMENT(long long, g_longlong, 4, 8);
+CHECK_ALIGNMENT(unsigned long long, g_ulonglong, 4, 8);
+CHECK_ALIGNMENT(_Complex double, g_complexdouble, 4, 8);
 
 // PR6362
-struct __attribute__((packed)) {unsigned int a;} g4;
-short chk1[__alignof__(g4) == 1 ? 1 : -1];
-short chk2[__alignof__(g4.a) == 1 ? 1 : -1];
+struct __attribute__((packed))
+packed_struct {
+  unsigned int a;
+};
+CHECK_ALIGNMENT(struct packed_struct, g_packedstruct, 1, 1);
+STATIC_ASSERT(__alignof__(g_packedstruct.a) == 1);
 
-double g6[3];
-short chk1[__alignof__(g6) == 8 ? 1 : -1];
-short chk2[__alignof__(double[3]) == 8 ? 1 : -1];
+typedef double arr3double[3];
+CHECK_ALIGNMENT(arr3double, g_arr3double, 4, 8);
 
-enum { x = 18446744073709551615ULL } g7;
-short chk1[__alignof__(g7) == 8 ? 1 : -1];
+enum big_enum { x = 18446744073709551615ULL };
+CHECK_ALIGNMENT(big_enum, g_bigenum, 4, 8);
 
 // PR5637
 
@@ -36,20 +35,20 @@
 
 typedef ALIGNED(2) struct {
   char a[3];
-} T;
+} aligned_before_struct;
 
-short chk1[sizeof(T)   == 3 ? 1 : -1];
-short chk2[sizeof(T[1])== 4 ? 1 : -1];
-short chk3[sizeof(T[2])== 6 ? 1 : -1];
-short chk4[sizeof(T[2][1]) == 8 ? 1 : -1];
-short chk5[sizeof(T[1][2]) == 6 ? 1 : -1];
+STATIC_ASSERT(sizeof(aligned_before_struct)   == 3);
+STATIC_ASSERT(sizeof(aligned_before_struct[1

[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-18 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan added a comment.

I'm having real difficulty with this - I get really odd errors in seemingly 
unrelated tests when I change things.


Repository:
  rC Clang

https://reviews.llvm.org/D53207



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-23 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan added a comment.

> Is it possible you have LLVM and Clang checked out at different revisions? 
> That's a common source of weird behavior, particularly in CodeGen tests.

Unfortunately no - when I don't specifically don't set the type trait kind of 
`__alignof` to `UETT_PreferredAlignOf`, and remove the code in `AlignOfType` to 
differentiate between `PreferredAlignOf` and `AlignOf`, all the tests pass 
again.


Repository:
  rC Clang

https://reviews.llvm.org/D53207



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-23 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan added a comment.

... Yup, that'd do it. Thanks Richard!


Repository:
  rC Clang

https://reviews.llvm.org/D53207



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-23 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan updated this revision to Diff 170814.
ubsan added a comment.

Finish doing the thing! all tests are passing, at least on the revision I'm 
running on :)

@rsmith please check the thing!


Repository:
  rC Clang

https://reviews.llvm.org/D53207

Files:
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TypeTraits.h
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  test/Headers/thumbv7-apple-ios-types.cpp
  test/Sema/align-x86-abi7.c
  test/Sema/align-x86.c
  test/SemaCXX/align-x86-abi7.cpp
  test/SemaCXX/align-x86.cpp
  test/SemaCXX/alignof.cpp

Index: test/SemaCXX/alignof.cpp
===
--- test/SemaCXX/alignof.cpp
+++ test/SemaCXX/alignof.cpp
@@ -4,14 +4,14 @@
 
 struct S0 {
   int x;
-  static const int test0 = __alignof__(x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
-  static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
-  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
+  static const int test0 = __alignof__(x); // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
+  static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
+  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
 };
 
 struct S1; // expected-note 6 {{forward declaration}}
 extern S1 s1;
-const int test3 = __alignof__(s1); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+const int test3 = __alignof__(s1); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 
 struct S2 {
   S2();
@@ -19,11 +19,11 @@
   int x;
 
   int test4 = __alignof__(x); // ok
-  int test5 = __alignof__(s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  int test5 = __alignof__(s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 };
 
 const int test6 = __alignof__(S2::x);
-const int test7 = __alignof__(S2::s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+const int test7 = __alignof__(S2::s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 
 // Arguably, these should fail like the S1 cases do: the alignment of
 // 's2.x' should depend on the alignment of both x-within-S2 and
@@ -34,10 +34,10 @@
   S2 s2;
 
   static const int test8 = __alignof__(s2.x);
-  static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
   auto test10() -> char(&)[__alignof__(s2.x)];
   static const int test11 = __alignof__(S3::s2.x);
-  static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
   auto test13() -> char(&)[__alignof__(s2.x)];
 };
 
@@ -59,9 +59,9 @@
 };
 const int test8 = __alignof__(S5::x);
 
-long long int test14[2];
+int test14[2];
 
-static_assert(alignof(test14) == 8, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
+static_assert(alignof(test14) == 4, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
 
 // PR19992
 static_assert(alignof(int[]) == alignof(int), ""); // ok
Index: test/SemaCXX/align-x86.cpp
===
--- /dev/null
+++ test/SemaCXX/align-x86.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+using size_t = decltype(sizeof(0));
+
+struct complex_double {
+  double real;
+  double imag;
+};
+
+template 
+struct check_alignment {
+  using type = T;
+  static type value;
+
+  static_assert(__alignof__(value) == Preferred, "__alignof__(value) != Preferred");
+  static_assert(__alignof__(type) == Preferred, "__alignof__(type) != Preferred");
+  static_assert(alignof(type) == ABI, "alignof(type) != ABI");
+};
+
+// PR3433
+template struct check_alignment;
+template struct check_alignment;
+template struct check_alignment;
+temp

[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-24 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan updated this revision to Diff 170994.
ubsan added a comment.

Add ABI breakage information and reflow


Repository:
  rC Clang

https://reviews.llvm.org/D53207

Files:
  docs/ReleaseNotes.rst
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TypeTraits.h
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  test/Headers/thumbv7-apple-ios-types.cpp
  test/Sema/align-x86-abi7.c
  test/Sema/align-x86.c
  test/SemaCXX/align-x86-abi7.cpp
  test/SemaCXX/align-x86.cpp
  test/SemaCXX/alignof.cpp

Index: test/SemaCXX/alignof.cpp
===
--- test/SemaCXX/alignof.cpp
+++ test/SemaCXX/alignof.cpp
@@ -4,14 +4,14 @@
 
 struct S0 {
   int x;
-  static const int test0 = __alignof__(x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
-  static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
-  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
+  static const int test0 = __alignof__(x); // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
+  static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
+  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
 };
 
 struct S1; // expected-note 6 {{forward declaration}}
 extern S1 s1;
-const int test3 = __alignof__(s1); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+const int test3 = __alignof__(s1); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 
 struct S2 {
   S2();
@@ -19,11 +19,11 @@
   int x;
 
   int test4 = __alignof__(x); // ok
-  int test5 = __alignof__(s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  int test5 = __alignof__(s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 };
 
 const int test6 = __alignof__(S2::x);
-const int test7 = __alignof__(S2::s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+const int test7 = __alignof__(S2::s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 
 // Arguably, these should fail like the S1 cases do: the alignment of
 // 's2.x' should depend on the alignment of both x-within-S2 and
@@ -34,10 +34,10 @@
   S2 s2;
 
   static const int test8 = __alignof__(s2.x);
-  static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
   auto test10() -> char(&)[__alignof__(s2.x)];
   static const int test11 = __alignof__(S3::s2.x);
-  static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
   auto test13() -> char(&)[__alignof__(s2.x)];
 };
 
@@ -59,9 +59,9 @@
 };
 const int test8 = __alignof__(S5::x);
 
-long long int test14[2];
+int test14[2];
 
-static_assert(alignof(test14) == 8, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
+static_assert(alignof(test14) == 4, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
 
 // PR19992
 static_assert(alignof(int[]) == alignof(int), ""); // ok
Index: test/SemaCXX/align-x86.cpp
===
--- /dev/null
+++ test/SemaCXX/align-x86.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+using size_t = decltype(sizeof(0));
+
+struct complex_double {
+  double real;
+  double imag;
+};
+
+template 
+struct check_alignment {
+  using type = T;
+  static type value;
+
+  static_assert(__alignof__(value) == Preferred, "__alignof__(value) != Preferred");
+  static_assert(__alignof__(type) == Preferred, "__alignof__(type) != Preferred");
+  static_assert(alignof(type) == ABI, "alignof(type) != ABI");
+};
+
+// PR3433
+template struct check_alignment;
+template struct check_alignment;
+template struct check_alignment;
+template struct check_alignment;
+
+// PR6362
+struct __attribut

[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-25 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan added a comment.

I don't actually know how to send this upstream, since it's been accepted... 
How should I proceed?


Repository:
  rC Clang

https://reviews.llvm.org/D53207



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-10-25 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan updated this revision to Diff 171247.
ubsan added a comment.

fix nits


Repository:
  rC Clang

https://reviews.llvm.org/D53207

Files:
  docs/ReleaseNotes.rst
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TypeTraits.h
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  test/Headers/thumbv7-apple-ios-types.cpp
  test/Sema/align-x86-abi7.c
  test/Sema/align-x86.c
  test/SemaCXX/align-x86-abi7.cpp
  test/SemaCXX/align-x86.cpp
  test/SemaCXX/alignof.cpp

Index: test/SemaCXX/alignof.cpp
===
--- test/SemaCXX/alignof.cpp
+++ test/SemaCXX/alignof.cpp
@@ -4,14 +4,14 @@
 
 struct S0 {
   int x;
-  static const int test0 = __alignof__(x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
-  static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
-  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of 'alignof' to a field of a class still being defined}}
+  static const int test0 = __alignof__(x); // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
+  static const int test1 = __alignof__(S0::x); // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
+  auto test2() -> char(&)[__alignof__(x)]; // expected-error {{invalid application of '__alignof' to a field of a class still being defined}}
 };
 
 struct S1; // expected-note 6 {{forward declaration}}
 extern S1 s1;
-const int test3 = __alignof__(s1); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+const int test3 = __alignof__(s1); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 
 struct S2 {
   S2();
@@ -19,11 +19,11 @@
   int x;
 
   int test4 = __alignof__(x); // ok
-  int test5 = __alignof__(s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  int test5 = __alignof__(s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 };
 
 const int test6 = __alignof__(S2::x);
-const int test7 = __alignof__(S2::s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+const int test7 = __alignof__(S2::s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
 
 // Arguably, these should fail like the S1 cases do: the alignment of
 // 's2.x' should depend on the alignment of both x-within-S2 and
@@ -34,10 +34,10 @@
   S2 s2;
 
   static const int test8 = __alignof__(s2.x);
-  static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  static const int test9 = __alignof__(s2.s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
   auto test10() -> char(&)[__alignof__(s2.x)];
   static const int test11 = __alignof__(S3::s2.x);
-  static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of 'alignof' to an incomplete type 'S1'}}
+  static const int test12 = __alignof__(S3::s2.s); // expected-error {{invalid application of '__alignof' to an incomplete type 'S1'}}
   auto test13() -> char(&)[__alignof__(s2.x)];
 };
 
@@ -59,9 +59,9 @@
 };
 const int test8 = __alignof__(S5::x);
 
-long long int test14[2];
+int test14[2];
 
-static_assert(alignof(test14) == 8, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
+static_assert(alignof(test14) == 4, "foo"); // expected-warning {{'alignof' applied to an expression is a GNU extension}}
 
 // PR19992
 static_assert(alignof(int[]) == alignof(int), ""); // ok
Index: test/SemaCXX/align-x86.cpp
===
--- /dev/null
+++ test/SemaCXX/align-x86.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+using size_t = decltype(sizeof(0));
+
+struct complex_double {
+  double real;
+  double imag;
+};
+
+template 
+struct check_alignment {
+  using type = T;
+  static type value;
+
+  static_assert(__alignof__(value) == Preferred, "__alignof__(value) != Preferred");
+  static_assert(__alignof__(type) == Preferred, "__alignof__(type) != Preferred");
+  static_assert(alignof(type) == ABI, "alignof(type) != ABI");
+};
+
+// PR3433
+template struct check_alignment;
+template struct check_alignment;
+template struct check_alignment;
+template struct check_alignment;
+
+// PR6362
+struct __attribute__((packed))
+packed_struct {

[PATCH] D53207: Fix bug 26547 - alignof should return ABI alignment, not preferred alignment

2018-11-21 Thread Nicole Mazzuca via Phabricator via cfe-commits
ubsan added a comment.

The ABI breakage was already there, in the difference between GCC and Clang

- if one compiles against libc++ with gcc, it is not compatible with things

that are compiled with clang. I frankly think that being ABI compatible
with gcc (and correct according to the standard) is far more important than
being ABI compatible with previous versions of clang - if people need the
ABI compatibility, they can and should use `-fclang-abi-compat`


Repository:
  rL LLVM

https://reviews.llvm.org/D53207



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits