r313675 - [OpenMP] fix seg-faults printing diagnostics with invalid ordered(n) values

2017-09-19 Thread Rachel Craik via cfe-commits
Author: rcraik
Date: Tue Sep 19 14:04:23 2017
New Revision: 313675

URL: http://llvm.org/viewvc/llvm-project?rev=313675=rev
Log:
[OpenMP] fix seg-faults printing diagnostics with invalid ordered(n) values

When the value specified for n in ordered(n) is larger than the number of loops 
a segmentation fault can occur in one of two ways when attempting to print out 
a diagnostic for an associated depend(sink : vec):
1) The iteration vector vec contains less than n items
2) The iteration vector vec contains a variable that is not a loop control 
variable
This patch addresses both of these issues.

Differential Revision: https://reviews.llvm.org/D38049

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/ordered_messages.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313675=313674=313675=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 19 14:04:23 
2017
@@ -8875,7 +8875,7 @@ def note_omp_critical_no_hint : Note<
 def err_omp_depend_clause_thread_simd : Error<
   "'depend' clauses cannot be mixed with '%0' clause">;
 def err_omp_depend_sink_expected_loop_iteration : Error<
-  "expected %0 loop iteration variable">;
+  "expected%select{| %1}0 loop iteration variable">;
 def err_omp_depend_sink_unexpected_expr : Error<
   "unexpected expression: number of expressions is larger than the number of 
associated loops">;
 def err_omp_depend_sink_expected_plus_minus : Error<

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=313675=313674=313675=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Sep 19 14:04:23 2017
@@ -10510,9 +10510,14 @@ Sema::ActOnOpenMPDependClause(OpenMPDepe
 if (!CurContext->isDependentContext() &&
 DSAStack->getParentOrderedRegionParam() &&
 DepCounter != DSAStack->isParentLoopControlVariable(D).first) {
-  Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration)
-  << DSAStack->getParentLoopControlVariable(
- DepCounter.getZExtValue());
+  ValueDecl* VD = DSAStack->getParentLoopControlVariable(
+  DepCounter.getZExtValue());
+  if (VD) {
+Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration)
+<< 1 << VD;
+  } else {
+ Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) << 
0;
+  }
   continue;
 }
 OpsOffs.push_back({RHS, OOK});
@@ -10545,8 +10550,9 @@ Sema::ActOnOpenMPDependClause(OpenMPDepe
 
 if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink &&
 TotalDepCount > VarList.size() &&
-DSAStack->getParentOrderedRegionParam()) {
-  Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration)
+DSAStack->getParentOrderedRegionParam() &&
+DSAStack->getParentLoopControlVariable(VarList.size() + 1)) {
+  Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) << 1
   << DSAStack->getParentLoopControlVariable(VarList.size() + 1);
 }
 if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink &&

Modified: cfe/trunk/test/OpenMP/ordered_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/ordered_messages.cpp?rev=313675=313674=313675=diff
==
--- cfe/trunk/test/OpenMP/ordered_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/ordered_messages.cpp Tue Sep 19 14:04:23 2017
@@ -270,5 +270,13 @@ int k;
 }
   }
 
+#pragma omp for ordered(2) // expected-note {{as specified in 'ordered' 
clause}}
+  for (int i = 0; i < 10; ++i) { // expected-error {{expected 2 for loops 
after '#pragma omp for', but found only 1}}
+#pragma omp ordered depend(sink : i)
+int j;
+#pragma omp ordered depend(sink : i, j) // expected-error {{expected loop 
iteration variable}}
+foo();
+  }
+
   return foo(); // expected-note {{in instantiation of function template 
specialization 'foo' requested here}}
 }


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


[libcxx] r308932 - Remove addtional parameters in function std::next() and std::prev()

2017-07-24 Thread Rachel Craik via cfe-commits
Author: rcraik
Date: Mon Jul 24 15:17:05 2017
New Revision: 308932

URL: http://llvm.org/viewvc/llvm-project?rev=308932=rev
Log:
Remove addtional parameters in function std::next() and std::prev()

Creating a function pointer with proper parameters pointing to std::next() or 
std::prev() should work.
This change moves the invented paramater for enable_if over to the return type 
to resolve this QoI issue.

Patch by Jason Liu.

Differential Revision: https://reviews.llvm.org/D34649

Modified:
libcxx/trunk/include/iterator

libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp

libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp

Modified: libcxx/trunk/include/iterator
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=308932=308931=308932=diff
==
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Mon Jul 24 15:17:05 2017
@@ -604,21 +604,27 @@ distance(_InputIter __first, _InputIter
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_InputIter
+typename enable_if
+<
+__is_input_iterator<_InputIter>::value, 
+_InputIter
+>::type
 next(_InputIter __x,
- typename iterator_traits<_InputIter>::difference_type __n = 1,
- typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
+ typename iterator_traits<_InputIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, __n);
 return __x;
 }
 
-template 
+template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-_BidiretionalIter
-prev(_BidiretionalIter __x,
- typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
- typename 
enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
+typename enable_if
+<
+__is_bidirectional_iterator<_BidirectionalIter>::value, 
+_BidirectionalIter
+>::type
+prev(_BidirectionalIter __x,
+ typename iterator_traits<_BidirectionalIter>::difference_type __n = 1)
 {
 _VSTD::advance(__x, -__n);
 return __x;

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp?rev=308932=308931=308932=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/next.pass.cpp
 Mon Jul 24 15:17:05 2017
@@ -24,6 +24,9 @@ void
 test(It i, typename std::iterator_traits::difference_type n, It x)
 {
 assert(std::next(i, n) == x);
+
+It (*next)(It, typename std::iterator_traits::difference_type) = 
std::next;
+assert(next(i, n) == x);
 }
 
 template 

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp?rev=308932=308931=308932=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 Mon Jul 24 15:17:05 2017
@@ -22,6 +22,9 @@ void
 test(It i, typename std::iterator_traits::difference_type n, It x)
 {
 assert(std::prev(i, n) == x);
+
+It (*prev)(It, typename std::iterator_traits::difference_type) = 
std::prev;
+assert(prev(i, n) == x);
 }
 
 template 


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


r247560 - Test commit

2015-09-14 Thread Rachel Craik via cfe-commits
Author: rcraik
Date: Mon Sep 14 09:08:18 2015
New Revision: 247560

URL: http://llvm.org/viewvc/llvm-project?rev=247560=rev
Log:
Test commit

Remove some trailing whitespace

Modified:
cfe/trunk/lib/Basic/Builtins.cpp

Modified: cfe/trunk/lib/Basic/Builtins.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=247560=247559=247560=diff
==
--- cfe/trunk/lib/Basic/Builtins.cpp (original)
+++ cfe/trunk/lib/Basic/Builtins.cpp Mon Sep 14 09:08:18 2015
@@ -44,7 +44,7 @@ Builtin::Context::Context() {
 
 void Builtin::Context::initializeTarget(const TargetInfo ) {
   assert(NumTSRecords == 0 && "Already initialized target?");
-  Target.getTargetBuiltins(TSRecords, NumTSRecords);  
+  Target.getTargetBuiltins(TSRecords, NumTSRecords);
 }
 
 bool Builtin::Context::builtinIsSupported(const Builtin::Info ,
@@ -52,7 +52,7 @@ bool Builtin::Context::builtinIsSupporte
   bool BuiltinsUnsupported = LangOpts.NoBuiltin &&
  strchr(BuiltinInfo.Attributes, 'f');
   bool MathBuiltinsUnsupported =
-LangOpts.NoMathBuiltin && BuiltinInfo.HeaderName &&  
+LangOpts.NoMathBuiltin && BuiltinInfo.HeaderName &&
 llvm::StringRef(BuiltinInfo.HeaderName).equals("math.h");
   bool GnuModeUnsupported = !LangOpts.GNUMode && (BuiltinInfo.Langs & 
GNU_LANG);
   bool MSModeUnsupported =


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


r247618 - C11 _Bool bitfield diagnostic

2015-09-14 Thread Rachel Craik via cfe-commits
Author: rcraik
Date: Mon Sep 14 16:27:36 2015
New Revision: 247618

URL: http://llvm.org/viewvc/llvm-project?rev=247618=rev
Log:
C11 _Bool bitfield diagnostic

Summary: Implement DR262 (for C). This patch will mainly affect bitfields of 
type _Bool

Reviewers: fraggamuffin, rsmith

Subscribers: hubert.reinterpretcast, cfe-commits

Differential Revision: http://reviews.llvm.org/D10018

Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGen/bitfield-2.c
cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp
cfe/trunk/test/Misc/warning-flags.c
cfe/trunk/test/Sema/bitfield.c
cfe/trunk/test/SemaCXX/bitfield-layout.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp
cfe/trunk/test/SemaObjC/class-bitfield.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=247618=247617=247618=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Sep 14 16:27:36 2015
@@ -32,6 +32,7 @@ def AutoImport : DiagGroup<"auto-import"
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 def GNUCompoundLiteralInitializer : 
DiagGroup<"gnu-compound-literal-initializer">;
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion">;
+def BitFieldWidth : DiagGroup<"bitfield-width">;
 def ConstantConversion :
   DiagGroup<"constant-conversion", [ BitFieldConstantConversion ] >;
 def LiteralConversion : DiagGroup<"literal-conversion">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=247618=247617=247618=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 14 16:27:36 
2015
@@ -4314,20 +4314,21 @@ def err_bitfield_has_negative_width : Er
 def err_anon_bitfield_has_negative_width : Error<
   "anonymous bit-field has negative width (%0)">;
 def err_bitfield_has_zero_width : Error<"named bit-field %0 has zero width">;
-def err_bitfield_width_exceeds_type_size : Error<
-  "size of bit-field %0 (%1 bits) exceeds size of its type (%2 bits)">;
-def err_anon_bitfield_width_exceeds_type_size : Error<
-  "size of anonymous bit-field (%0 bits) exceeds size of its type (%1 bits)">;
+def err_bitfield_width_exceeds_type_width : Error<
+  "width of bit-field %0 (%1 bits) exceeds width of its type (%2 bit%s2)">;
+def err_anon_bitfield_width_exceeds_type_width : Error<
+  "width of anonymous bit-field (%0 bits) exceeds width of its type "
+  "(%1 bit%s1)">;
 def err_incorrect_number_of_vector_initializers : Error<
   "number of elements must be either one or match the size of the vector">;
 
 // Used by C++ which allows bit-fields that are wider than the type.
-def warn_bitfield_width_exceeds_type_size: Warning<
-  "size of bit-field %0 (%1 bits) exceeds the size of its type; value will be "
-  "truncated to %2 bits">;
-def warn_anon_bitfield_width_exceeds_type_size : Warning<
-  "size of anonymous bit-field (%0 bits) exceeds size of its type; value will "
-  "be truncated to %1 bits">;
+def warn_bitfield_width_exceeds_type_width: Warning<
+  "width of bit-field %0 (%1 bits) exceeds the width of its type; value will "
+  "be truncated to %2 bit%s2">, InGroup;
+def warn_anon_bitfield_width_exceeds_type_width : Warning<
+  "width of anonymous bit-field (%0 bits) exceeds width of its type; value "
+  "will be truncated to %1 bit%s1">, InGroup;
 
 def warn_missing_braces : Warning<
   "suggest braces around initialization of subobject">,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=247618=247617=247618=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep 14 16:27:36 2015
@@ -12625,26 +12625,26 @@ ExprResult Sema::VerifyBitField(SourceLo
   }
 
   if (!FieldTy->isDependentType()) {
-uint64_t TypeSize = Context.getTypeSize(FieldTy);
-if (Value.getZExtValue() > TypeSize) {
+uint64_t TypeWidth = Context.getIntWidth(FieldTy);
+if (Value.ugt(TypeWidth)) {
   if (!getLangOpts().CPlusPlus || IsMsStruct ||
   Context.getTargetInfo().getCXXABI().isMicrosoft()) {
 if (FieldName) 
-  return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_size)
+  return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
 << 

Re: [PATCH] D10018: C11 _Bool bitfield diagnostic

2015-09-11 Thread Rachel Craik via cfe-commits
rcraik updated the summary for this revision.
rcraik updated this revision to Diff 34571.
rcraik added a comment.

switched to using getIntWidth instead of getTypeSize and updated the error and 
warning messages accordingly, as have the necessary test cases. The separate 
check for _Bool bitfields has been removed, so the check is now consistent for 
all types.


http://reviews.llvm.org/D10018

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/CodeGen/bitfield-2.c
  test/CodeGenCXX/warn-padded-packed.cpp
  test/Misc/warning-flags.c
  test/Sema/bitfield.c
  test/SemaCXX/bitfield-layout.cpp
  test/SemaCXX/constant-expression-cxx11.cpp
  test/SemaCXX/constant-expression-cxx1y.cpp
  test/SemaCXX/ms_wide_bitfield.cpp
  test/SemaObjC/class-bitfield.m

Index: test/SemaObjC/class-bitfield.m
===
--- test/SemaObjC/class-bitfield.m
+++ test/SemaObjC/class-bitfield.m
@@ -5,7 +5,7 @@
   int a : -1; // expected-error{{bit-field 'a' has negative width}}
 
   // rdar://6081627
-  int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}
 
   int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}
   int d : (int)(1 + 0.25); 
Index: test/SemaCXX/ms_wide_bitfield.cpp
===
--- test/SemaCXX/ms_wide_bitfield.cpp
+++ test/SemaCXX/ms_wide_bitfield.cpp
@@ -1,9 +1,10 @@
 // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only -mms-bitfields -verify %s 2>&1
 
 struct A {
-  char a : 9; // expected-error{{size of bit-field 'a' (9 bits) exceeds size of its type (8 bits)}}
-  int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}
-  bool c : 9; // expected-error{{size of bit-field 'c' (9 bits) exceeds size of its type (8 bits)}}
+  char a : 9; // expected-error{{width of bit-field 'a' (9 bits) exceeds width of its type (8 bits)}}
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}
+  bool c : 9; // expected-error{{width of bit-field 'c' (9 bits) exceeds width of its type (1 bit)}}
+  bool d : 3; // expected-error{{width of bit-field 'd' (3 bits) exceeds width of its type (1 bit)}}
 };
 
 int a[sizeof(A) == 1 ? 1 : -1];
Index: test/SemaCXX/constant-expression-cxx1y.cpp
===
--- test/SemaCXX/constant-expression-cxx1y.cpp
+++ test/SemaCXX/constant-expression-cxx1y.cpp
@@ -872,7 +872,7 @@
 
 namespace Bitfields {
   struct A {
-bool b : 3;
+bool b : 1;
 int n : 4;
 unsigned u : 5;
   };
Index: test/SemaCXX/constant-expression-cxx11.cpp
===
--- test/SemaCXX/constant-expression-cxx11.cpp
+++ test/SemaCXX/constant-expression-cxx11.cpp
@@ -1801,9 +1801,9 @@
 bool b : 1;
 unsigned u : 5;
 int n : 5;
-bool b2 : 3;
-unsigned u2 : 74; // expected-warning {{exceeds the size of its type}}
-int n2 : 81; // expected-warning {{exceeds the size of its type}}
+bool b2 : 3; // expected-warning {{exceeds the width of its type}}
+unsigned u2 : 74; // expected-warning {{exceeds the width of its type}}
+int n2 : 81; // expected-warning {{exceeds the width of its type}}
   };
 
   constexpr A a = { false, 33, 31, false, 0x, 0x7fff }; // expected-warning 2{{truncation}}
Index: test/SemaCXX/bitfield-layout.cpp
===
--- test/SemaCXX/bitfield-layout.cpp
+++ test/SemaCXX/bitfield-layout.cpp
@@ -5,25 +5,25 @@
 
 // Simple tests.
 struct Test1 {
-  char c : 9; // expected-warning {{size of bit-field 'c' (9 bits) exceeds the size of its type; value will be truncated to 8 bits}}
+  char c : 9; // expected-warning {{width of bit-field 'c' (9 bits) exceeds the width of its type; value will be truncated to 8 bits}}
 };
 CHECK_SIZE(Test1, 2);
 CHECK_ALIGN(Test1, 1);
 
 struct Test2 {
-  char c : 16; // expected-warning {{size of bit-field 'c' (16 bits) exceeds the size of its type; value will be truncated to 8 bits}}
+  char c : 16; // expected-warning {{width of bit-field 'c' (16 bits) exceeds the width of its type; value will be truncated to 8 bits}}
 };
 CHECK_SIZE(Test2, 2);
 CHECK_ALIGN(Test2, 2);
 
 struct Test3 {
-  char c : 32; // expected-warning {{size of bit-field 'c' (32 bits) exceeds the size of its type; value will be truncated to 8 bits}}
+  char c : 32; // expected-warning {{width of bit-field 'c' (32 bits) exceeds the width of its type; value will be truncated to 8 bits}}
 };
 CHECK_SIZE(Test3, 4);
 CHECK_ALIGN(Test3, 4);
 
 struct Test4 {
-  char c : 64; // expected-warning {{size of 

Re: [PATCH] D10018: C11 _Bool bitfield diagnostic

2015-09-11 Thread Rachel Craik via cfe-commits
rcraik marked 3 inline comments as done.
rcraik added a comment.

http://reviews.llvm.org/D10018



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


Re: [PATCH] D10018: C11 _Bool bitfield diagnostic

2015-09-10 Thread Rachel Craik via cfe-commits
rcraik added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:12586
@@ -12585,3 +12585,3 @@
   if (!FieldTy->isDependentType()) {
 uint64_t TypeSize = Context.getTypeSize(FieldTy);
 if (Value.getZExtValue() > TypeSize) {

hubert.reinterpretcast wrote:
> rsmith wrote:
> > I think the right way to fix this is to call `getIntWidth` here instead of 
> > `getTypeSize`, and finesse our error message to clarify that we're talking 
> > about the width of the type (the number of value bits) rather than the size 
> > of the type (the number of storage bits).
> The implementation of `getIntWidth` currently makes this consideration moot 
> at this time, but should this extend to C89 (aside from the `_Bool` 
> extension)?
I think we have three options (the special case for _Bool bitfields being 
removed in each case):
  # change `getTypeSize` to `getIntWidth` and leave the rest of the checks 
as-is 
  # change `getTypeSize` to `getIntWidth` and update the C/MS diagnostic to 
either `ExtWarn` or `Warning`  (for some or all language levels)
  # leave as `getTypeSize` for lower language levels

Opinions?


http://reviews.llvm.org/D10018



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


Re: [PATCH] D10018: C11 _Bool bitfield diagnostic

2015-09-09 Thread Rachel Craik via cfe-commits
rcraik updated this revision to Diff 34339.
rcraik added a comment.

I've updated the message to make it a bit clearer that this is a portability 
concern. Are there any further concerns with this patch?


http://reviews.llvm.org/D10018

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/Misc/warning-flags.c
  test/Sema/c11-bitfield-width.c

Index: test/Sema/c11-bitfield-width.c
===
--- test/Sema/c11-bitfield-width.c
+++ test/Sema/c11-bitfield-width.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c99
+
+struct A {
+  _Bool : 0;// ok
+  _Bool : 3;// expected-warning {{size of anonymous bit-field (3 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool : 5;// expected-warning {{size of anonymous bit-field (5 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool : 7;// expected-warning {{size of anonymous bit-field (7 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool a : 1;  // ok
+  _Bool b : 2;  // expected-warning {{size of bit-field 'b' (2 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool c : 4;  // expected-warning {{size of bit-field 'c' (4 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+  _Bool d : 8;  // expected-warning {{size of bit-field 'd' (8 bits) exceeds the minimum width required to represent all valid values of that bit-field type}}
+};
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (92):
+CHECK: Warnings without flags (90):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -44,10 +44,8 @@
 CHECK-NEXT:   pp_pragma_sysheader_in_main_file
 CHECK-NEXT:   w_asm_qualifier_ignored
 CHECK-NEXT:   warn_accessor_property_type_mismatch
-CHECK-NEXT:   warn_anon_bitfield_width_exceeds_type_size
 CHECK-NEXT:   warn_arcmt_nsalloc_realloc
 CHECK-NEXT:   warn_asm_label_on_auto_decl
-CHECK-NEXT:   warn_bitfield_width_exceeds_type_size
 CHECK-NEXT:   warn_c_kext
 CHECK-NEXT:   warn_call_to_pure_virtual_member_function_from_ctor_dtor
 CHECK-NEXT:   warn_call_wrong_number_of_arguments
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12604,6 +12604,20 @@
 Diag(FieldLoc, diag::warn_anon_bitfield_width_exceeds_type_size)
   << (unsigned)Value.getZExtValue() << (unsigned)TypeSize;
 }
+// C11 6.7.2.1p4 + footnote 122/C99 6.7.2.1p3 - the width of a bitfield
+// of type _Bool may be erroneous if it exceeds 1 bit.
+// Warn about _Bool bitfields > 1 bit as they will not be portable across
+// different platforms
+if ((getLangOpts().C11 || getLangOpts().C99) && 
+FieldTy->isBooleanType() &&
+Value.getZExtValue() > 1) {
+  if (FieldName)
+Diag(FieldLoc, diag::warn_bitfield_width_longer_than_necessary)
+<< FieldName << (unsigned)Value.getZExtValue();
+  else
+Diag(FieldLoc, diag::warn_anon_bitfield_width_longer_than_necessary)
+<< (unsigned)Value.getZExtValue();
+}
   }
 
   return BitWidth;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -4317,14 +4317,20 @@
   "size of anonymous bit-field (%0 bits) exceeds size of its type (%1 bits)">;
 def err_incorrect_number_of_vector_initializers : Error<
   "number of elements must be either one or match the size of the vector">;
+def warn_bitfield_width_longer_than_necessary : Warning<
+  "size of bit-field %0 (%1 bits) exceeds the minimum width required to "
+  "represent all valid values of that bit-field type">, InGroup;
+def warn_anon_bitfield_width_longer_than_necessary : Warning<
+  "size of anonymous bit-field (%0 bits) exceeds the minimum width required to "
+  "represent all valid values of that bit-field type">, InGroup;
 
 // Used by C++ which allows bit-fields that are wider than the type.
 def warn_bitfield_width_exceeds_type_size: Warning<
   "size of bit-field %0 (%1 bits) exceeds the size of its type; value will be "
-  "truncated to %2 bits">;
+  "truncated to %2 bits">, InGroup;
 def warn_anon_bitfield_width_exceeds_type_size : Warning<
   "size of anonymous 

Re: [PATCH] D11582: Fix assertion failure in TransformOpaqueValueExpr

2015-08-12 Thread Rachel Craik via cfe-commits
rcraik added a comment.

ping 2!


http://reviews.llvm.org/D11582



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