[PATCH] D32635: [libcxx] regex: fix backreferences in forward assertions

2017-04-28 Thread Peter Ammon via Phabricator via cfe-commits
pammon created this revision.
Herald added a reviewer: EricWF.

In regex, forward assertions like '(?=stuff)' are implemented by
constructing a child regular expression 'stuff' and matching that.
If the child regular expression contains a backreference, this would
trip an assertion or reference the wrong capture group, because the
child was ignorant of the capture groups of its parent. For example,
/(x)(?=\1)/ would trip an assertion.

Address this by propagating submatches into the child, so that
backreferences reference the correct capture groups. This also allows us
to eliminate the mexp_ field, because the child expression shares the
entire submatch array with the parent.


https://reviews.llvm.org/D32635

Files:
  include/regex
  test/std/re/re.alg/re.alg.match/ecma.pass.cpp

Index: test/std/re/re.alg/re.alg.match/ecma.pass.cpp
===
--- test/std/re/re.alg/re.alg.match/ecma.pass.cpp
+++ test/std/re/re.alg/re.alg.match/ecma.pass.cpp
@@ -637,6 +637,22 @@
 assert(m.str(0) == s);
 }
 {
+  std::cmatch m;
+  const char s[] = "abcabc";
+  assert(std::regex_match(s, m, std::regex("(.+)(?=\\1)(\\1)")));
+  assert(m.size() == 3);
+  assert(m.str(1) == "abc");
+  assert(m.str(2) == "abc");
+}
+{
+  std::cmatch m;
+  const char s[] = "aa";
+  assert(std::regex_match(s, m, std::regex("(a+)(?!\\1)(a*)")));
+  assert(m.size() == 3);
+  assert(m.str(1) == "aa");
+  assert(m.str(2) == "");
+}
+{
 std::cmatch m;
 const char s[] = "foobar";
 assert(std::regex_match(s, m, std::regex("[^\\0]*")));
Index: include/regex
===
--- include/regex
+++ include/regex
@@ -2826,7 +2826,7 @@
 void __push_end_marked_subexpression(unsigned);
 void __push_empty();
 void __push_word_boundary(bool);
-void __push_lookahead(const basic_regex&, bool, unsigned);
+void __push_lookahead(basic_regex, bool);
 
 template 
 bool
@@ -2843,6 +2843,7 @@
 bool
 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
  match_results& __m,
+ const vector> &incoming_sub_matches,
  regex_constants::match_flag_type __flags, bool) const;
 template 
 bool
@@ -2964,17 +2965,16 @@
 typedef __owns_one_state<_CharT> base;
 
 basic_regex<_CharT, _Traits> __exp_;
-unsigned __mexp_;
 bool __invert_;
 
 __lookahead(const __lookahead&);
 __lookahead& operator=(const __lookahead&);
 public:
 typedef _VSTD::__state<_CharT> __state;
 
 _LIBCPP_INLINE_VISIBILITY
-__lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
-: base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
+__lookahead(basic_regex<_CharT, _Traits> __exp, bool __invert, __node<_CharT>* __s)
+: base(__s), __exp_(move(__exp)), __invert_(__invert) {}
 
 virtual void __exec(__state&) const;
 };
@@ -2987,16 +2987,18 @@
 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
 bool __matched = __exp_.__match_at_start_ecma(
 __s.__current_, __s.__last_,
-__m,
+__m, __s.__sub_matches_,
 (__s.__flags_ | regex_constants::match_continuous) &
 ~regex_constants::__full_match,
 __s.__at_first_ && __s.__current_ == __s.__first_);
 if (__matched != __invert_)
 {
 __s.__do_ = __state::__accept_but_not_consume;
 __s.__node_ = this->first();
-for (unsigned __i = 1; __i < __m.size(); ++__i) {
-__s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
+if (__matched) {
+for (unsigned __i = 1; __i < __m.size(); ++__i) {
+__s.__sub_matches_[__i - 1] = __m.__matches_[__i];
+}
 }
 }
 else
@@ -4168,26 +4170,16 @@
 switch (*__temp)
 {
 case '=':
-{
-basic_regex __exp;
-__exp.__flags_ = __flags_;
-__temp = __exp.__parse(++__temp, __last);
-unsigned __mexp = __exp.__marked_count_;
-__push_lookahead(_VSTD::move(__exp), false, __marked_count_);
-__marked_count_ += __mexp;
-if (__temp == __last || *__temp != ')')
-__throw_regex_error();
-__first = ++__temp;
-}
-break;
 case '!':
 {
+bool __invert = (*__temp == '!');
 basic_regex __exp;
   

[PATCH] D32638: [x86][inline-asm][clang]Amend size directive deduction mechanism of unsized memory operands

2017-04-28 Thread coby via Phabricator via cfe-commits
coby created this revision.

This is an extension of the work being carried by the following change:
https://reviews.llvm.org/D26586
This commit handles cases where the size qualifier of an indirect memory 
reference operand in Intel syntax is missing (e.g. "vaddps xmm1, xmm2, [a]").
GCC will deduce the size qualifier based on the possible matches:
"vaddps xmm1, xmm2, [a]" matches only “XMMWORD PTR” qualifier.
"vaddps xmm1, xmm2, [a]{1to4}" matches only “DWORD PTR” qualifier.
"mov rax, [a]" matches only "QWORD PTR"

Currently, size directive will be deduced based on the size of the memory 
operand (apart from those cases which were handled by 
https://reviews.llvm.org/D26586).
For example:
"vaddps xmm1, xmm2, [a]"
"char a;" will imply "BYTE PTR" qualifier
"short a;" will imply "WORD PTR" qualifier.

This commit aligns LLVM to GCC’s behavior.

This is the Clang part of the review.
The LLVM part can be found here:
https://reviews.llvm.org/D32636


Repository:
  rL LLVM

https://reviews.llvm.org/D32638

Files:
  test/CodeGen/ms-inline-asm-memory-adjustments.c


Index: test/CodeGen/ms-inline-asm-memory-adjustments.c
===
--- test/CodeGen/ms-inline-asm-memory-adjustments.c
+++ test/CodeGen/ms-inline-asm-memory-adjustments.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -target-cpu 
skylake-avx512 -fasm-blocks -o - | FileCheck %s
+
+void t() {
+  char c;
+  // CHECK: vaddps xmm1, xmm2, dword ptr $1{1to4}
+  __asm vaddps xmm1, xmm2, [c]{1to4}
+  // CHECK: vaddps xmm1, xmm2, xmmword ptr $2
+  __asm vaddps xmm1, xmm2, [c]
+  // CHECK: mov eax, dword ptr $3
+  __asm mov eax, [c]
+  // CHECK: mov qword ptr $0, rax
+  __asm mov [c], rax
+}
+


Index: test/CodeGen/ms-inline-asm-memory-adjustments.c
===
--- test/CodeGen/ms-inline-asm-memory-adjustments.c
+++ test/CodeGen/ms-inline-asm-memory-adjustments.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -target-cpu skylake-avx512 -fasm-blocks -o - | FileCheck %s
+
+void t() {
+  char c;
+  // CHECK: vaddps xmm1, xmm2, dword ptr $1{1to4}
+  __asm vaddps xmm1, xmm2, [c]{1to4}
+  // CHECK: vaddps xmm1, xmm2, xmmword ptr $2
+  __asm vaddps xmm1, xmm2, [c]
+  // CHECK: mov eax, dword ptr $3
+  __asm mov eax, [c]
+  // CHECK: mov qword ptr $0, rax
+  __asm mov [c], rax
+}
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31320: [analyzer] Teach CloneDetection about Qt Meta-Object Compiler

2017-04-28 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai updated this revision to Diff 97059.
xiangzhai added a comment.

Hi Artem,

Thanks for your review!

> Because LLVM's Illinois license is rather permissive than copyleft, we try to 
> avoid stuff copied from GPL/LGPL software (such as Qt or K3B) in our 
> codebase. The code doesn't seem to have been copy-pasted from a copyleft 
> project, but I guess it's better to rename the file to avoid referencing to 
> K3B.

Sorry for my mistake! I have rename the testcase to moc_autogenerated.cpp and 
autogenerated_automoc.cpp. I am the maintainer of K3B, if you find any bug when 
burning ISO please report bug to me :)

> Other LLVM contributors are free to edit this file, and i doubt it was 
> autogenerated; i believe these comments should be removed.

Sorry for my fault!

  /* This file is autogenerated, do not edit*/

it is autogenerated by MOC, I removed it!

And I use a single line LLVM regex instead of std::string functions, please 
review my patch, thanks a lot!

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D31320

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  test/Analysis/copypaste/autogenerated_automoc.cpp
  test/Analysis/copypaste/moc_autogenerated.cpp

Index: test/Analysis/copypaste/autogenerated_automoc.cpp
===
--- test/Analysis/copypaste/autogenerated_automoc.cpp
+++ test/Analysis/copypaste/autogenerated_automoc.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Because files that have `_automoc.' in their names are most likely autogenerated,
+// we suppress copy-paste warnings here.
+
+// expected-no-diagnostics
+
+void f1() {
+  int *p1 = new int[1];
+  int *p2 = new int[1];
+  if (p1) {
+delete [] p1;
+p1 = nullptr;
+  }
+  if (p2) {
+delete [] p1; // no-warning
+p2 = nullptr;
+  }
+}
Index: test/Analysis/copypaste/moc_autogenerated.cpp
===
--- test/Analysis/copypaste/moc_autogenerated.cpp
+++ test/Analysis/copypaste/moc_autogenerated.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Because files that have `moc_' in their names are most likely autogenerated,
+// we suppress copy-paste warnings here.
+
+// expected-no-diagnostics
+
+void f1() {
+  int *p1 = new int[1];
+  int *p2 = new int[1];
+  if (p1) {
+delete [] p1;
+p1 = nullptr;
+  }
+  if (p2) {
+delete [] p1; // no-warning
+p2 = nullptr;
+  }
+}
Index: lib/StaticAnalyzer/Checkers/CloneChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CloneChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CloneChecker.cpp
@@ -78,7 +78,8 @@
   // because reportSuspiciousClones() wants to search them for errors.
   std::vector AllCloneGroups;
 
-  Detector.findClones(AllCloneGroups, RecursiveCloneTypeIIConstraint(),
+  Detector.findClones(AllCloneGroups, AutoGeneratedCloneConstraint(), 
+  RecursiveCloneTypeIIConstraint(),
   MinComplexityConstraint(MinComplexity),
   MinGroupSizeConstraint(2), OnlyLargestCloneConstraint());
 
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -21,6 +21,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Regex.h"
 
 using namespace clang;
 
@@ -366,6 +367,29 @@
   }
 }
 
+bool AutoGeneratedCloneConstraint::isAutoGenerated(const CloneDetector::CloneGroup &Group) {
+  if (Group.empty())
+return false;
+
+  for (const StmtSequence &S : Group) {
+const Decl *D = S.getContainingDecl();
+const SourceManager &SM = D->getASTContext().getSourceManager();
+std::string Filename = std::string(SM.getFilename(D->getLocation()));
+// Get Basename
+const size_t LastSlash = Filename.find_last_of("\\/");
+if (LastSlash != std::string::npos)
+  Filename.erase(0, LastSlash + 1);
+const size_t LastDot = Filename.rfind('.');
+if (LastDot != std::string::npos)
+  Filename.erase(LastDot);
+llvm::Regex R(StringRef("^(moc_|.*_automoc$)"));
+if (R.match(StringRef(Filename)))
+  return true;
+  }
+
+  return false;
+}
+
 static size_t createHash(llvm::MD5 &Hash) {
   size_t HashCode;
 
Index: include/clang/Analysis/CloneDetection.h
===
--- include/clang/Analysis/CloneDetection.h
+++ include/clang/Analysis/CloneDetection.h
@@ -319,6 +319,17 @@
   void constrain(std::vector &Result);
 };
 
+struct AutoGeneratedCloneConstraint {
+  bool isAutoGenerated(const CloneDetector::CloneGroup &Group);
+
+  void cons

[PATCH] D32592: [Analyzer] Iterator Checker - Part1: Minimal Checker for a Simple Test Case

2017-04-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 97060.
baloghadamsoftware added a comment.

Checker and test included now :-)


https://reviews.llvm.org/D32592

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/iterator-past-end.cpp
  test/Analysis/iterator-range.cpp

Index: test/Analysis/iterator-range.cpp
===
--- /dev/null
+++ test/Analysis/iterator-range.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorRange -analyzer-eagerly-assume -analyzer-config c++-container-inlining=false %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorRange -analyzer-eagerly-assume -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void simple_good_end(const std::vector &v) {
+  auto i = v.end();
+  if (i != v.end())
+*i; // no-warning
+}
+
+void simple_bad_end(const std::vector &v) {
+  auto i = v.end();
+  *i; // expected-warning{{Iterator accessed outside of its range}}
+}
Index: test/Analysis/iterator-past-end.cpp
===
--- test/Analysis/iterator-past-end.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorPastEnd -analyzer-eagerly-assume -analyzer-config c++-container-inlining=false %s -verify
-// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorPastEnd -analyzer-eagerly-assume -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
-
-#include "Inputs/system-header-simulator-cxx.h"
-
-void simple_good(const std::vector &v) {
-  auto i = v.end();
-  if (i != v.end())
-*i; // no-warning
-}
-
-void simple_good_negated(const std::vector &v) {
-  auto i = v.end();
-  if (!(i == v.end()))
-*i; // no-warning
-}
-
-void simple_bad(const std::vector &v) {
-  auto i = v.end();
-  *i; // expected-warning{{Iterator accessed past its end}}
-}
-
-void copy(const std::vector &v) {
-  auto i1 = v.end();
-  auto i2 = i1;
-  *i2; // expected-warning{{Iterator accessed past its end}}
-}
-
-void decrease(const std::vector &v) {
-  auto i = v.end();
-  --i;
-  *i; // no-warning
-}
-
-void copy_and_decrease1(const std::vector &v) {
-  auto i1 = v.end();
-  auto i2 = i1;
-  --i1;
-  *i1; // no-warning
-}
-
-void copy_and_decrease2(const std::vector &v) {
-  auto i1 = v.end();
-  auto i2 = i1;
-  --i1;
-  *i2; // expected-warning{{Iterator accessed past its end}}
-}
-
-void copy_and_increase1(const std::vector &v) {
-  auto i1 = v.begin();
-  auto i2 = i1;
-  ++i1;
-  if (i1 == v.end())
-*i2; // no-warning
-}
-
-void copy_and_increase2(const std::vector &v) {
-  auto i1 = v.begin();
-  auto i2 = i1;
-  ++i1;
-  if (i2 == v.end())
-*i2; // expected-warning{{Iterator accessed past its end}}
-}
-
-void good_find(std::vector &vec, int e) {
-  auto first = std::find(vec.begin(), vec.end(), e);
-  if (vec.end() != first)
-*first; // no-warning
-}
-
-void bad_find(std::vector &vec, int e) {
-  auto first = std::find(vec.begin(), vec.end(), e);
-  *first; // expected-warning{{Iterator accessed past its end}}
-}
-
-void good_find_end(std::vector &vec, std::vector &seq) {
-  auto last = std::find_end(vec.begin(), vec.end(), seq.begin(), seq.end());
-  if (vec.end() != last)
-*last; // no-warning
-}
-
-void bad_find_end(std::vector &vec, std::vector &seq) {
-  auto last = std::find_end(vec.begin(), vec.end(), seq.begin(), seq.end());
-  *last; // expected-warning{{Iterator accessed past its end}}
-}
-
-void good_find_first_of(std::vector &vec, std::vector &seq) {
-  auto first =
-  std::find_first_of(vec.begin(), vec.end(), seq.begin(), seq.end());
-  if (vec.end() != first)
-*first; // no-warning
-}
-
-void bad_find_first_of(std::vector &vec, std::vector &seq) {
-  auto first = std::find_end(vec.begin(), vec.end(), seq.begin(), seq.end());
-  *first; // expected-warning{{Iterator accessed past its end}}
-}
-
-bool odd(int i) { return i % 2; }
-
-void good_find_if(std::vector &vec) {
-  auto first = std::find_if(vec.begin(), vec.end(), odd);
-  if (vec.end() != first)
-*first; // no-warning
-}
-
-void bad_find_if(std::vector &vec, int e) {
-  auto first = std::find_if(vec.begin(), vec.end(), odd);
-  *first; // expected-warning{{Iterator accessed past its end}}
-}
-
-void good_find_if_not(std::vector &vec) {
-  auto first = std::find_if_not(vec.begin(), vec.end(), odd);
-  if (vec.end() != first)
-*first; // no-warning
-}
-
-void bad_find_if_not(std::vector &vec, int e) {
-  auto first = 

[PATCH] D31320: [analyzer] Teach CloneDetection about Qt Meta-Object Compiler

2017-04-28 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In general, I think we should support such use-cases. It seems cleaner to me if 
we provide some sort of callbacks where the users can specify their custom 
false positive filters. I've discussed this in brief with Raphael and we were 
planning to write this up.


Repository:
  rL LLVM

https://reviews.llvm.org/D31320



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


[PATCH] D31320: [analyzer] Teach CloneDetection about Qt Meta-Object Compiler

2017-04-28 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai added a comment.

Hi Vassil,

The first one considered about CopyPaste dection 
 Thanks for 
your reply! Let's do it together and Happy International Labor Day :)

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D31320



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


[PATCH] D30946: [ScopePrinting] Added support to print full scopes of types and declarations.

2017-04-28 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added a comment.

Can you please run clang-format on this change? There are pieces that don't 
follow the style.

Also the mutable state in PrintingPolicy is really really ugly, is there no 
better way for this? :(


https://reviews.llvm.org/D30946



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


r301635 - [index] Handle vector types in USR generator

2017-04-28 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Apr 28 04:46:36 2017
New Revision: 301635

URL: http://llvm.org/viewvc/llvm-project?rev=301635&view=rev
Log:
[index] Handle vector types in USR generator

rdar://25339187

Modified:
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/usrs.cpp

Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=301635&r1=301634&r2=301635&view=diff
==
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Fri Apr 28 04:46:36 2017
@@ -811,7 +811,13 @@ void USRGenerator::VisitType(QualType T)
   T = InjT->getInjectedSpecializationType();
   continue;
 }
-
+if (const auto *VT = T->getAs()) {
+  Out << (T->isExtVectorType() ? ']' : '[');
+  Out << VT->getNumElements();
+  T = VT->getElementType();
+  continue;
+}
+
 // Unhandled type.
 Out << ' ';
 break;

Modified: cfe/trunk/test/Index/usrs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.cpp?rev=301635&r1=301634&r2=301635&view=diff
==
--- cfe/trunk/test/Index/usrs.cpp (original)
+++ cfe/trunk/test/Index/usrs.cpp Fri Apr 28 04:46:36 2017
@@ -95,6 +95,14 @@ class TC1 {
   void meth(TC1);
 };
 
+typedef __attribute__((__ext_vector_type__(3))) float float3;
+
+typedef float __m128 __attribute__((__vector_size__(16)));
+
+float3 vectorOverload(float3 f);
+
+__m128 vectorOverload(__m128 f);
+
 // RUN: c-index-test -test-load-source-usrs all -fno-delayed-template-parsing 
%s | FileCheck %s
 // CHECK: usrs.cpp c:@N@foo Extent=[1:1 - 4:2]
 // CHECK: usrs.cpp c:@N@foo@x Extent=[2:3 - 2:8]
@@ -172,3 +180,6 @@ class TC1 {
 // CHECK: usrs.cpp c:usrs.cpp@s...@usrs.cpp@1510@FI@x Extent=[91:10 - 91:15]
 
 // CHECK: usrs.cpp c:@ST>1#T@TC1@F@meth#>@ST>1#T@TC11t0.0# Extent=[95:3 - 
95:17]
+
+// CHECK: usrs.cpp c:@F@vectorOverload#]3f# Extent=[102:1 - 102:32]
+// CHECK: usrs.cpp c:@F@vectorOverload#[4f# Extent=[104:1 - 104:32]


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


r301637 - [X86][SSE] Add _mm_set_pd1 (PR32827)

2017-04-28 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Fri Apr 28 05:28:32 2017
New Revision: 301637

URL: http://llvm.org/viewvc/llvm-project?rev=301637&view=rev
Log:
[X86][SSE] Add _mm_set_pd1 (PR32827)

Matches _mm_set_ps1 implementation

Modified:
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/test/CodeGen/sse2-builtins.c

Modified: cfe/trunk/lib/Headers/emmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/emmintrin.h?rev=301637&r1=301636&r2=301637&view=diff
==
--- cfe/trunk/lib/Headers/emmintrin.h (original)
+++ cfe/trunk/lib/Headers/emmintrin.h Fri Apr 28 05:28:32 2017
@@ -1750,6 +1750,24 @@ _mm_set1_pd(double __w)
   return (__m128d){ __w, __w };
 }
 
+/// \brief Constructs a 128-bit floating-point vector of [2 x double], with 
each
+///of the two double-precision floating-point vector elements set to the
+///specified double-precision floating-point value.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  VMOVDDUP / MOVLHPS  instruction.
+///
+/// \param __w
+///A double-precision floating-point value used to initialize each vector
+///element of the result.
+/// \returns An initialized 128-bit floating-point vector of [2 x double].
+static __inline__ __m128d __DEFAULT_FN_ATTRS
+_mm_set_pd1(double __w)
+{
+  return _mm_set1_pd(__w);
+}
+
 /// \brief Constructs a 128-bit floating-point vector of [2 x double]
 ///initialized with the specified double-precision floating-point values.
 ///

Modified: cfe/trunk/test/CodeGen/sse2-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sse2-builtins.c?rev=301637&r1=301636&r2=301637&view=diff
==
--- cfe/trunk/test/CodeGen/sse2-builtins.c (original)
+++ cfe/trunk/test/CodeGen/sse2-builtins.c Fri Apr 28 05:28:32 2017
@@ -951,6 +951,13 @@ __m128d test_mm_set_pd(double A, double
   return _mm_set_pd(A, B);
 }
 
+__m128d test_mm_set_pd1(double A) {
+  // CHECK-LABEL: test_mm_set_pd1
+  // CHECK: insertelement <2 x double> undef, double %{{.*}}, i32 0
+  // CHECK: insertelement <2 x double> %{{.*}}, double %{{.*}}, i32 1
+  return _mm_set_pd1(A);
+}
+
 __m128d test_mm_set_sd(double A) {
   // CHECK-LABEL: test_mm_set_sd
   // CHECK: insertelement <2 x double> undef, double %{{.*}}, i32 0


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


[PATCH] D32395: [clang-tidy] modernize-use-emplace: remove unnecessary make_pair calls

2017-04-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.

LG


https://reviews.llvm.org/D32395



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


r301643 - [Sema] Avoid an invalid redefinition error that was presented for

2017-04-28 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Apr 28 07:30:05 2017
New Revision: 301643

URL: http://llvm.org/viewvc/llvm-project?rev=301643&view=rev
Log:
[Sema] Avoid an invalid redefinition error that was presented for
of a function whose previous definition was typo-corrected

rdar://28550928

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/typo-correction.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=301643&r1=301642&r2=301643&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Apr 28 07:30:05 2017
@@ -1068,6 +1068,12 @@ public:
   /// same special member, we should act as if it is not yet declared.
   llvm::SmallSet SpecialMembersBeingDeclared;
 
+  /// The function definitions which were renamed as part of typo-correction
+  /// to match their respective declarations. We want to keep track of them
+  /// to ensure that we don't emit a "redefinition" error if we encounter a
+  /// correctly named definition after the renamed definition.
+  llvm::SmallPtrSet TypoCorrectedFunctionDefinitions;
+
   void ReadMethodPool(Selector Sel);
   void updateOutOfDateSelector(Selector Sel);
 
@@ -3117,6 +3123,8 @@ public:
 const PartialDiagnostic &PrevNote,
 bool ErrorRecovery = true);
 
+  void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F);
+
   void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc,
   ArrayRef Args,
AssociatedNamespaceSet 
&AssociatedNamespaces,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=301643&r1=301642&r2=301643&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 28 07:30:05 2017
@@ -7424,6 +7424,10 @@ class DifferentNameValidatorCCC : public
 
 } // end anonymous namespace
 
+void Sema::MarkTypoCorrectedFunctionDefinition(const NamedDecl *F) {
+  TypoCorrectedFunctionDefinitions.insert(F);
+}
+
 /// \brief Generate diagnostics for an invalid function redeclaration.
 ///
 /// This routine handles generating the diagnostic messages for an invalid
@@ -7521,6 +7525,8 @@ static NamedDecl *DiagnoseInvalidRedecla
 if ((*I)->getCanonicalDecl() == Canonical)
   Correction.setCorrectionDecl(*I);
 
+  // Let Sema know about the correction.
+  SemaRef.MarkTypoCorrectedFunctionDefinition(Result);
   SemaRef.diagnoseTypo(
   Correction,
   SemaRef.PDiag(IsLocalFriend
@@ -11732,6 +11738,11 @@ Sema::CheckForFunctionRedefinition(Funct
   if (canRedefineFunction(Definition, getLangOpts()))
 return;
 
+  // Don't emit an error when this is redifinition of a typo-corrected
+  // definition.
+  if (TypoCorrectedFunctionDefinitions.count(Definition))
+return;
+
   // If we don't have a visible definition of the function, and it's inline or
   // a template, skip the new definition.
   if (SkipBody && !hasVisibleDefinition(Definition) &&

Modified: cfe/trunk/test/SemaCXX/typo-correction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=301643&r1=301642&r2=301643&view=diff
==
--- cfe/trunk/test/SemaCXX/typo-correction.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction.cpp Fri Apr 28 07:30:05 2017
@@ -679,3 +679,30 @@ int g() {
   sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
 };
 }
+
+namespace avoidRedundantRedefinitionErrors {
+class Class {
+  void function(int pid); // expected-note {{'function' declared here}}
+};
+
+void Class::function2(int pid) { // expected-error {{out-of-line definition of 
'function2' does not match any declaration in 
'avoidRedundantRedefinitionErrors::Class'; did you mean 'function'?}}
+}
+
+// Expected no redefinition error here.
+void Class::function(int pid) { // expected-note {{previous definition is 
here}}
+}
+
+void Class::function(int pid) { // expected-error {{redefinition of 
'function'}}
+}
+
+namespace ns {
+void create_test(); // expected-note {{'create_test' declared here}}
+}
+
+void ns::create_test2() { // expected-error {{out-of-line definition of 
'create_test2' does not match any declaration in namespace 
'avoidRedundantRedefinitionErrors::ns'; did you mean 'create_test'?}}
+}
+
+// Expected no redefinition error here.
+void ns::create_test() {
+}
+}


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


[PATCH] D25113: [Sema] Don't display an invalid redefinition error when dealing with a redefinition of a function whose previous definition was typo-corrected

2017-04-28 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301643: [Sema] Avoid an invalid redefinition error that was 
presented for (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D25113?vs=96123&id=97084#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25113

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/SemaCXX/typo-correction.cpp


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1068,6 +1068,12 @@
   /// same special member, we should act as if it is not yet declared.
   llvm::SmallSet SpecialMembersBeingDeclared;
 
+  /// The function definitions which were renamed as part of typo-correction
+  /// to match their respective declarations. We want to keep track of them
+  /// to ensure that we don't emit a "redefinition" error if we encounter a
+  /// correctly named definition after the renamed definition.
+  llvm::SmallPtrSet TypoCorrectedFunctionDefinitions;
+
   void ReadMethodPool(Selector Sel);
   void updateOutOfDateSelector(Selector Sel);
 
@@ -3117,6 +3123,8 @@
 const PartialDiagnostic &PrevNote,
 bool ErrorRecovery = true);
 
+  void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F);
+
   void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc,
   ArrayRef Args,
AssociatedNamespaceSet 
&AssociatedNamespaces,
Index: cfe/trunk/test/SemaCXX/typo-correction.cpp
===
--- cfe/trunk/test/SemaCXX/typo-correction.cpp
+++ cfe/trunk/test/SemaCXX/typo-correction.cpp
@@ -679,3 +679,30 @@
   sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
 };
 }
+
+namespace avoidRedundantRedefinitionErrors {
+class Class {
+  void function(int pid); // expected-note {{'function' declared here}}
+};
+
+void Class::function2(int pid) { // expected-error {{out-of-line definition of 
'function2' does not match any declaration in 
'avoidRedundantRedefinitionErrors::Class'; did you mean 'function'?}}
+}
+
+// Expected no redefinition error here.
+void Class::function(int pid) { // expected-note {{previous definition is 
here}}
+}
+
+void Class::function(int pid) { // expected-error {{redefinition of 
'function'}}
+}
+
+namespace ns {
+void create_test(); // expected-note {{'create_test' declared here}}
+}
+
+void ns::create_test2() { // expected-error {{out-of-line definition of 
'create_test2' does not match any declaration in namespace 
'avoidRedundantRedefinitionErrors::ns'; did you mean 'create_test'?}}
+}
+
+// Expected no redefinition error here.
+void ns::create_test() {
+}
+}
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -7424,6 +7424,10 @@
 
 } // end anonymous namespace
 
+void Sema::MarkTypoCorrectedFunctionDefinition(const NamedDecl *F) {
+  TypoCorrectedFunctionDefinitions.insert(F);
+}
+
 /// \brief Generate diagnostics for an invalid function redeclaration.
 ///
 /// This routine handles generating the diagnostic messages for an invalid
@@ -7521,6 +7525,8 @@
 if ((*I)->getCanonicalDecl() == Canonical)
   Correction.setCorrectionDecl(*I);
 
+  // Let Sema know about the correction.
+  SemaRef.MarkTypoCorrectedFunctionDefinition(Result);
   SemaRef.diagnoseTypo(
   Correction,
   SemaRef.PDiag(IsLocalFriend
@@ -11732,6 +11738,11 @@
   if (canRedefineFunction(Definition, getLangOpts()))
 return;
 
+  // Don't emit an error when this is redifinition of a typo-corrected
+  // definition.
+  if (TypoCorrectedFunctionDefinitions.count(Definition))
+return;
+
   // If we don't have a visible definition of the function, and it's inline or
   // a template, skip the new definition.
   if (SkipBody && !hasVisibleDefinition(Definition) &&


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1068,6 +1068,12 @@
   /// same special member, we should act as if it is not yet declared.
   llvm::SmallSet SpecialMembersBeingDeclared;
 
+  /// The function definitions which were renamed as part of typo-correction
+  /// to match their respective declarations. We want to keep track of them
+  /// to ensure that we don't emit a "redefinition" error if we encounter a
+  /// correctly named definition after the renamed definition.
+  llvm::SmallPtrSet TypoCorrectedFunctionDefinitions;
+
   void ReadMethodPool(Selector Sel);
   void updateOutOfDateSelector(Selector Sel);
 
@@ -3117,6 +3123,8 @@
 const PartialDiagn

[PATCH] D31887: [clangd] Add documentation page

2017-04-28 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle-ericsson added a comment.

Would it be possible to commit this? I do not have commit rights. Thanks!


https://reviews.llvm.org/D31887



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


[PATCH] D31887: [clangd] Add documentation page

2017-04-28 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D31887#740727, @malaperle-ericsson wrote:

> Would it be possible to commit this? I do not have commit rights. Thanks!


Why won't you get commit right? You will probably make some other contribution 
to clangd, so it will be handy to have it :)


https://reviews.llvm.org/D31887



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


[PATCH] D29768: [TargetInfo] Set 'UseSignedCharForObjCBool' to false by default

2017-04-28 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D29768



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


[PATCH] D29768: [TargetInfo] Set 'UseSignedCharForObjCBool' to false by default

2017-04-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Basic/Targets.cpp:4340-4341
 llvm::Triple T = llvm::Triple(Triple);
-if (T.isWatchOS())
-  UseSignedCharForObjCBool = false;
+if (!T.isWatchOS())
+  UseSignedCharForObjCBool = true;
 SizeType = UnsignedLong;

Rather than using an if statement, why not assign directly? 
`UseSignedCharForObjCBool = !T.isWatchOS();`



Comment at: lib/Basic/Targets.cpp:4772-4773
 llvm::Triple T = llvm::Triple(Triple);
-if (T.isiOS())
-  UseSignedCharForObjCBool = false;
+if (!T.isiOS())
+  UseSignedCharForObjCBool = true;
 resetDataLayout("e-m:o-i64:64-f80:128-n8:16:32:64-S128");

Same here.


Repository:
  rL LLVM

https://reviews.llvm.org/D29768



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


[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-28 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D32389



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


[PATCH] D29877: Warn about unused static file scope function template declarations.

2017-04-28 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 97098.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

Implement a special diagnostic switch for the warning.


https://reviews.llvm.org/D29877

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/warn-unused-filescoped.cpp

Index: test/SemaCXX/warn-unused-filescoped.cpp
===
--- test/SemaCXX/warn-unused-filescoped.cpp
+++ test/SemaCXX/warn-unused-filescoped.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-unused-local-typedefs -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s
 
 #ifdef HEADER
 
@@ -65,7 +65,7 @@
   template <> void TS::m() { }  // expected-warning{{unused}}
 
   template 
-  void tf() { }
+  void tf() { }  // expected-warning{{unused}}
   template <> void tf() { }  // expected-warning{{unused}}
   
   struct VS {
@@ -200,6 +200,18 @@
 static void func() {}
 }
 
+namespace test9 {
+template
+static void completeRedeclChainForTemplateSpecialization() { } // expected-warning {{unused}}
+}
+
+namespace test10 {
+#if __cplusplus >= 201103L
+template
+constexpr T pi = T(3.14); // expected-warning {{unused}}
+#endif
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   // FIXME: We should warn on both of these.
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8904,6 +8904,7 @@
 if (FunctionTemplate) {
   if (NewFD->isInvalidDecl())
 FunctionTemplate->setInvalidDecl();
+  MarkUnusedFileScopedDecl(NewFD);
   return FunctionTemplate;
 }
   }
@@ -11004,8 +11005,7 @@
 
 /// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform
 /// any semantic actions necessary after any initializer has been attached.
-void
-Sema::FinalizeDeclaration(Decl *ThisDecl) {
+void Sema::FinalizeDeclaration(Decl *ThisDecl) {
   // Note that we are no longer parsing the initializer for this declaration.
   ParsingInitForAutoVars.erase(ThisDecl);
 
@@ -11170,9 +11170,8 @@
   if (DC->getRedeclContext()->isFileContext() && VD->isExternallyVisible())
 AddPushedVisibilityAttribute(VD);
 
-  // FIXME: Warn on unused templates.
-  if (VD->isFileVarDecl() && !VD->getDescribedVarTemplate() &&
-  !isa(VD))
+  // FIXME: Warn on unused var template partial specializations.
+  if (VD->isFileVarDecl() && !isa(VD))
 MarkUnusedFileScopedDecl(VD);
 
   // Now we have parsed the initializer and can update the table of magic
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -463,6 +463,13 @@
 return true;
 
   if (const FunctionDecl *FD = dyn_cast(D)) {
+// If this is a function template and none of its specializations is used,
+// we should warn.
+if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate())
+  for (const auto *Spec : Template->specializations())
+if (ShouldRemoveFromUnused(SemaRef, Spec))
+  return true;
+
 // UnusedFileScopedDecls stores the first declaration.
 // The declaration may have become definition so check again.
 const FunctionDecl *DeclToCheck;
@@ -486,6 +493,13 @@
 VD->isUsableInConstantExpressions(SemaRef->Context))
   return true;
 
+if (VarTemplateDecl *Template = VD->getDescribedVarTemplate())
+  // If this is a variable template and none of its specializations is used,
+  // we should warn.
+  for (const auto *Spec : Template->specializations())
+if (ShouldRemoveFromUnused(SemaRef, Spec))
+  return true;
+
 // UnusedFileScopedDecls stores the first declaration.
 // The declaration may have become definition so check again.
 const VarDecl *DeclToCheck = VD->getDefinition();
@@ -891,10 +905,14 @@
<< /*function*/0 << DiagD->getDeclName();
   }
 } else {
-  Diag(DiagD->getLocation(),
-   isa(DiagD) ? diag::warn_unused_member_function
- : diag::warn_unused_function)
-<< DiagD->getDeclName();
+  if (FD->getDescribedFunctionTemplate())
+Diag(DiagD->getLocation(), diag::warn_unused_template)
+  << /*function*/0 << DiagD->getDeclName();
+  else
+Diag(DiagD->getLocation(),
+ isa(DiagD) ? diag::warn_unu

[PATCH] D29877: Warn about unused static file scope function template declarations.

2017-04-28 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

@rsmith, @mclow.lists, @arphaman, I am planning to reland that soon. Let me 
know if you have any objections.


https://reviews.llvm.org/D29877



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


r301647 - Use the -Wunknown-warning-option group for the "unknown warning group"

2017-04-28 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Apr 28 09:45:25 2017
New Revision: 301647

URL: http://llvm.org/viewvc/llvm-project?rev=301647&view=rev
Log:
Use the -Wunknown-warning-option group for the "unknown warning group"
diagnostic in #pragma diagnostic

This matches the warning group that's specified for the unknown warning options
that are passed-in as command line arguments.

rdar://29526025

Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/test/Preprocessor/pragma_diagnostic.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=301647&r1=301646&r2=301647&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Fri Apr 28 09:45:25 2017
@@ -503,7 +503,7 @@ def warn_pragma_diagnostic_invalid_token
InGroup;
 def warn_pragma_diagnostic_unknown_warning :
ExtWarn<"unknown warning group '%0', ignored">,
-   InGroup;
+   InGroup;
 // - #pragma __debug
 def warn_pragma_debug_unexpected_command : Warning<
   "unexpected debug command '%0'">, InGroup;

Modified: cfe/trunk/test/Preprocessor/pragma_diagnostic.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_diagnostic.c?rev=301647&r1=301646&r2=301647&view=diff
==
--- cfe/trunk/test/Preprocessor/pragma_diagnostic.c (original)
+++ cfe/trunk/test/Preprocessor/pragma_diagnostic.c Fri Apr 28 09:45:25 2017
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-undef %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-undef 
-Wno-unknown-warning-option -DAVOID_UNKNOWN_WARNING %s
 // rdar://2362963
 
 #if FOO// ok.
@@ -28,8 +29,10 @@
 #pragma GCC diagnostic error "-Wundef" 42  // expected-warning {{unexpected 
token in pragma diagnostic}}
 #pragma GCC diagnostic error "invalid-name"  // expected-warning {{pragma 
diagnostic expected option name (e.g. "-Wundef")}}
 
-#pragma GCC diagnostic error "-Winvalid-name"  // expected-warning {{unknown 
warning group '-Winvalid-name', ignored}}
-
+#pragma GCC diagnostic error "-Winvalid-name"
+#ifndef AVOID_UNKNOWN_WARNING
+// expected-warning@-2 {{unknown warning group '-Winvalid-name', ignored}}
+#endif
 
 // Testing pragma clang diagnostic with -Weverything
 void ppo(){} // First test that we do not diagnose on this.


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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

This is an update patch for bug [1].

-Wmissing-braces should not fire for system headers.

[1] https://bugs.llvm.org/show_bug.cgi?id=24007


https://reviews.llvm.org/D32646

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/warn-missing-braces.c


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,24 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _GUID {
+  unsigned Data1;
+  unsigned short  Data2;
+  unsigned short  Data3;
+  unsigned char Data4[8];
+} GUID;
+
+#define REGISTRY_EXTENSION_GUID { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} 
expected-warning{{suggest braces}}
+
+GUID g = REGISTRY_EXTENSION_GUID; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,17 +885,22 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system 
header.
 if (T->isArrayType() || T->isRecordType()) {
-  SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
-   diag::warn_missing_braces)
-  << StructuredSubobjectInitList->getSourceRange()
-  << FixItHint::CreateInsertion(
- StructuredSubobjectInitList->getLocStart(), "{")
-  << FixItHint::CreateInsertion(
- SemaRef.getLocForEndOfToken(
- StructuredSubobjectInitList->getLocEnd()),
- "}");
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {
+SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
+ diag::warn_missing_braces)
+<< StructuredSubobjectInitList->getSourceRange()
+<< FixItHint::CreateInsertion(
+   StructuredSubobjectInitList->getLocStart(), "{")
+<< FixItHint::CreateInsertion(
+   SemaRef.getLocForEndOfToken(
+   StructuredSubobjectInitList->getLocEnd()),
+   "}");
+  }
 }
   }
 }


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,24 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _GUID {
+  unsigned Data1;
+  unsigned short  Data2;
+  unsigned short  Data3;
+  unsigned char Data4[8];
+} GUID;
+
+#define REGISTRY_EXTENSION_GUID { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
+
+GUID g = REGISTRY_EXTENSION_GUID; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,17 +885,22 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system header.
 if (T->isArrayType() || T->isRecordType()) {
-  SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
-   diag::warn_missing_braces)
-  << StructuredSubobjectInitList->getSourceRange()
-  << FixItHint::CreateInsertion(
- StructuredSubobjectInitList->getLocStart(), "{")
-  << FixItHint::CreateInsertion(
- SemaRef.getLocForEndOfToken(
- StructuredSubobjectInitList->getLocEnd()),
- "}");
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {
+SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
+ diag::warn_missing_braces)
+<< StructuredSubobjectInitList->getSourceRange()
+<< FixItHint::CreateInsertion(
+   StructuredSubobjectInitList->getLocStart(), "{")
+<< FixItHint::CreateInsertion(
+   SemaRef.getLocForEndOfToken(
+   StructuredSubobjectInitList->getLocE

[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-28 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: test/Sema/warn-missing-braces.c:6-11
+typedef struct _GUID {
+  unsigned Data1;
+  unsigned short  Data2;
+  unsigned short  Data3;
+  unsigned char Data4[8];
+} GUID;

You can simplify this, can't you? It seems something like

  struct foo { unsigned data[2]; };

suffices.



Comment at: test/Sema/warn-missing-braces.c:22
+
+GUID g = REGISTRY_EXTENSION_GUID; // should not show warnings
+

So this can be something like `struct foo b = BAR;`


https://reviews.llvm.org/D32646



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


[PATCH] D32372: Arrays of unknown bound in constant expressions

2017-04-28 Thread Robert Haberlach via Phabricator via cfe-commits
Arcoth updated this revision to Diff 97105.
Arcoth added a comment.

Updated `SubobjectDesignator` to hold `MostDerivedIsAnUnsizedArray` instead of 
`FirstEntryIsAnUnsizedArray`. Consequently, we cannot know whether the first 
element is an unsized array; please see line 7352 in particular, where the 
check for `isMostDerivedAnUnsizedArray`had to be removed (is this fine? All 
regression tests pass.)


https://reviews.llvm.org/D32372

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/SemaCXX/constexpr-array-unknown-bound.cpp

Index: test/SemaCXX/constexpr-array-unknown-bound.cpp
===
--- /dev/null
+++ test/SemaCXX/constexpr-array-unknown-bound.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++1z -fsyntax-only -verify
+
+const extern int arr[];
+constexpr auto p = arr; // ok
+constexpr int f(int i) {return p[i];} // expected-note {{read of dereferenced one-past-the-end pointer}}
+
+constexpr int arr[] {1, 2, 3};
+constexpr auto p2 = arr + 2; // ok
+constexpr int x = f(2); // ok
+constexpr int y = f(3); // expected-error {{constant expression}}
+// expected-note-re@-1 {{in call to 'f({{.*}})'}}
+
+struct A {int m[];} a;
+constexpr auto p3 = a.m; // ok
+constexpr auto p4 = a.m + 1; // expected-error {{constant expression}} expected-note {{constant bound}}
+
+void g(int i) {
+  int arr[i];
+  constexpr auto p = arr + 2; // expected-error {{constant expression}} expected-note {{constant bound}}
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -148,22 +148,26 @@
   static unsigned
   findMostDerivedSubobject(ASTContext &Ctx, APValue::LValueBase Base,
ArrayRef Path,
-   uint64_t &ArraySize, QualType &Type, bool &IsArray) {
+   uint64_t &ArraySize, QualType &Type, bool &IsArray,
+   bool &isUnsizedArray) {
 // This only accepts LValueBases from APValues, and APValues don't support
 // arrays that lack size info.
 assert(!isBaseAnAllocSizeCall(Base) &&
"Unsized arrays shouldn't appear here");
 unsigned MostDerivedLength = 0;
 Type = getType(Base);
 
 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
-  if (Type->isArrayType()) {
-const ConstantArrayType *CAT =
-cast(Ctx.getAsArrayType(Type));
-Type = CAT->getElementType();
-ArraySize = CAT->getSize().getZExtValue();
+  if (auto AT = Ctx.getAsArrayType(Type)) {
 MostDerivedLength = I + 1;
 IsArray = true;
+if (auto CAT = Ctx.getAsConstantArrayType(Type))
+  ArraySize = CAT->getSize().getZExtValue();
+else {
+  ArraySize = 0;
+  isUnsizedArray = true;
+}
+Type = AT->getElementType();
   } else if (Type->isAnyComplexType()) {
 const ComplexType *CT = Type->castAs();
 Type = CT->getElementType();
@@ -200,8 +204,9 @@
 /// Is this a pointer one past the end of an object?
 unsigned IsOnePastTheEnd : 1;
 
-/// Indicator of whether the first entry is an unsized array.
-unsigned FirstEntryIsAnUnsizedArray : 1;
+/// Indicator of whether the most-derived object is an unsized array (e.g.
+/// of unknown bound).
+unsigned MostDerivedIsAnUnsizedArray : 1;
 
 /// Indicator of whether the most-derived object is an array element.
 unsigned MostDerivedIsArrayElement : 1;
@@ -231,25 +236,28 @@
 
 explicit SubobjectDesignator(QualType T)
 : Invalid(false), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0),
   MostDerivedType(T) {}
 
 SubobjectDesignator(ASTContext &Ctx, const APValue &V)
 : Invalid(!V.isLValue() || !V.hasLValuePath()), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0) {
   assert(V.isLValue() && "Non-LValue used to make an LValue designator?");
   if (!Invalid) {
 IsOnePastTheEnd = V.isLValueOnePastTheEnd();
 ArrayRef VEntries = V.getLValuePath();
 Entries.insert(Entries.end(), VEntries.begin(), VEntries.end());
-if (V.getLValueBase()) {
-  bool IsArray = false;
+if (auto Base = V.getLValueBase()) {
+  if (auto Decl = Base.dyn_cast())
+Base = cast(Decl->getMostRecentDecl());
+  bool IsArray = false, IsUnsizedArray = false;
   MostDerivedPathLength = findMostDerivedSubobject(
-  Ctx, V.getLValueBase(), V.getLValuePath

r301648 - [libclang] Expose some target information via the C API.

2017-04-28 Thread Emilio Cobos Alvarez via cfe-commits
Author: emilio
Date: Fri Apr 28 10:56:39 2017
New Revision: 301648

URL: http://llvm.org/viewvc/llvm-project?rev=301648&view=rev
Log:
[libclang] Expose some target information via the C API.

This allows users to query the target triple and target pointer width, which
would make me able to fix https://github.com/servo/rust-bindgen/issues/593 and
other related bugs in an elegant way (without having to manually parse the
target triple in the command line arguments).

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


Added:
cfe/trunk/test/Index/target-info.c
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CXTranslationUnit.h
cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=301648&r1=301647&r2=301648&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Apr 28 10:56:39 2017
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 37
+#define CINDEX_VERSION_MINOR 38
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -81,6 +81,12 @@ extern "C" {
 typedef void *CXIndex;
 
 /**
+ * \brief An opaque type representing target information for a given 
translation
+ * unit.
+ */
+typedef struct CXTargetInfoImpl *CXTargetInfo;
+
+/**
  * \brief A single translation unit, which resides in an index.
  */
 typedef struct CXTranslationUnitImpl *CXTranslationUnit;
@@ -1553,6 +1559,36 @@ CINDEX_LINKAGE CXTUResourceUsage clang_g
 CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
 
 /**
+ * \brief Get target information for this translation unit.
+ *
+ * The CXTargetInfo object cannot outlive the CXTranslationUnit object.
+ */
+CINDEX_LINKAGE CXTargetInfo
+clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit);
+
+/**
+ * \brief Destroy the CXTargetInfo object.
+ */
+CINDEX_LINKAGE void
+clang_TargetInfo_dispose(CXTargetInfo Info);
+
+/**
+ * \brief Get the normalized target triple as a string.
+ *
+ * Returns the empty string in case of any error.
+ */
+CINDEX_LINKAGE CXString
+clang_TargetInfo_getTriple(CXTargetInfo Info);
+
+/**
+ * \brief Get the pointer width of the target in bits.
+ *
+ * Returns -1 in case of error.
+ */
+CINDEX_LINKAGE int
+clang_TargetInfo_getPointerWidth(CXTargetInfo Info);
+
+/**
  * @}
  */
 

Added: cfe/trunk/test/Index/target-info.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/target-info.c?rev=301648&view=auto
==
--- cfe/trunk/test/Index/target-info.c (added)
+++ cfe/trunk/test/Index/target-info.c Fri Apr 28 10:56:39 2017
@@ -0,0 +1,6 @@
+// RUN: c-index-test -test-print-target-info %s 
--target=i386-unknown-linux-gnu | FileCheck %s
+// RUN: c-index-test -test-print-target-info %s 
--target=x86_64-unknown-linux-gnu | FileCheck --check-prefix=CHECK-1 %s
+// CHECK: TargetTriple: i386-unknown-linux-gnu
+// CHECK: PointerWidth: 32
+// CHECK-1: TargetTriple: x86_64-unknown-linux-gnu
+// CHECK-1: PointerWidth: 64

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=301648&r1=301647&r2=301648&view=diff
==
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Fri Apr 28 10:56:39 2017
@@ -1560,6 +1560,51 @@ static enum CXChildVisitResult PrintType
 }
 
 
/**/
+/* Target information testing.
*/
+/**/
+
+static int print_target_info(int argc, const char **argv) {
+  CXIndex Idx;
+  CXTranslationUnit TU;
+  CXTargetInfo TargetInfo;
+  CXString Triple;
+  const char *FileName;
+  enum CXErrorCode Err;
+  int PointerWidth;
+
+  if (argc == 0) {
+fprintf(stderr, "No filename specified\n");
+return 1;
+  }
+
+  FileName = argv[1];
+
+  Idx = clang_createIndex(0, 1);
+  Err = clang_parseTranslationUnit2(Idx, FileName, argv, argc, NULL, 0,
+getDefaultParsingOptions(), &TU);
+  if (Err != CXError_Success) {
+fprintf(stderr, "Couldn't parse translation unit!\n");
+describeLibclangFailure(Err);
+clang_disposeIndex(Idx);
+return 1;
+  }
+
+  TargetInfo = clang_getTranslationUnitTargetInfo(TU);
+
+  Triple = clang_TargetInfo_getTriple(TargetInfo);
+  printf("TargetTriple: %s\n", clang_getCString(Triple));

[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-28 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301648: [libclang] Expose some target information via the C 
API. (authored by emilio).

Changed prior to commit:
  https://reviews.llvm.org/D32389?vs=96834&id=97109#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32389

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/test/Index/target-info.c
  cfe/trunk/tools/c-index-test/c-index-test.c
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/tools/libclang/CXTranslationUnit.h
  cfe/trunk/tools/libclang/libclang.exports

Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -26,6 +26,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticCategories.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -4018,6 +4019,50 @@
   return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
 }
 
+CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) {
+  if (isNotUsableTU(CTUnit)) {
+LOG_BAD_TU(CTUnit);
+return nullptr;
+  }
+
+  CXTargetInfoImpl* impl = new CXTargetInfoImpl();
+  impl->TranslationUnit = CTUnit;
+  return impl;
+}
+
+CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return cxstring::createEmpty();
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit) &&
+ "Unexpected unusable translation unit in TargetInfo");
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  std::string Triple =
+CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
+  return cxstring::createDup(Triple);
+}
+
+int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return -1;
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit) &&
+ "Unexpected unusable translation unit in TargetInfo");
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
+}
+
+void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return;
+
+  delete TargetInfo;
+}
+
 //===--===//
 // CXFile Operations.
 //===--===//
Index: cfe/trunk/tools/libclang/CXTranslationUnit.h
===
--- cfe/trunk/tools/libclang/CXTranslationUnit.h
+++ cfe/trunk/tools/libclang/CXTranslationUnit.h
@@ -35,6 +35,10 @@
   clang::index::CommentToXMLConverter *CommentToXML;
 };
 
+struct CXTargetInfoImpl {
+  CXTranslationUnit TranslationUnit;
+};
+
 namespace clang {
 namespace cxtu {
 
Index: cfe/trunk/tools/libclang/libclang.exports
===
--- cfe/trunk/tools/libclang/libclang.exports
+++ cfe/trunk/tools/libclang/libclang.exports
@@ -79,6 +79,9 @@
 clang_TParamCommandComment_isParamPositionValid
 clang_TParamCommandComment_getDepth
 clang_TParamCommandComment_getIndex
+clang_TargetInfo_dispose
+clang_TargetInfo_getPointerWidth
+clang_TargetInfo_getTriple
 clang_Type_getAlignOf
 clang_Type_getClassType
 clang_Type_getSizeOf
@@ -250,6 +253,7 @@
 clang_getTokenSpelling
 clang_getTranslationUnitCursor
 clang_getTranslationUnitSpelling
+clang_getTranslationUnitTargetInfo
 clang_getTypeDeclaration
 clang_getTypeKindSpelling
 clang_getTypeSpelling
Index: cfe/trunk/tools/c-index-test/c-index-test.c
===
--- cfe/trunk/tools/c-index-test/c-index-test.c
+++ cfe/trunk/tools/c-index-test/c-index-test.c
@@ -1560,6 +1560,51 @@
 }
 
 /**/
+/* Target information testing.*/
+/**/
+
+static int print_target_info(int argc, const char **argv) {
+  CXIndex Idx;
+  CXTranslationUnit TU;
+  CXTargetInfo TargetInfo;
+  CXString Triple;
+  const char *FileName;
+  enum CXErrorCode Err;
+  int PointerWidth;
+
+  if (argc == 0) {
+fprintf(stderr, "No filename specified\n");
+return 1;
+  }
+
+  FileName = argv[1];
+
+  Idx = clang_createIndex(0, 1);
+  Err = clang_parseTranslationUnit2(Idx, FileName, argv, argc, NULL, 0,
+getDefaultParsingOptions(), &TU);
+  if (Err != CXError_Success) {
+fprintf(stderr, "Couldn't parse translation unit!\n");
+describeLibclangFailure(Err);
+clang_disposeIndex(Idx);
+return 1;
+  }
+
+  TargetInfo = clang_getTranslationUnitTargetInfo(TU);
+
+  Tri

[clang-tools-extra] r301651 - [clang-tidy] modernize-use-emplace: remove unnecessary make_pair calls

2017-04-28 Thread Jakub Kuderski via cfe-commits
Author: kuhar
Date: Fri Apr 28 11:25:45 2017
New Revision: 301651

URL: http://llvm.org/viewvc/llvm-project?rev=301651&view=rev
Log:
[clang-tidy] modernize-use-emplace: remove unnecessary make_pair calls

Summary:
When there is a push_back with a call to make_pair, turn it into emplace_back 
and remove the unnecessary make_pair call.

Eg.

```
std::vector> v;
v.push_back(std::make_pair(1, 2)); // --> v.emplace_back(1, 2);
```

make_pair doesn't get removed when explicit template parameters are provided, 
because of potential problems with type conversions.

Reviewers: Prazek, aaron.ballman, hokein, alexfh

Reviewed By: Prazek, alexfh

Subscribers: JDevlieghere, JonasToth, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-use-emplace.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp?rev=301651&r1=301650&r2=301651&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp Fri Apr 28 
11:25:45 2017
@@ -15,10 +15,16 @@ namespace clang {
 namespace tidy {
 namespace modernize {
 
-static const auto DefaultContainersWithPushBack =
+namespace {
+AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) {
+  return Node.hasExplicitTemplateArgs();
+}
+
+const auto DefaultContainersWithPushBack =
 "::std::vector; ::std::list; ::std::deque";
-static const auto DefaultSmartPointers =
+const auto DefaultSmartPointers =
 "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
+} // namespace
 
 UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -39,7 +45,6 @@ void UseEmplaceCheck::registerMatchers(M
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  // + match for make_pair calls.
   auto callPushBack = cxxMemberCallExpr(
   hasDeclaration(functionDecl(hasName("push_back"))),
   on(hasType(cxxRecordDecl(hasAnyName(SmallVector(
@@ -80,10 +85,23 @@ void UseEmplaceCheck::registerMatchers(M
   .bind("ctor");
   auto hasConstructExpr = has(ignoringImplicit(soughtConstructExpr));
 
-  auto ctorAsArgument = materializeTemporaryExpr(
-  anyOf(hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
+  auto makePair = ignoringImplicit(
+  callExpr(callee(expr(ignoringImplicit(
+  declRefExpr(unless(hasExplicitTemplateArgs()),
+  to(functionDecl(hasName("::std::make_pair"
+  .bind("make_pair"));
+
+  // make_pair can return type convertible to container's element type.
+  // Allow the conversion only on containers of pairs.
+  auto makePairCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(makePair)),
+  hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
+
+  auto soughtParam = materializeTemporaryExpr(
+  anyOf(has(makePair), has(makePairCtor),
+hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
 
-  Finder->addMatcher(cxxMemberCallExpr(callPushBack, has(ctorAsArgument),
+  Finder->addMatcher(cxxMemberCallExpr(callPushBack, has(soughtParam),
unless(isInTemplateInstantiation()))
  .bind("call"),
  this);
@@ -92,8 +110,10 @@ void UseEmplaceCheck::registerMatchers(M
 void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Call = Result.Nodes.getNodeAs("call");
   const auto *InnerCtorCall = Result.Nodes.getNodeAs("ctor");
+  const auto *MakePairCall = Result.Nodes.getNodeAs("make_pair");
+  assert((InnerCtorCall || MakePairCall) && "No push_back parameter matched");
 
-  auto FunctionNameSourceRange = CharSourceRange::getCharRange(
+  const auto FunctionNameSourceRange = CharSourceRange::getCharRange(
   Call->getExprLoc(), Call->getArg(0)->getExprLoc());
 
   auto Diag = diag(Call->getExprLoc(), "use emplace_back instead of 
push_back");
@@ -101,22 +121,28 @@ void UseEmplaceCheck::check(const MatchF
   if (FunctionNameSourceRange.getBegin().isMacroID())
 return;
 
-  Diag << FixItHint::CreateReplacement(FunctionNameSourceRange,
-   "emplace_back(");
+  const auto *EmplacePrefix = MakePairCall ? "emplace_back" : "emplace_back(";
+  Diag << FixItHint::CreateReplacement(FunctionNameSourceRange, EmplacePrefix);
 
-  auto Cal

[PATCH] D32395: [clang-tidy] modernize-use-emplace: remove unnecessary make_pair calls

2017-04-28 Thread Jakub Kuderski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301651: [clang-tidy] modernize-use-emplace: remove 
unnecessary make_pair calls (authored by kuhar).

Changed prior to commit:
  https://reviews.llvm.org/D32395?vs=96634&id=97113#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32395

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-emplace.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -15,10 +15,16 @@
 namespace tidy {
 namespace modernize {
 
-static const auto DefaultContainersWithPushBack =
+namespace {
+AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) {
+  return Node.hasExplicitTemplateArgs();
+}
+
+const auto DefaultContainersWithPushBack =
 "::std::vector; ::std::list; ::std::deque";
-static const auto DefaultSmartPointers =
+const auto DefaultSmartPointers =
 "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
+} // namespace
 
 UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -39,7 +45,6 @@
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  // + match for make_pair calls.
   auto callPushBack = cxxMemberCallExpr(
   hasDeclaration(functionDecl(hasName("push_back"))),
   on(hasType(cxxRecordDecl(hasAnyName(SmallVector(
@@ -80,43 +85,64 @@
   .bind("ctor");
   auto hasConstructExpr = has(ignoringImplicit(soughtConstructExpr));
 
-  auto ctorAsArgument = materializeTemporaryExpr(
-  anyOf(hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
+  auto makePair = ignoringImplicit(
+  callExpr(callee(expr(ignoringImplicit(
+  declRefExpr(unless(hasExplicitTemplateArgs()),
+  to(functionDecl(hasName("::std::make_pair"
+  .bind("make_pair"));
+
+  // make_pair can return type convertible to container's element type.
+  // Allow the conversion only on containers of pairs.
+  auto makePairCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(makePair)),
+  hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
+
+  auto soughtParam = materializeTemporaryExpr(
+  anyOf(has(makePair), has(makePairCtor),
+hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
 
-  Finder->addMatcher(cxxMemberCallExpr(callPushBack, has(ctorAsArgument),
+  Finder->addMatcher(cxxMemberCallExpr(callPushBack, has(soughtParam),
unless(isInTemplateInstantiation()))
  .bind("call"),
  this);
 }
 
 void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Call = Result.Nodes.getNodeAs("call");
   const auto *InnerCtorCall = Result.Nodes.getNodeAs("ctor");
+  const auto *MakePairCall = Result.Nodes.getNodeAs("make_pair");
+  assert((InnerCtorCall || MakePairCall) && "No push_back parameter matched");
 
-  auto FunctionNameSourceRange = CharSourceRange::getCharRange(
+  const auto FunctionNameSourceRange = CharSourceRange::getCharRange(
   Call->getExprLoc(), Call->getArg(0)->getExprLoc());
 
   auto Diag = diag(Call->getExprLoc(), "use emplace_back instead of push_back");
 
   if (FunctionNameSourceRange.getBegin().isMacroID())
 return;
 
-  Diag << FixItHint::CreateReplacement(FunctionNameSourceRange,
-   "emplace_back(");
+  const auto *EmplacePrefix = MakePairCall ? "emplace_back" : "emplace_back(";
+  Diag << FixItHint::CreateReplacement(FunctionNameSourceRange, EmplacePrefix);
 
-  auto CallParensRange = InnerCtorCall->getParenOrBraceRange();
+  const SourceRange CallParensRange =
+  MakePairCall ? SourceRange(MakePairCall->getCallee()->getLocEnd(),
+ MakePairCall->getRParenLoc())
+   : InnerCtorCall->getParenOrBraceRange();
 
   // Finish if there is no explicit constructor call.
   if (CallParensRange.getBegin().isInvalid())
 return;
 
+  const SourceLocation ExprBegin =
+  MakePairCall ? MakePairCall->getExprLoc() : InnerCtorCall->getExprLoc();
+
   // Range for constructor name and opening brace.
-  auto CtorCallSourceRange = CharSourceRange::getTokenRange(
-  InnerCtorCall->getExprLoc(), CallParensRange.getBegin());
+  const auto ParamCallSourceRange =
+  CharSourceRange::getTokenRange(ExprBegin, CallParensRange.getBegin());
 
-  Diag << FixItHint::CreateRemoval(CtorCallSo

r301652 - [DOXYGEN] Minor improvements in doxygen comments.

2017-04-28 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Fri Apr 28 11:45:39 2017
New Revision: 301652

URL: http://llvm.org/viewvc/llvm-project?rev=301652&view=rev
Log:
[DOXYGEN] Minor improvements in doxygen comments.

- I removed doxygen comments for the intrinsics that "alias" the other existing 
documented intrinsics and that only sligtly differ in spelling (single 
underscores vs. double underscores). 
 #define _tzcnt_u16(a) (__tzcnt_u16((a)))

It will be very hard to keep the documentation for these "aliases" in sync with 
the documentation for the intrinsics they alias to. Out of sync documentation 
will be more confusing than no documentation.

I got an OK from Eric Christopher to commit doxygen comments without prior code
review upstream.


Modified:
cfe/trunk/lib/Headers/bmiintrin.h

Modified: cfe/trunk/lib/Headers/bmiintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/bmiintrin.h?rev=301652&r1=301651&r2=301652&view=diff
==
--- cfe/trunk/lib/Headers/bmiintrin.h (original)
+++ cfe/trunk/lib/Headers/bmiintrin.h Fri Apr 28 11:45:39 2017
@@ -28,107 +28,17 @@
 #ifndef __BMIINTRIN_H
 #define __BMIINTRIN_H
 
-/// \brief Counts the number of trailing zero bits in the operand.
-///
-/// \headerfile 
-///
-/// \code
-/// unsigned short _tzcnt_u16(unsigned short a);
-/// \endcode
-///
-/// This intrinsic corresponds to the  TZCNT  instruction.
-///
-/// \param a
-///An unsigned 16-bit integer whose trailing zeros are to be counted.
-/// \returns An unsigned 16-bit integer containing the number of trailing zero
-///bits in the operand.
 #define _tzcnt_u16(a) (__tzcnt_u16((a)))
 
-/// \brief Performs a bitwise AND of the second operand with the one's
-///complement of the first operand.
-///
-/// \headerfile 
-///
-/// \code
-/// unsigned int _andn_u32(unsigned int a, unsigned int b);
-/// \endcode
-///
-/// This intrinsic corresponds to the  ANDN  instruction.
-///
-/// \param a
-///An unsigned integer containing one of the operands.
-/// \param b
-///An unsigned integer containing one of the operands.
-/// \returns An unsigned integer containing the bitwise AND of the second
-///operand with the one's complement of the first operand.
 #define _andn_u32(a, b)   (__andn_u32((a), (b)))
 
 /* _bextr_u32 != __bextr_u32 */
-/// \brief Clears all bits in the source except for the least significant bit
-///containing a value of 1 and returns the result.
-///
-/// \headerfile 
-///
-/// \code
-/// unsigned int _blsi_u32(unsigned int a);
-/// \endcode
-///
-/// This intrinsic corresponds to the  BLSI  instruction.
-///
-/// \param a
-///An unsigned integer whose bits are to be cleared.
-/// \returns An unsigned integer containing the result of clearing the bits 
from
-///the source operand.
 #define _blsi_u32(a)  (__blsi_u32((a)))
 
-/// \brief Creates a mask whose bits are set to 1, using bit 0 up to and
-///including the least siginificant bit that is set to 1 in the source
-///operand and returns the result.
-///
-/// \headerfile 
-///
-/// \code
-/// unsigned int _blsmsk_u32(unsigned int a);
-/// \endcode
-///
-/// This intrinsic corresponds to the  BLSMSK  instruction.
-///
-/// \param a
-///An unsigned integer used to create the mask.
-/// \returns An unsigned integer containing the newly created mask.
 #define _blsmsk_u32(a)(__blsmsk_u32((a)))
 
-/// \brief Clears the least siginificant bit that is set to 1 in the source
-///operand and returns the result.
-///
-/// \headerfile 
-///
-/// \code
-/// unsigned int _blsr_u32(unsigned int a);
-/// \endcode
-///
-/// This intrinsic corresponds to the  BLSR  instruction.
-///
-/// \param a
-///An unsigned integer containing the operand to be cleared.
-/// \returns An unsigned integer containing the result of clearing the source
-///operand.
 #define _blsr_u32(a)  (__blsr_u32((a)))
 
-/// \brief Counts the number of trailing zero bits in the operand.
-///
-/// \headerfile 
-///
-/// \code
-/// unsigned int _tzcnt_u32(unsigned int a);
-/// \endcode
-///
-/// This intrinsic corresponds to the  TZCNT  instruction.
-///
-/// \param a
-///An unsigned 32-bit integer whose trailing zeros are to be counted.
-/// \returns An unsigned 32-bit integer containing the number of trailing zero
-///bits in the operand.
 #define _tzcnt_u32(a) (__tzcnt_u32((a)))
 
 /* Define the default attributes for the functions in this file. */
@@ -305,91 +215,15 @@ _mm_tzcnt_32(unsigned int __X)
 
 #ifdef __x86_64__
 
-/// \brief Performs a bitwise AND of the second operand with the one's
-///complement of the first operand.
-///
-/// \headerfile 
-///
-/// \code
-/// unsigned long long _andn_u64 (unsigned long long a, unsigned long long b);
-/// \endcode
-///
-/// This intrinsic corresponds to the  ANDN  instruction.
-///
-/// \param a
-///An unsigned 64-bit integer containing one of the operands.
-/// \param b
-///An unsigned

[PATCH] D32372: Arrays of unknown bound in constant expressions

2017-04-28 Thread Robert Haberlach via Phabricator via cfe-commits
Arcoth updated this revision to Diff 97114.
Arcoth added a comment.

Simplified array-to-pointer conversion (simply add the array as unsized; let 
findCompleteObject and the SubobjectDesignator ctor do the work).


https://reviews.llvm.org/D32372

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/SemaCXX/constexpr-array-unknown-bound.cpp

Index: test/SemaCXX/constexpr-array-unknown-bound.cpp
===
--- /dev/null
+++ test/SemaCXX/constexpr-array-unknown-bound.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++1z -fsyntax-only -verify
+
+const extern int arr[];
+constexpr auto p = arr; // ok
+constexpr int f(int i) {return p[i];} // expected-note {{read of dereferenced one-past-the-end pointer}}
+
+constexpr int arr[] {1, 2, 3};
+constexpr auto p2 = arr + 2; // ok
+constexpr int x = f(2); // ok
+constexpr int y = f(3); // expected-error {{constant expression}}
+// expected-note-re@-1 {{in call to 'f({{.*}})'}}
+
+struct A {int m[];} a;
+constexpr auto p3 = a.m; // ok
+constexpr auto p4 = a.m + 1; // expected-error {{constant expression}} expected-note {{constant bound}}
+
+void g(int i) {
+  int arr[i];
+  constexpr auto p = arr + 2; // expected-error {{constant expression}} expected-note {{constant bound}}
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -148,22 +148,26 @@
   static unsigned
   findMostDerivedSubobject(ASTContext &Ctx, APValue::LValueBase Base,
ArrayRef Path,
-   uint64_t &ArraySize, QualType &Type, bool &IsArray) {
+   uint64_t &ArraySize, QualType &Type, bool &IsArray,
+   bool &isUnsizedArray) {
 // This only accepts LValueBases from APValues, and APValues don't support
 // arrays that lack size info.
 assert(!isBaseAnAllocSizeCall(Base) &&
"Unsized arrays shouldn't appear here");
 unsigned MostDerivedLength = 0;
 Type = getType(Base);
 
 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
-  if (Type->isArrayType()) {
-const ConstantArrayType *CAT =
-cast(Ctx.getAsArrayType(Type));
-Type = CAT->getElementType();
-ArraySize = CAT->getSize().getZExtValue();
+  if (auto AT = Ctx.getAsArrayType(Type)) {
 MostDerivedLength = I + 1;
 IsArray = true;
+if (auto CAT = Ctx.getAsConstantArrayType(Type))
+  ArraySize = CAT->getSize().getZExtValue();
+else {
+  ArraySize = 0;
+  isUnsizedArray = true;
+}
+Type = AT->getElementType();
   } else if (Type->isAnyComplexType()) {
 const ComplexType *CT = Type->castAs();
 Type = CT->getElementType();
@@ -200,8 +204,9 @@
 /// Is this a pointer one past the end of an object?
 unsigned IsOnePastTheEnd : 1;
 
-/// Indicator of whether the first entry is an unsized array.
-unsigned FirstEntryIsAnUnsizedArray : 1;
+/// Indicator of whether the most-derived object is an unsized array (e.g.
+/// of unknown bound).
+unsigned MostDerivedIsAnUnsizedArray : 1;
 
 /// Indicator of whether the most-derived object is an array element.
 unsigned MostDerivedIsArrayElement : 1;
@@ -231,25 +236,28 @@
 
 explicit SubobjectDesignator(QualType T)
 : Invalid(false), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0),
   MostDerivedType(T) {}
 
 SubobjectDesignator(ASTContext &Ctx, const APValue &V)
 : Invalid(!V.isLValue() || !V.hasLValuePath()), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0) {
   assert(V.isLValue() && "Non-LValue used to make an LValue designator?");
   if (!Invalid) {
 IsOnePastTheEnd = V.isLValueOnePastTheEnd();
 ArrayRef VEntries = V.getLValuePath();
 Entries.insert(Entries.end(), VEntries.begin(), VEntries.end());
-if (V.getLValueBase()) {
-  bool IsArray = false;
+if (auto Base = V.getLValueBase()) {
+  if (auto Decl = Base.dyn_cast())
+Base = cast(Decl->getMostRecentDecl());
+  bool IsArray = false, IsUnsizedArray = false;
   MostDerivedPathLength = findMostDerivedSubobject(
-  Ctx, V.getLValueBase(), V.getLValuePath(), MostDerivedArraySize,
-  MostDerivedType, IsArray);
-  MostDerivedIsArrayElement = IsArray;
+  Ctx, Base, V.getLValuePath(), MostDerivedArraySize,
+   

[PATCH] D32372: Arrays of unknown bound in constant expressions

2017-04-28 Thread Robert Haberlach via Phabricator via cfe-commits
Arcoth updated this revision to Diff 97116.
Arcoth added a comment.

(Just fixed a slip after typing with the wrong window in focus...)


https://reviews.llvm.org/D32372

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/SemaCXX/constexpr-array-unknown-bound.cpp

Index: test/SemaCXX/constexpr-array-unknown-bound.cpp
===
--- /dev/null
+++ test/SemaCXX/constexpr-array-unknown-bound.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++1z -fsyntax-only -verify
+
+const extern int arr[];
+constexpr auto p = arr; // ok
+constexpr int f(int i) {return p[i];} // expected-note {{read of dereferenced one-past-the-end pointer}}
+
+constexpr int arr[] {1, 2, 3};
+constexpr auto p2 = arr + 2; // ok
+constexpr int x = f(2); // ok
+constexpr int y = f(3); // expected-error {{constant expression}}
+// expected-note-re@-1 {{in call to 'f({{.*}})'}}
+
+struct A {int m[];} a;
+constexpr auto p3 = a.m; // ok
+constexpr auto p4 = a.m + 1; // expected-error {{constant expression}} expected-note {{constant bound}}
+
+void g(int i) {
+  int arr[i];
+  constexpr auto p = arr + 2; // expected-error {{constant expression}} expected-note {{constant bound}}
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -148,22 +148,26 @@
   static unsigned
   findMostDerivedSubobject(ASTContext &Ctx, APValue::LValueBase Base,
ArrayRef Path,
-   uint64_t &ArraySize, QualType &Type, bool &IsArray) {
+   uint64_t &ArraySize, QualType &Type, bool &IsArray,
+   bool &isUnsizedArray) {
 // This only accepts LValueBases from APValues, and APValues don't support
 // arrays that lack size info.
 assert(!isBaseAnAllocSizeCall(Base) &&
"Unsized arrays shouldn't appear here");
 unsigned MostDerivedLength = 0;
 Type = getType(Base);
 
 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
-  if (Type->isArrayType()) {
-const ConstantArrayType *CAT =
-cast(Ctx.getAsArrayType(Type));
-Type = CAT->getElementType();
-ArraySize = CAT->getSize().getZExtValue();
+  if (auto AT = Ctx.getAsArrayType(Type)) {
 MostDerivedLength = I + 1;
 IsArray = true;
+if (auto CAT = Ctx.getAsConstantArrayType(Type))
+  ArraySize = CAT->getSize().getZExtValue();
+else {
+  ArraySize = 0;
+  isUnsizedArray = true;
+}
+Type = AT->getElementType();
   } else if (Type->isAnyComplexType()) {
 const ComplexType *CT = Type->castAs();
 Type = CT->getElementType();
@@ -200,8 +204,9 @@
 /// Is this a pointer one past the end of an object?
 unsigned IsOnePastTheEnd : 1;
 
-/// Indicator of whether the first entry is an unsized array.
-unsigned FirstEntryIsAnUnsizedArray : 1;
+/// Indicator of whether the most-derived object is an unsized array (e.g.
+/// of unknown bound).
+unsigned MostDerivedIsAnUnsizedArray : 1;
 
 /// Indicator of whether the most-derived object is an array element.
 unsigned MostDerivedIsArrayElement : 1;
@@ -231,25 +236,28 @@
 
 explicit SubobjectDesignator(QualType T)
 : Invalid(false), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0),
   MostDerivedType(T) {}
 
 SubobjectDesignator(ASTContext &Ctx, const APValue &V)
 : Invalid(!V.isLValue() || !V.hasLValuePath()), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0) {
   assert(V.isLValue() && "Non-LValue used to make an LValue designator?");
   if (!Invalid) {
 IsOnePastTheEnd = V.isLValueOnePastTheEnd();
 ArrayRef VEntries = V.getLValuePath();
 Entries.insert(Entries.end(), VEntries.begin(), VEntries.end());
-if (V.getLValueBase()) {
-  bool IsArray = false;
+if (auto Base = V.getLValueBase()) {
+  if (auto Decl = Base.dyn_cast())
+Base = cast(Decl->getMostRecentDecl());
+  bool IsArray = false, IsUnsizedArray = false;
   MostDerivedPathLength = findMostDerivedSubobject(
-  Ctx, V.getLValueBase(), V.getLValuePath(), MostDerivedArraySize,
-  MostDerivedType, IsArray);
-  MostDerivedIsArrayElement = IsArray;
+  Ctx, Base, V.getLValuePath(), MostDerivedArraySize,
+  MostDerivedType, IsArray, IsUnsizedArray);
+  MostDerivedI

[PATCH] D32550: Supress all uses of LLVM_END_WITH_NULL

2017-04-28 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a subscriber: mehdi_amini.
serge-sans-paille added a comment.

@mehdi_amini  are you okay with my previous explanation?


https://reviews.llvm.org/D32550



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


[PATCH] D32601: [CodeGen][ObjC] Don't retain/release capture objects at block creation that are const-qualified

2017-04-28 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301667: [CodeGen][ObjC] Don't retain captured Objective-C 
pointers at block (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D32601?vs=96940&id=97136#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32601

Files:
  cfe/trunk/lib/CodeGen/CGBlocks.cpp
  cfe/trunk/lib/CodeGen/CGObjC.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGenObjC/arc-blocks.m
  cfe/trunk/test/CodeGenObjC/arc-foreach.m

Index: cfe/trunk/test/CodeGenObjC/arc-blocks.m
===
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m
@@ -298,15 +298,11 @@
 // CHECK:  [[D0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
 // CHECK:  [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
 // CHECK-NEXT: [[T1:%.*]] = load [[TEST8]]*, [[TEST8]]** [[SELF]],
-// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST8]]* [[T1]] to i8*
-// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]])
-// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST8]]*
-// CHECK-NEXT: store [[TEST8]]* [[T4]], [[TEST8]]** [[T0]]
+// CHECK-NEXT: store %0* [[T1]], %0** [[T0]]
 // CHECK-NEXT: bitcast [[BLOCK_T]]* [[BLOCK]] to
 // CHECK: call void @test8_helper(
-// CHECK-NEXT: [[T1:%.*]] = load [[TEST8]]*, [[TEST8]]** [[D0]]
-// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST8]]* [[T1]] to i8*
-// CHECK-NEXT: call void @objc_release(i8* [[T2]])
+// CHECK-NEXT: [[T2:%.*]] = load [[TEST8]]*, [[TEST8]]** [[D0]]
+// CHECK-NEXT: call void (...) @clang.arc.use([[TEST8]]* [[T2]])
 // CHECK: ret void
 
   extern void test8_helper(void (^)(void));
@@ -741,5 +737,31 @@
 // CHECK-NEXT: ret void
 }
 
+// CHECK-LABEL: define void @test20(
+// CHECK: [[XADDR:%.*]] = alloca i8*
+// CHECK-NEXT: [[BLOCK:%.*]] = alloca <[[BLOCKTY:.*]]>
+// CHECK-NEXT: [[RETAINEDX:%.*]] = call i8* @objc_retain(i8* %{{.*}})
+// CHECK-NEXT: store i8* [[RETAINEDX]], i8** [[XADDR]]
+// CHECK-NEXT: [[CAPTUREFIELD:%.*]] = getelementptr inbounds <[[BLOCKTY]]>, <[[BLOCKTY]]>* [[BLOCK]], i32 0, i32 5
+// CHECK: [[BLOCKCAPTURED:%.*]] = getelementptr inbounds <[[BLOCKTY]]>, <[[BLOCKTY]]>* [[BLOCK]], i32 0, i32 5
+// CHECK: [[CAPTURED:%.*]] = load i8*, i8** [[XADDR]]
+// CHECK: store i8* [[CAPTURED]], i8** [[BLOCKCAPTURED]]
+// CHECK: [[CAPTURE:%.*]] = load i8*, i8** [[CAPTUREFIELD]]
+// CHECK-NEXT: call void (...) @clang.arc.use(i8* [[CAPTURE]])
+// CHECK-NEXT: [[X:%.*]] = load i8*, i8** [[XADDR]]
+// CHECK-NEXT: call void @objc_release(i8* [[X]])
+// CHECK-NEXT: ret void
+
+// CHECK-LABEL: define internal void @__copy_helper_block
+// CHECK: [[BLOCKSOURCE:%.*]] = bitcast i8* %{{.*}} to <[[BLOCKTY]]>*
+// CHECK: [[CAPTUREFIELD:%.*]] = getelementptr inbounds <[[BLOCKTY]]>, <[[BLOCKTY]]>* [[BLOCKSOURCE]], i32 0, i32 5
+// CHECK: [[BLOCKCOPYSRC:%.*]] = load i8*, i8** [[CAPTUREFIELD]]
+// CHECK: call i8* @objc_retain(i8* [[BLOCKCOPYSRC]])
+
+void test20_callee(void (^)());
+void test20(const id x) {
+  test20_callee(^{ (void)x; });
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: cfe/trunk/test/CodeGenObjC/arc-foreach.m
===
--- cfe/trunk/test/CodeGenObjC/arc-foreach.m
+++ cfe/trunk/test/CodeGenObjC/arc-foreach.m
@@ -63,11 +63,11 @@
 // CHECK-LP64:  [[D0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
 // CHECK-LP64:  [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
 // CHECK-LP64-NEXT: [[T1:%.*]] = load i8*, i8** [[X]]
-// CHECK-LP64-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
-// CHECK-LP64-NEXT: store i8* [[T2]], i8** [[T0]]
-// CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] 
-// CHECK-LP64: call void @use_block(
-// CHECK-LP64-NEXT: call void @objc_storeStrong(i8** [[D0]], i8* null)
+// CHECK-LP64-NEXT: store i8* [[T1]], i8** [[T0]]
+// CHECK-LP64-NEXT: [[BLOCK1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]]
+// CHECK-LP64-NEXT: call void @use_block(void ()* [[BLOCK1]])
+// CHECK-LP64-NEXT: [[CAPTURE:%.*]] = load i8*, i8** [[D0]]
+// CHECK-LP64: call void (...) @clang.arc.use(i8* [[CAPTURE]])
 
 // CHECK-LP64:  [[T0:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_
 // CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[ARRAY_T]]* [[SAVED_ARRAY]] to i8*
@@ -200,13 +200,10 @@
 // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5
 // CHECK-LP64: [[BC:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5
 // CHECK-LP64: [[T1:%.*]] 

r301667 - [CodeGen][ObjC] Don't retain captured Objective-C pointers at block

2017-04-28 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Apr 28 13:50:57 2017
New Revision: 301667

URL: http://llvm.org/viewvc/llvm-project?rev=301667&view=rev
Log:
[CodeGen][ObjC] Don't retain captured Objective-C pointers at block
creation that are const-qualified.

When a block captures an ObjC object pointer, clang retains the pointer
to prevent prematurely destroying the object the pointer points to
before the block is called or copied.

When the captured object pointer is const-qualified, we can avoid
emitting the retain/release pair since the pointer variable cannot be
modified in the scope in which the block literal is introduced.

For example:

void test(const id x) {
callee(^{ (void)x; });
}

This patch implements that optimization.

rdar://problem/28894510

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenObjC/arc-blocks.m
cfe/trunk/test/CodeGenObjC/arc-foreach.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=301667&r1=301666&r2=301667&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Apr 28 13:50:57 2017
@@ -619,7 +619,13 @@ static void enterBlockScope(CodeGenFunct
 
 // Block captures count as local values and have imprecise semantics.
 // They also can't be arrays, so need to worry about that.
-if (dtorKind == QualType::DK_objc_strong_lifetime) {
+//
+// For const-qualified captures, emit clang.arc.use to ensure the captured
+// object doesn't get released while we are still depending on its validity
+// within the block.
+if (VT.isConstQualified() && VT.getObjCLifetime() == 
Qualifiers::OCL_Strong)
+  destroyer = CodeGenFunction::emitARCIntrinsicUse;
+else if (dtorKind == QualType::DK_objc_strong_lifetime) {
   destroyer = CodeGenFunction::destroyARCStrongImprecise;
 } else {
   destroyer = CGF.getDestroyer(dtorKind);
@@ -866,6 +872,12 @@ llvm::Value *CodeGenFunction::EmitBlockL
 } else if (type->isReferenceType()) {
   Builder.CreateStore(src.getPointer(), blockField);
 
+// If type is const-qualified, copy the value into the block field.
+} else if (type.isConstQualified() &&
+   type.getObjCLifetime() == Qualifiers::OCL_Strong) {
+  llvm::Value *value = Builder.CreateLoad(src, "captured");
+  Builder.CreateStore(value, blockField);
+
 // If this is an ARC __strong block-pointer variable, don't do a
 // block copy.
 //

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=301667&r1=301666&r2=301667&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri Apr 28 13:50:57 2017
@@ -2415,6 +2415,12 @@ void CodeGenFunction::destroyARCWeak(Cod
   CGF.EmitARCDestroyWeak(addr);
 }
 
+void CodeGenFunction::emitARCIntrinsicUse(CodeGenFunction &CGF, Address addr,
+  QualType type) {
+  llvm::Value *value = CGF.Builder.CreateLoad(addr);
+  CGF.EmitARCIntrinsicUse(value);
+}
+
 namespace {
   struct CallObjCAutoreleasePoolObject final : EHScopeStack::Cleanup {
 llvm::Value *Token;

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=301667&r1=301666&r2=301667&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Apr 28 13:50:57 2017
@@ -3369,6 +3369,7 @@ public:
   static Destroyer destroyARCStrongImprecise;
   static Destroyer destroyARCStrongPrecise;
   static Destroyer destroyARCWeak;
+  static Destroyer emitARCIntrinsicUse;
 
   void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr); 
   llvm::Value *EmitObjCAutoreleasePoolPush();

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=301667&r1=301666&r2=301667&view=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Fri Apr 28 13:50:57 2017
@@ -298,15 +298,11 @@ void test7(void) {
 // CHECK:  [[D0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* 
[[BLOCK]], i32 0, i32 5
 // CHECK:  [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* 
[[BLOCK]], i32 0, i32 5
 // CHECK-NEXT: [[T1:%.*]] = load [[TEST8]]*, [[TEST8]]** [[SELF]],
-// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST8]]* [[T1]] to i8*
-// CHECK-NEXT: [[T3:%.*]] = call i8* @ob

[PATCH] D31887: [clangd] Add documentation page

2017-04-28 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle-ericsson added a comment.

In https://reviews.llvm.org/D31887#740747, @Prazek wrote:

> In https://reviews.llvm.org/D31887#740727, @malaperle-ericsson wrote:
>
> > Would it be possible to commit this? I do not have commit rights. Thanks!
>
>
> Why won't you get commit right? You will probably make some other 
> contribution to clangd, so it will be handy to have it :)


I wasn't sure at what moment it was appropriate to ask for commit rights. I 
just sent the request for it :)


https://reviews.llvm.org/D31887



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


[PATCH] D32475: [clang-format] Don’t propagate AvoidBinPacking into argument subexpressions

2017-04-28 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes added a comment.

Friendly ping :)  happy to make more changes if needed. Thanks again for your 
time.


https://reviews.llvm.org/D32475



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


r301684 - Enable -fno-split-dwarf-inlining even when -gsplit-dwarf isn't specified.

2017-04-28 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Fri Apr 28 15:50:25 2017
New Revision: 301684

URL: http://llvm.org/viewvc/llvm-project?rev=301684&view=rev
Log:
Enable -fno-split-dwarf-inlining even when -gsplit-dwarf isn't specified.

Since -gsplit-dwarf is specified on a backend compile (in ThinLTO
parlance) it isn't passed during the frontend compile (because no ELF
object/dwo file is produced then), yet the -fno-split-dwarf-inlining
value needs to be encoded in the LLVM DebugInfo metadata to have
effect...

So let it be specified & it'll be silently ignored if -gsplit-dwarf
isn't used in the end, otherwise it'll be used on a per-cu basis
depending on where it's specified in the frontend compile actions.

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/split-debug.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=301684&r1=301683&r2=301684&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Apr 28 15:50:25 2017
@@ -2773,12 +2773,14 @@ void Clang::ConstructJob(Compilation &C,
   // -gsplit-dwarf should turn on -g and enable the backend dwarf
   // splitting and extraction.
   // FIXME: Currently only works on Linux.
-  if (getToolChain().getTriple().isOSLinux() && SplitDwarfArg) {
+  if (getToolChain().getTriple().isOSLinux()) {
 if (!splitDwarfInlining)
   CmdArgs.push_back("-fno-split-dwarf-inlining");
-if (DebugInfoKind == codegenoptions::NoDebugInfo)
-  DebugInfoKind = codegenoptions::LimitedDebugInfo;
-CmdArgs.push_back("-enable-split-dwarf");
+if (SplitDwarfArg) {
+  if (DebugInfoKind == codegenoptions::NoDebugInfo)
+DebugInfoKind = codegenoptions::LimitedDebugInfo;
+  CmdArgs.push_back("-enable-split-dwarf");
+}
   }
 
   // After we've dealt with all combinations of things that could

Modified: cfe/trunk/test/Driver/split-debug.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/split-debug.c?rev=301684&r1=301683&r2=301684&view=diff
==
--- cfe/trunk/test/Driver/split-debug.c (original)
+++ cfe/trunk/test/Driver/split-debug.c Fri Apr 28 15:50:25 2017
@@ -40,6 +40,13 @@
 // CHECK-GMLT-WITH-SPLIT: "-debug-info-kind=line-tables-only"
 // CHECK-GMLT-WITH-SPLIT: "-split-dwarf-file"
 
+// RUN: %clang -target x86_64-unknown-linux-gnu -g -fno-split-dwarf-inlining 
-S -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-NOINLINE-WITHOUT-SPLIT < %t %s
+//
+// CHECK-NOINLINE-WITHOUT-SPLIT-NOT: "-enable-split-dwarf"
+// CHECK-NOINLINE-WITHOUT-SPLIT: "-fno-split-dwarf-inlining"
+// CHECK-NOINLINE-WITHOUT-SPLIT: "-debug-info-kind=limited"
+
 // RUN: %clang -target x86_64-unknown-linux-gnu -gmlt -gsplit-dwarf 
-fno-split-dwarf-inlining -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-GMLT < %t %s
 //


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


[PATCH] D24999: [Sema] Only relax array-at-end-of-object checks in __builtin_object_size when -fno-strict-aliasing is given.

2017-04-28 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a dependency: D21453: Add support for attribute "overallocated".
ahatanak added a comment.

Depends on https://reviews.llvm.org/D21453.

Adding a dependency as a reminder to look into https://reviews.llvm.org/D21453 
before committing this patch.


https://reviews.llvm.org/D24999



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


r301701 - [ODRHash] Add testcase with different paramter names. NFC

2017-04-28 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Apr 28 17:03:28 2017
New Revision: 301701

URL: http://llvm.org/viewvc/llvm-project?rev=301701&view=rev
Log:
[ODRHash] Add testcase with different paramter names.  NFC

Modified:
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=301701&r1=301700&r2=301701&view=diff
==
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Fri Apr 28 17:03:28 2017
@@ -887,6 +887,52 @@ Bravo golf;
 #endif
 }
 
+namespace DifferentParameterNameInTemplate {
+#if defined(FIRST) || defined(SECOND)
+template 
+struct S {
+  typedef T Type;
+
+  static void Run(const Type *name_one);
+};
+
+template 
+void S::Run(const T *name_two) {}
+
+template 
+struct Foo {
+  ~Foo() { Handler::Run(nullptr); }
+  Foo() {}
+
+  class Handler : public S {};
+
+  void Get(typename Handler::Type *x = nullptr) {}
+  void Add() { Handler::Run(nullptr); }
+};
+#endif
+
+#if defined(FIRST)
+struct Beta;
+
+struct Alpha {
+  Alpha();
+  void Go() { betas.Get(); }
+  Foo betas;
+};
+
+#elif defined(SECOND)
+struct Beta {};
+
+struct BetaHelper {
+  void add_Beta() { betas.Add(); }
+  Foo betas;
+};
+
+#else
+Alpha::Alpha() {}
+#endif
+}
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST


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


r301707 - Adapt to LLVM API change (DINamespace no longer takes line/file info).

2017-04-28 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Fri Apr 28 17:25:53 2017
New Revision: 301707

URL: http://llvm.org/viewvc/llvm-project?rev=301707&view=rev
Log:
Adapt to LLVM API change (DINamespace no longer takes line/file info).

rdar://problem/17484998
https://reviews.llvm.org/D32648

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
cfe/trunk/test/Modules/ExtDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=301707&r1=301706&r2=301707&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 28 17:25:53 2017
@@ -4034,11 +4034,9 @@ CGDebugInfo::getOrCreateNameSpace(const
   if (I != NameSpaceCache.end())
 return cast(I->second);
 
-  unsigned LineNo = getLineNumber(NSDecl->getLocation());
-  llvm::DIFile *FileD = getOrCreateFile(NSDecl->getLocation());
   llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
-  llvm::DINamespace *NS = DBuilder.createNameSpace(
-  Context, NSDecl->getName(), FileD, LineNo, NSDecl->isInline());
+  llvm::DINamespace *NS =
+  DBuilder.createNameSpace(Context, NSDecl->getName(), NSDecl->isInline());
   NameSpaceCache[NSDecl].reset(NS);
   return NS;
 }

Modified: cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp?rev=301707&r1=301706&r2=301707&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp Fri Apr 28 17:25:53 2017
@@ -53,21 +53,27 @@ inline namespace I {
 int var_i;
 }
 }
-void B::func_fwd() {}
+namespace {
+int anonymous;
+}
+void B::func_fwd() {
+  anonymous = 0;
+}
+
 
 // This should work even if 'i' and 'func' were declarations & not definitions,
 // but it doesn't yet.
 
 // CHECK: [[I:![0-9]+]] = distinct !DIGlobalVariable(name: "i",{{.*}} scope: 
[[NS:![0-9]+]],
-// CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]], file: 
[[FOOCPP:![0-9]+]], line: 1)
-// CHECK: [[FOOCPP]] = !DIFile(filename: "foo.cpp"
-// CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null, file: 
[[FILE:![0-9]+]], line: 5)
-// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-namespace.cpp",
+// CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]])
+// CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null)
+// CHECK: [[FOOCPP:.*]] = !DIFile(filename: "foo.cpp"
 // CHECK: [[VAR_FWD:![0-9]+]] = distinct !DIGlobalVariable(name: 
"var_fwd",{{.*}} scope: [[NS]],
 // CHECK-SAME: line: 44
 // CHECK-SAME: isDefinition: true
 // CHECK: distinct !DIGlobalVariable(name: "var_i",{{.*}} scope: 
[[INLINE:![0-9]+]],
-// CHECK: [[INLINE]] = !DINamespace(name: "I", scope: [[CTXT]], file: 
[[FOOCPP]], line: 46, exportSymbols: true)
+// CHECK: [[INLINE]] = !DINamespace(name: "I", scope: [[CTXT]], exportSymbols: 
true)
+// CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
 // CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]}
@@ -106,7 +112,7 @@ void B::func_fwd() {}
 // CHECK-SAME:  scope: [[NS]], file: [[FOOCPP]], line: 
9
 // CHECK: [[M15]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[VAR_FWD:![0-9]+]]
 // CHECK: [[M16]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[FUNC_FWD:![0-9]+]]
-// CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 
50,{{.*}} isDefinition: true
+// CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 
53,{{.*}} isDefinition: true
 // CHECK: [[M17]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
 
 // CHECK-GMLT: [[CU:![0-9]+]] = distinct !DICompileUnit(

Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=301707&r1=301706&r2=301707&view=diff
==
--- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original)
+++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Fri Apr 28 17:25:53 2017
@@ -76,7 +76,7 @@ void foo() {
 // CHECK-SAME: flags: DIFlagFwdDecl,
 // CHECK-SAME: identifier:  "_ZTSN8DebugCXX4EnumE")
 
-// CHECK: ![[NS]] = !DINamespace(name: "Deb

[PATCH] D32515: [libcxx] [test] Changes to accommodate LWG 2904 "Make variant move-assignment more exception safe"

2017-04-28 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter added a comment.

Added some inline notes for reviewers.




Comment at: 
test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp:195
 }
-assert(v.valueless_by_exception());
+assert(v.index() == 0);
+assert(std::get<0>(v) == "hello");

Reviewer note: After LWG 2904, the assignment on 191 uses a new "emplace from 
temporary" path. The temporary creation now throws *before* v becomes valueless.



Comment at: 
test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp:168
-// variant only provides copy assignment when both the copy and move
-// constructors are well formed
 using V = std::variant;

Reviewer note: This comment is no longer true after LWG 2904 copy assignment no 
longer requires move constructible alternatives.



Comment at: 
test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp:121
-// variant only provides move assignment when both the move constructor
-// and move assignment operator are well formed.
 using V = std::variant;

Reviewer note: this comment is technically true even after LWG 2904, but no 
longer significant. `variant` *does* have an implicitly deleted 
move assignment operator, but `is_move_assignable_v>` is 
nonetheless true after LWG 2904 since `variant` now has a viable 
*copy* assignment operator.


https://reviews.llvm.org/D32515



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


LLVM buildmaster will be updated and restarted tonight

2017-04-28 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 7 PM Pacific time
today.

Thanks

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


[PATCH] D32410: change the way the expr evaluator handles objcboxedexpr

2017-04-28 Thread Nick Lewycky via Phabricator via cfe-commits
nlewycky updated this revision to Diff 97173.
nlewycky added a comment.

If the boxing method can't be constexpr then we can never evaluate it for a 
constant value, which means that we should unconditionally return Error, and 
use noteFailure to decide whether to visit the subexpr.


https://reviews.llvm.org/D32410

Files:
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExprObjC.cpp
  test/CodeGenObjCXX/boxing.mm


Index: test/CodeGenObjCXX/boxing.mm
===
--- test/CodeGenObjCXX/boxing.mm
+++ test/CodeGenObjCXX/boxing.mm
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | 
FileCheck %s
+
+@interface NSNumber
++ (id)numberWithInt:(int)n;
+@end
+
+int n = 1;
+int m = (@(n++), 0);
+
+// CHECK: define {{.*}} @__cxx_global_var_init()
+// CHECK: load i32, i32* @n
+// CHECK: store i32 %{{.*}}, i32* @n
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -595,7 +595,6 @@
 break;
   }
 }
-CheckForIntOverflow(ValueExpr);
 // FIXME:  Do I need to do anything special with BoolTy expressions?
 
 // Look for the appropriate method within NSNumber.
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9882,6 +9882,9 @@
 
 if (auto InitList = dyn_cast(E))
   Exprs.append(InitList->inits().begin(), InitList->inits().end());
+
+if (isa(E))
+  E->IgnoreParenCasts()->EvaluateForOverflow(Context);
   } while (!Exprs.empty());
 }
 
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -5481,8 +5481,11 @@
   bool VisitUnaryAddrOf(const UnaryOperator *E);
   bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
   { return Success(E); }
-  bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
-  { return Success(E); }
+  bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
+if (Info.noteFailure())
+  EvaluateIgnoredValue(Info, E->getSubExpr());
+return Error(E);
+  }
   bool VisitAddrLabelExpr(const AddrLabelExpr *E)
   { return Success(E); }
   bool VisitCallExpr(const CallExpr *E);


Index: test/CodeGenObjCXX/boxing.mm
===
--- test/CodeGenObjCXX/boxing.mm
+++ test/CodeGenObjCXX/boxing.mm
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+
+@interface NSNumber
++ (id)numberWithInt:(int)n;
+@end
+
+int n = 1;
+int m = (@(n++), 0);
+
+// CHECK: define {{.*}} @__cxx_global_var_init()
+// CHECK: load i32, i32* @n
+// CHECK: store i32 %{{.*}}, i32* @n
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -595,7 +595,6 @@
 break;
   }
 }
-CheckForIntOverflow(ValueExpr);
 // FIXME:  Do I need to do anything special with BoolTy expressions?
 
 // Look for the appropriate method within NSNumber.
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9882,6 +9882,9 @@
 
 if (auto InitList = dyn_cast(E))
   Exprs.append(InitList->inits().begin(), InitList->inits().end());
+
+if (isa(E))
+  E->IgnoreParenCasts()->EvaluateForOverflow(Context);
   } while (!Exprs.empty());
 }
 
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -5481,8 +5481,11 @@
   bool VisitUnaryAddrOf(const UnaryOperator *E);
   bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
   { return Success(E); }
-  bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
-  { return Success(E); }
+  bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
+if (Info.noteFailure())
+  EvaluateIgnoredValue(Info, E->getSubExpr());
+return Error(E);
+  }
   bool VisitAddrLabelExpr(const AddrLabelExpr *E)
   { return Success(E); }
   bool VisitCallExpr(const CallExpr *E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32410: change the way the expr evaluator handles objcboxedexpr

2017-04-28 Thread Richard Smith via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


https://reviews.llvm.org/D32410



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


[PATCH] D32566: Revert rL301328 and add tests for the regressions introduced.

2017-04-28 Thread Richard Smith via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Yes, let's first revert back to the clang 4.0 behavior, then please mail 
cfe-dev to discuss what the right behavior should be.


Repository:
  rL LLVM

https://reviews.llvm.org/D32566



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


r301721 - ObjCBoxedExpr can't be evaluated by the constant expression evaluator.

2017-04-28 Thread Nick Lewycky via cfe-commits
Author: nicholas
Date: Fri Apr 28 19:07:27 2017
New Revision: 301721

URL: http://llvm.org/viewvc/llvm-project?rev=301721&view=rev
Log:
ObjCBoxedExpr can't be evaluated by the constant expression evaluator.

A boxed expression evaluates its subexpr and then calls an objc method to 
transform it into another value with pointer type. The objc method can never be 
constexpr and therefore this expression can never be evaluated. Fixes a 
miscompile boxing expressions with side-effects.

Also make ObjCBoxedExpr handling a normal part of the expression evaluator 
instead of being the only case besides full-expression where we check for 
integer overflow.

Added:
cfe/trunk/test/CodeGenObjCXX/boxing.mm
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=301721&r1=301720&r2=301721&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Apr 28 19:07:27 2017
@@ -5481,8 +5481,11 @@ public:
   bool VisitUnaryAddrOf(const UnaryOperator *E);
   bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
   { return Success(E); }
-  bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
-  { return Success(E); }
+  bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
+if (Info.noteFailure())
+  EvaluateIgnoredValue(Info, E->getSubExpr());
+return Error(E);
+  }
   bool VisitAddrLabelExpr(const AddrLabelExpr *E)
   { return Success(E); }
   bool VisitCallExpr(const CallExpr *E);

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=301721&r1=301720&r2=301721&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Apr 28 19:07:27 2017
@@ -9882,6 +9882,9 @@ void Sema::CheckForIntOverflow (Expr *E)
 
 if (auto InitList = dyn_cast(E))
   Exprs.append(InitList->inits().begin(), InitList->inits().end());
+
+if (isa(E))
+  E->IgnoreParenCasts()->EvaluateForOverflow(Context);
   } while (!Exprs.empty());
 }
 

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=301721&r1=301720&r2=301721&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Apr 28 19:07:27 2017
@@ -595,7 +595,6 @@ ExprResult Sema::BuildObjCBoxedExpr(Sour
 break;
   }
 }
-CheckForIntOverflow(ValueExpr);
 // FIXME:  Do I need to do anything special with BoolTy expressions?
 
 // Look for the appropriate method within NSNumber.

Added: cfe/trunk/test/CodeGenObjCXX/boxing.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/boxing.mm?rev=301721&view=auto
==
--- cfe/trunk/test/CodeGenObjCXX/boxing.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/boxing.mm Fri Apr 28 19:07:27 2017
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | 
FileCheck %s
+
+@interface NSNumber
++ (id)numberWithInt:(int)n;
+@end
+
+int n = 1;
+int m = (@(n++), 0);
+
+// CHECK: define {{.*}} @__cxx_global_var_init()
+// CHECK: load i32, i32* @n
+// CHECK: store i32 %{{.*}}, i32* @n


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


r301725 - Add pragma to perform module import and use it in -E output.

2017-04-28 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Apr 28 19:34:47 2017
New Revision: 301725

URL: http://llvm.org/viewvc/llvm-project?rev=301725&view=rev
Log:
Add pragma to perform module import and use it in -E output.

Many of our supported configurations support modules but do not have any
first-class syntax to perform a module import. This leaves us with a problem:
there is no way to represent the expansion of a #include that imports a module
in the -E output for such languages. (We don't want to just leave it as a
#include because that requires the consumer of the preprocessed source to have
the same file system layout and include paths as the creator.)

This patch adds a new pragma:

  #pragma clang module import MODULE.NAME.HERE

that imports a module, and changes -E and -frewrite-includes to use it when
rewriting a #include that maps to a module import. We don't make any attempt
to use a native language syntax import if one exists, to get more consistent
output. (If in the future, @import and #include have different semantics in
some way, the pragma will track the #include semantics.)

Added:
cfe/trunk/test/Modules/import-syntax.c
cfe/trunk/test/Preprocessor/pragma_module.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/test/Frontend/rewrite-includes-modules.c
cfe/trunk/test/Modules/crash-vfs-path-emptydir-entries.m
cfe/trunk/test/Modules/crash-vfs-path-symlink-component.m
cfe/trunk/test/Modules/crash-vfs-path-symlink-topheader.m
cfe/trunk/test/Modules/crash-vfs-path-traversal.m
cfe/trunk/test/Modules/crash-vfs-relative-overlay.m
cfe/trunk/test/Modules/preprocess-module.cpp
cfe/trunk/test/Modules/preprocess.cpp
cfe/trunk/test/Modules/preprocess.m
cfe/trunk/test/Preprocessor/pp-modules.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=301725&r1=301724&r2=301725&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Fri Apr 28 19:34:47 2017
@@ -475,6 +475,8 @@ def warn_pragma_pop_macro_no_push : Warn
 def warn_pragma_message : Warning<"%0">,
InGroup, DefaultWarnNoWerror;
 def err_pragma_message : Error<"%0">;
+def err_pragma_module_import_expected_module_name : Error<
+  "expected %select{identifier in|'.' or end of directive after}0 module 
name">;
 def warn_pragma_ignored : Warning<"unknown pragma ignored">,
InGroup, DefaultIgnore;
 def ext_stdc_pragma_ignored : ExtWarn<"unknown pragma in STDC namespace">,

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=301725&r1=301724&r2=301725&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Apr 28 19:34:47 2017
@@ -1263,6 +1263,10 @@ public:
   CachedTokens[CachedLexPos-1] = Tok;
   }
 
+  /// Enter an annotation token into the token stream.
+  void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind,
+void *AnnotationVal);
+
   /// Update the current token to represent the provided
   /// identifier, in order to cache an action performed by typo correction.
   void TypoCorrectToken(const Token &Tok) {
@@ -1963,6 +1967,7 @@ public:
   void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token &SysHeaderTok);
   void HandlePragmaDependency(Token &DependencyTok);
+  void HandlePragmaModuleImport(Token &Tok);
   void HandlePragmaPushMacro(Token &Tok);
   void HandlePragmaPopMacro(Token &Tok);
   void HandlePragmaIncludeAlias(Token &Tok);

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=301725&r1=301724&r2=301725&view=diff
==
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Fri Apr 28 19:34:47 2017
@@ -324,43 +324,50 @@ void PrintPPOutputPPCallbacks::Inclusion
   StringRef SearchPath,
   StringRef RelativePath,
   const Module *Imported) {
-  if (Imported) {
-// When preprocessing, turn implicit imports into @imports.
-// FIXME: This is a stop-gap until a more comprehensive "preprocessing with
-// modules" solution is intro

[PATCH] D32372: Arrays of unknown bound in constant expressions

2017-04-28 Thread Richard Smith via Phabricator via cfe-commits
rsmith added a comment.

Thanks, this looks good, just a couple of minor things and then it should be 
ready to land.

Do you have commit access or will you need someone else to commit this for you?




Comment at: lib/AST/ExprConstant.cpp:152
+   uint64_t &ArraySize, QualType &Type, bool &IsArray,
+   bool &isUnsizedArray) {
 // This only accepts LValueBases from APValues, and APValues don't support

Please start variable names with an uppercase letter.



Comment at: lib/AST/ExprConstant.cpp:168
+  ArraySize = 0;
+  isUnsizedArray = true;
+}

The other 'most derived' paths through here should set this back to `false` (a 
sized array in a field in an element of an unsized array does not give an 
unsized array).



Comment at: lib/AST/ExprConstant.cpp:1301
 void addUnsizedArray(EvalInfo &Info, QualType ElemTy) {
-  assert(Designator.Entries.empty() && getType(Base)->isPointerType());
-  assert(isBaseAnAllocSizeCall(Base) &&
- "Only alloc_size bases can have unsized arrays");
-  Designator.FirstEntryIsAnUnsizedArray = true;
   Designator.addUnsizedArrayUnchecked(ElemTy);
 }

We should call `checkSubobject` here, for cases like:

```
void f(int n) {
  int arr[2][n];
  constexpr int *p = &arr[2][0];
}
```

... which we should reject because `arr[2]` is a one-past-the-end lvalue, so 
cannot be indexed (we reject this if `n` is instead a constant).


https://reviews.llvm.org/D32372



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


r301726 - Remove unused, empty test directories.

2017-04-28 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Apr 28 19:46:27 2017
New Revision: 301726

URL: http://llvm.org/viewvc/llvm-project?rev=301726&view=rev
Log:
Remove unused, empty test directories.

Removed:
cfe/trunk/test/Frontend/Rewriter/

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


r301727 - PR26771: don't forget the " 2" (returning from #included file) linemarker after including an empty file with -frewrite-includes.

2017-04-28 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Apr 28 19:54:03 2017
New Revision: 301727

URL: http://llvm.org/viewvc/llvm-project?rev=301727&view=rev
Log:
PR26771: don't forget the " 2" (returning from #included file) linemarker after 
including an empty file with -frewrite-includes.

Added:
cfe/trunk/test/Frontend/Inputs/empty.h
Modified:
cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
cfe/trunk/test/Frontend/rewrite-includes-line-markers.c

Modified: cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp?rev=301727&r1=301726&r2=301727&view=diff
==
--- cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp Fri Apr 28 19:54:03 
2017
@@ -52,7 +52,7 @@ class InclusionRewriter : public PPCallb
 public:
   InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers,
 bool UseLineDirectives);
-  bool Process(FileID FileId, SrcMgr::CharacteristicKind FileType);
+  void Process(FileID FileId, SrcMgr::CharacteristicKind FileType);
   void setPredefinesBuffer(const llvm::MemoryBuffer *Buf) {
 PredefinesBuffer = Buf;
   }
@@ -400,9 +400,8 @@ bool InclusionRewriter::HandleHasInclude
 
 /// Use a raw lexer to analyze \p FileId, incrementally copying parts of it
 /// and including content of included files recursively.
-bool InclusionRewriter::Process(FileID FileId,
-SrcMgr::CharacteristicKind FileType)
-{
+void InclusionRewriter::Process(FileID FileId,
+SrcMgr::CharacteristicKind FileType) {
   bool Invalid;
   const MemoryBuffer &FromFile = *SM.getBuffer(FileId, &Invalid);
   assert(!Invalid && "Attempting to process invalid inclusion");
@@ -419,7 +418,7 @@ bool InclusionRewriter::Process(FileID F
 WriteLineInfo(FileName, 1, FileType, " 1");
 
   if (SM.getFileIDSize(FileId) == 0)
-return false;
+return;
 
   // The next byte to be copied from the source file, which may be non-zero if
   // the lexer handled a BOM.
@@ -453,14 +452,11 @@ bool InclusionRewriter::Process(FileID F
 if (const Module *Mod = FindModuleAtLocation(Loc))
   WriteImplicitModuleImport(Mod);
 else if (const IncludedFile *Inc = FindIncludeAtLocation(Loc)) {
-  // include and recursively process the file
-  if (Process(Inc->Id, Inc->FileType)) {
-// and set lineinfo back to this file, if the nested one was
-// actually included
-// `2' indicates returning to a file (after having included
-// another file.
-LineInfoExtra = " 2";
-  }
+  // Include and recursively process the file.
+  Process(Inc->Id, Inc->FileType);
+  // Add line marker to indicate we're returning from an included
+  // file.
+  LineInfoExtra = " 2";
 }
 // fix up lineinfo (since commented out directive changed line
 // numbers) for inclusions that were skipped due to header guards
@@ -569,7 +565,6 @@ bool InclusionRewriter::Process(FileID F
   OutputContentUpTo(FromFile, NextToWrite,
 SM.getFileOffset(SM.getLocForEndOfFile(FileId)), LocalEOL,
 Line, /*EnsureNewline=*/true);
-  return true;
 }
 
 /// InclusionRewriterInInput - Implement -frewrite-includes mode.

Added: cfe/trunk/test/Frontend/Inputs/empty.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/Inputs/empty.h?rev=301727&view=auto
==
(empty)

Modified: cfe/trunk/test/Frontend/rewrite-includes-line-markers.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/rewrite-includes-line-markers.c?rev=301727&r1=301726&r2=301727&view=diff
==
--- cfe/trunk/test/Frontend/rewrite-includes-line-markers.c (original)
+++ cfe/trunk/test/Frontend/rewrite-includes-line-markers.c Fri Apr 28 19:54:03 
2017
@@ -3,6 +3,8 @@
 #include "test.h"
 int f() { return x; }
 
+#include "empty.h"
+
 // GNU: {{^}}# 1 "{{.*}}rewrite-includes-line-markers.c"
 // GNU: {{^}}#include "test.h"
 // GNU: {{^}}# 1 "{{.*}}test.h"
@@ -11,6 +13,9 @@ int f() { return x; }
 // GNU: {{^}}int x;
 // GNU: {{^}}# 4 "{{.*}}rewrite-includes-line-markers.c" 2
 // GNU: {{^}}int f() { return x; }
+// GNU: {{^}}
+// GNU: {{^}}# 1 "{{.*}}empty.h" 1
+// GNU: {{^}}# 7 "{{.*}}rewrite-includes-line-markers.c" 2
 
 // LINE: {{^}}#line 1 "{{.*}}rewrite-includes-line-markers.c"
 // LINE: {{^}}#include "test.h"
@@ -20,3 +25,6 @@ int f() { return x; }
 // LINE: {{^}}int x;
 // LINE: {{^}}#line 4 "{{.*}}rewrite-includes-line-markers.c"
 // LINE: {{^}}int f() { return x; }
+// LINE: {{

[PATCH] D32412: analyze all kinds of expressions for integer overflow

2017-04-28 Thread Nick Lewycky via Phabricator via cfe-commits
nlewycky updated this revision to Diff 97178.
nlewycky edited the summary of this revision.
nlewycky added a comment.

Rebase. Now that ObjCBoxedExpr change is in, we can remove 
Sema::CheckForIntOverflow entirely.


https://reviews.llvm.org/D32412

Files:
  include/clang/Sema/Sema.h
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaChecking.cpp
  test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/distribute_simd_aligned_messages.cpp
  test/OpenMP/for_simd_aligned_messages.cpp
  test/OpenMP/parallel_for_simd_aligned_messages.cpp
  test/OpenMP/simd_aligned_messages.cpp
  test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/target_simd_aligned_messages.cpp
  test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
  test/OpenMP/taskloop_simd_aligned_messages.cpp
  test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/teams_distribute_simd_aligned_messages.cpp
  test/Sema/integer-overflow.c

Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -152,8 +152,14 @@
   uint64_t b2 = b[4608 * 1024 * 1024] + 1;
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  (void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1);
+  int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024);
 
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  int j2 = -(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  uint64_t j3 = b[4608 * 1024 * 1024];
+
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
 }
Index: test/OpenMP/teams_distribute_simd_aligned_messages.cpp
===
--- test/OpenMP/teams_distribute_simd_aligned_messages.cpp
+++ test/OpenMP/teams_distribute_simd_aligned_messages.cpp
@@ -123,9 +123,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
 
 #pragma omp target
Index: test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
===
--- test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
@@ -123,9 +123,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
 
 #pragma omp target
Index: test/OpenMP/taskloop_simd_aligned_messages.cpp
===
--- test/OpenMP/taskloop_simd_aligned_messages.cpp
+++ test/OpenMP/taskloop_simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
   #pragma omp taskloop simd aligned // expected-error {{expected '(' after 'aligned'}}
   for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
===
--- test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
+++ test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
@@ -110,9 +110,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
 
 #pragma omp target teams distribute simd aligned // expected-error {{expected '(' after 'aligned'}}
Index: test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
===
--- test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp

[PATCH] D32412: analyze all kinds of expressions for integer overflow

2017-04-28 Thread Nick Lewycky via Phabricator via cfe-commits
nlewycky added a comment.

> If we're now catching integer overflow in more cases, please add some 
> relevant testcases.

Both more and fewer. More because we no longer have a whitelist of three kinds 
of expressions that we recurse into. Fewer because we no longer call 
IgnoreParenCasts() on the full-expression so "(void)(4608 * 1024 * 1024);" used 
to get a warning but now doesn't. The plan to fix this is a patch to call 
EvaluateIgnoredValue on non-literal types, which will get us that warning back.

I've added two cases to test/Sema/integer-overflow.c and changed one to 
demonstrate this patch. It previously had an additional + on it just to trigger 
the int overflow checking.

> I have an unsubstantiated performance concern: we've seen this overflow 
> checking having a visible effect on compile times in LNT before

I haven't observed slowdown like I did with my previous attempt at this change 
in https://reviews.llvm.org/D31839, but yes we may need to back this patch out 
if it causes problems.


https://reviews.llvm.org/D32412



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


[PATCH] D32412: analyze all kinds of expressions for integer overflow

2017-04-28 Thread Nick Lewycky via Phabricator via cfe-commits
nlewycky updated this revision to Diff 97179.
nlewycky added a comment.

[No changes, just full context this time.]


https://reviews.llvm.org/D32412

Files:
  include/clang/Sema/Sema.h
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaChecking.cpp
  test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/distribute_simd_aligned_messages.cpp
  test/OpenMP/for_simd_aligned_messages.cpp
  test/OpenMP/parallel_for_simd_aligned_messages.cpp
  test/OpenMP/simd_aligned_messages.cpp
  test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/target_simd_aligned_messages.cpp
  test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
  test/OpenMP/taskloop_simd_aligned_messages.cpp
  test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
  test/OpenMP/teams_distribute_simd_aligned_messages.cpp
  test/Sema/integer-overflow.c

Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -152,7 +152,13 @@
   uint64_t b2 = b[4608 * 1024 * 1024] + 1;
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  (void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1);
+  int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  int j2 = -(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+  uint64_t j3 = b[4608 * 1024 * 1024];
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
Index: test/OpenMP/teams_distribute_simd_aligned_messages.cpp
===
--- test/OpenMP/teams_distribute_simd_aligned_messages.cpp
+++ test/OpenMP/teams_distribute_simd_aligned_messages.cpp
@@ -123,9 +123,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
 
 #pragma omp target
Index: test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
===
--- test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
@@ -123,9 +123,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
 
 #pragma omp target
Index: test/OpenMP/taskloop_simd_aligned_messages.cpp
===
--- test/OpenMP/taskloop_simd_aligned_messages.cpp
+++ test/OpenMP/taskloop_simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
   #pragma omp taskloop simd aligned // expected-error {{expected '(' after 'aligned'}}
   for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
===
--- test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
+++ test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
@@ -110,9 +110,8 @@
 template int foomain(I argc, C **argv) {
   I e(argc);
   I g(argc);
-  int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
-  // expected-note@+2 {{declared here}}
-  // expected-note@+1 {{reference to 'i' is not a constant expression}}
+  int i; // expected-note {{'i' defined here}}
+  // expected-note@+1 {{declared here}}
   int &j = i;
 
 #pragma omp target teams distribute simd aligned // expected-error {{expected '(' after 'aligned'}}
Index: test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
===
--- test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
@@ -110,9 +110,8 @@
 t

[PATCH] D32372: Arrays of unknown bound in constant expressions

2017-04-28 Thread Robert Haberlach via Phabricator via cfe-commits
Arcoth updated this revision to Diff 97180.
Arcoth added a comment.

Applied the last review's suggestions.


https://reviews.llvm.org/D32372

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/SemaCXX/constexpr-array-unknown-bound.cpp

Index: test/SemaCXX/constexpr-array-unknown-bound.cpp
===
--- /dev/null
+++ test/SemaCXX/constexpr-array-unknown-bound.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++1z -fsyntax-only -verify
+
+const extern int arr[];
+constexpr auto p = arr; // ok
+constexpr int f(int i) {return p[i];} // expected-note {{read of dereferenced one-past-the-end pointer}}
+
+constexpr int arr[] {1, 2, 3};
+constexpr auto p2 = arr + 2; // ok
+constexpr int x = f(2); // ok
+constexpr int y = f(3); // expected-error {{constant expression}}
+// expected-note-re@-1 {{in call to 'f({{.*}})'}}
+
+struct A {int m[];} a;
+constexpr auto p3 = a.m; // ok
+constexpr auto p4 = a.m + 1; // expected-error {{constant expression}} expected-note {{constant bound}}
+
+void g(int i) {
+  int arr[i];
+  constexpr auto p = arr + 2; // expected-error {{constant expression}} expected-note {{constant bound}}
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -148,37 +148,44 @@
   static unsigned
   findMostDerivedSubobject(ASTContext &Ctx, APValue::LValueBase Base,
ArrayRef Path,
-   uint64_t &ArraySize, QualType &Type, bool &IsArray) {
+   uint64_t &ArraySize, QualType &Type, bool &IsArray,
+   bool &IsUnsizedArray) {
 // This only accepts LValueBases from APValues, and APValues don't support
 // arrays that lack size info.
 assert(!isBaseAnAllocSizeCall(Base) &&
"Unsized arrays shouldn't appear here");
 unsigned MostDerivedLength = 0;
 Type = getType(Base);
 
 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
-  if (Type->isArrayType()) {
-const ConstantArrayType *CAT =
-cast(Ctx.getAsArrayType(Type));
-Type = CAT->getElementType();
-ArraySize = CAT->getSize().getZExtValue();
+  if (auto AT = Ctx.getAsArrayType(Type)) {
 MostDerivedLength = I + 1;
 IsArray = true;
+if (auto CAT = Ctx.getAsConstantArrayType(Type))
+  ArraySize = CAT->getSize().getZExtValue();
+else {
+  ArraySize = 0;
+  IsUnsizedArray = true;
+}
+Type = AT->getElementType();
   } else if (Type->isAnyComplexType()) {
 const ComplexType *CT = Type->castAs();
 Type = CT->getElementType();
 ArraySize = 2;
 MostDerivedLength = I + 1;
 IsArray = true;
+IsUnsizedArray = false;
   } else if (const FieldDecl *FD = getAsField(Path[I])) {
 Type = FD->getType();
 ArraySize = 0;
 MostDerivedLength = I + 1;
 IsArray = false;
+IsUnsizedArray = false;
   } else {
 // Path[I] describes a base class.
 ArraySize = 0;
 IsArray = false;
+IsUnsizedArray = false;
   }
 }
 return MostDerivedLength;
@@ -200,8 +207,9 @@
 /// Is this a pointer one past the end of an object?
 unsigned IsOnePastTheEnd : 1;
 
-/// Indicator of whether the first entry is an unsized array.
-unsigned FirstEntryIsAnUnsizedArray : 1;
+/// Indicator of whether the most-derived object is an unsized array (e.g.
+/// of unknown bound).
+unsigned MostDerivedIsAnUnsizedArray : 1;
 
 /// Indicator of whether the most-derived object is an array element.
 unsigned MostDerivedIsArrayElement : 1;
@@ -231,25 +239,28 @@
 
 explicit SubobjectDesignator(QualType T)
 : Invalid(false), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0),
   MostDerivedType(T) {}
 
 SubobjectDesignator(ASTContext &Ctx, const APValue &V)
 : Invalid(!V.isLValue() || !V.hasLValuePath()), IsOnePastTheEnd(false),
-  FirstEntryIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
+  MostDerivedIsAnUnsizedArray(false), MostDerivedIsArrayElement(false),
   MostDerivedPathLength(0), MostDerivedArraySize(0) {
   assert(V.isLValue() && "Non-LValue used to make an LValue designator?");
   if (!Invalid) {
 IsOnePastTheEnd = V.isLValueOnePastTheEnd();
 ArrayRef VEntries = V.getLValuePath();
 Entries.insert(Entries.end(), VEntries.begin(), VEntries.end());
-if (V.getLValueBase()) {
-  bool IsArray = false;
+if (auto Base = V.getLValueBase()) {
+  if (auto Decl = Base.dyn_cast())

r301731 - Fix "REQUIRES: system-darwin" failing tests after r301725.

2017-04-28 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Apr 28 20:29:44 2017
New Revision: 301731

URL: http://llvm.org/viewvc/llvm-project?rev=301731&view=rev
Log:
Fix "REQUIRES: system-darwin" failing tests after r301725.

Also remove the apparently-unneeded REQUIRES (the tests also pass on at least
Linux, and don't appear to have anything Darwin-specific in them).

Modified:
cfe/trunk/test/Modules/crash-vfs-relative-incdir.m
cfe/trunk/test/Modules/crash-vfs-run-reproducer.m

Modified: cfe/trunk/test/Modules/crash-vfs-relative-incdir.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-relative-incdir.m?rev=301731&r1=301730&r2=301731&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-relative-incdir.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-relative-incdir.m Fri Apr 28 20:29:44 2017
@@ -1,4 +1,4 @@
-// REQUIRES: crash-recovery, shell, system-darwin
+// REQUIRES: crash-recovery, shell
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/m
@@ -21,7 +21,7 @@
 // CHECK-NEXT: note: diagnostic msg: {{.*}}.m
 // CHECK-NEXT: note: diagnostic msg: {{.*}}.cache
 
-// CHECKSRC: @import cstd.stdio;
+// CHECKSRC: #pragma clang module import cstd.stdio
 
 // CHECKSH: # Crash reproducer
 // CHECKSH-NEXT: # Driver args: "-fsyntax-only"

Modified: cfe/trunk/test/Modules/crash-vfs-run-reproducer.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-run-reproducer.m?rev=301731&r1=301730&r2=301731&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-run-reproducer.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-run-reproducer.m Fri Apr 28 20:29:44 2017
@@ -1,4 +1,4 @@
-// REQUIRES: crash-recovery, shell, system-darwin
+// REQUIRES: crash-recovery, shell
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/i %t/m %t
@@ -21,7 +21,7 @@
 // CHECK-NEXT: note: diagnostic msg: {{.*}}.m
 // CHECK-NEXT: note: diagnostic msg: {{.*}}.cache
 
-// CHECKSRC: @import cstd.stdio;
+// CHECKSRC: #pragma clang module import cstd.stdio
 
 // CHECKSH: # Crash reproducer
 // CHECKSH-NEXT: # Driver args: "-fsyntax-only"


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


[PATCH] D32291: [analyzer] Implement handling array subscript into null pointer, improve null dereference checks for array subscripts

2017-04-28 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:80
 }
-else if (isDeclRefExprToReference(E)) {
+else if (isa(E)) {
   return E;

Not sure what this does, but looks like we are stricter here now.
Also, since you are changing bug reporter visitor, shouldn't there be tests for 
diagnostic paths?


Repository:
  rL LLVM

https://reviews.llvm.org/D32291



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


r301732 - Remove some apparently-unnecessary 'REQUIRES: system-darwin' from tests.

2017-04-28 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Apr 28 20:38:29 2017
New Revision: 301732

URL: http://llvm.org/viewvc/llvm-project?rev=301732&view=rev
Log:
Remove some apparently-unnecessary 'REQUIRES: system-darwin' from tests.

Let's see if any buildbots actually have trouble with these. (They at least 
pass on Linux.)

Modified:
cfe/trunk/test/Modules/crash-vfs-headermaps.m
cfe/trunk/test/Modules/crash-vfs-include-pch.m
cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m

Modified: cfe/trunk/test/Modules/crash-vfs-headermaps.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-headermaps.m?rev=301732&r1=301731&r2=301732&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-headermaps.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-headermaps.m Fri Apr 28 20:38:29 2017
@@ -1,4 +1,4 @@
-// REQUIRES: crash-recovery, shell, system-darwin
+// REQUIRES: crash-recovery, shell
 
 // This uses a headermap with this entry:
 //   Foo.h -> Foo/Foo.h

Modified: cfe/trunk/test/Modules/crash-vfs-include-pch.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-include-pch.m?rev=301732&r1=301731&r2=301732&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-include-pch.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-include-pch.m Fri Apr 28 20:38:29 2017
@@ -1,4 +1,4 @@
-// REQUIRES: crash-recovery, shell, system-darwin
+// REQUIRES: crash-recovery, shell
 //
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/m %t/out

Modified: cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m?rev=301732&r1=301731&r2=301732&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-ivfsoverlay.m Fri Apr 28 20:38:29 2017
@@ -1,4 +1,4 @@
-// REQUIRES: crash-recovery, shell, system-darwin
+// REQUIRES: crash-recovery, shell
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/m


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


r301735 - Fix PR32831: 'this capture while instantiating generic lambda call operator specialization

2017-04-28 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Fri Apr 28 22:49:17 2017
New Revision: 301735

URL: http://llvm.org/viewvc/llvm-project?rev=301735&view=rev
Log:
Fix PR32831: 'this capture while instantiating generic lambda call operator 
specialization

When computing the appropriate cv-qualifiers for the 'this' capture, we have to 
examine each enclosing lambda - but when using the FunctionScopeInfo stack we 
have to ensure that the lambda below (outer) is the decl-context of the 
closure-class of the current lambda.

https://bugs.llvm.org/show_bug.cgi?id=32831

Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=301735&r1=301734&r2=301735&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Apr 28 22:49:17 2017
@@ -901,17 +901,35 @@ static QualType adjustCVQualifiersForCXX
   // capturing lamdbda's call operator.
   //
 
-  // The issue is that we cannot rely entirely on the FunctionScopeInfo stack
-  // since ScopeInfos are pushed on during parsing and treetransforming. But
-  // since a generic lambda's call operator can be instantiated anywhere (even
-  // end of the TU) we need to be able to examine its enclosing lambdas and so
-  // we use the DeclContext to get a hold of the closure-class and query it for
-  // capture information.  The reason we don't just resort to always using the
-  // DeclContext chain is that it is only mature for lambda expressions
-  // enclosing generic lambda's call operators that are being instantiated.
+  // Since the FunctionScopeInfo stack is representative of the lexical
+  // nesting of the lambda expressions during initial parsing (and is the best
+  // place for querying information about captures about lambdas that are
+  // partially processed) and perhaps during instantiation of function 
templates
+  // that contain lambda expressions that need to be transformed BUT not
+  // necessarily during instantiation of a nested generic lambda's function 
call
+  // operator (which might even be instantiated at the end of the TU) - at 
which
+  // time the DeclContext tree is mature enough to query capture information
+  // reliably - we use a two pronged approach to walk through all the lexically
+  // enclosing lambda expressions:
+  //
+  //  1) Climb down the FunctionScopeInfo stack as long as each item represents
+  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is 
lexically
+  //  enclosed by the call-operator of the LSI below it on the stack (while
+  //  tracking the enclosing DC for step 2 if needed).  Note the topmost LSI on
+  //  the stack represents the innermost lambda.
+  //
+  //  2) Iterate out through the DeclContext chain (if it represents a lambda's
+  //  call operator, and therefore must be a generic lambda's call operator,
+  //  which is the only time an inconsistency between the LSI and the
+  //  DeclContext should occur) querying closure types regarding capture
+  //  information.
 
+
+  // 1) Climb down the function scope info stack.
   for (int I = FunctionScopes.size();
-   I-- && isa(FunctionScopes[I]);
+   I-- && isa(FunctionScopes[I]) &&
+   (!CurLSI || CurLSI->Lambda->getDeclContext() ==
+   cast(FunctionScopes[I])->CallOperator);
CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
 CurLSI = cast(FunctionScopes[I]);
 
@@ -927,11 +945,17 @@ static QualType adjustCVQualifiersForCXX
   return ASTCtx.getPointerType(ClassType);
 }
   }
-  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of generic lambdas)
+
+  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
+  // happen during instantiation of its nested generic lambda call operator)
   if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI);
-assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator));
+assert(CurLSI && "While computing 'this' capture-type for a generic "
+ "lambda, we must have a corresponding LambdaScopeInfo");
+assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
+   "While computing 'this' capture-type for a generic lambda, when we "
+   "run out of enclosing LSI's, yet the enclosing DC is a "
+   "lambda-call-operator we must be (i.e. Current LSI) in a generic "
+   "lambda call oeprator");
 assert(CurDC == getLambdaAwareParentOfDeclContext(CurLSI->CallOperator));
 
 auto IsThisCaptured =

Modified: cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp?rev=301735&r1=301734&r2=301735&view=diff

RE: r301707 - Adapt to LLVM API change (DINamespace no longer takes line/file info).

2017-04-28 Thread Yung, Douglas via cfe-commits
Hi Adrian,

This commit, or the previous one you made seems to be causing a failure in the 
clang test CodeGenCXX\debug-info-namespace.cpp on the ps4 Windows and Linux 
bots. It's failing when trying to match the CHECK line on line 79 of the test 
because the line it matches seems to have one extra import on the PS4 target. 
Can you take a look?

Douglas Yung

> -Original Message-
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of
> Adrian Prantl via cfe-commits
> Sent: Friday, April 28, 2017 15:26
> To: cfe-commits@lists.llvm.org
> Subject: r301707 - Adapt to LLVM API change (DINamespace no longer takes
> line/file info).
> 
> Author: adrian
> Date: Fri Apr 28 17:25:53 2017
> New Revision: 301707
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=301707&view=rev
> Log:
> Adapt to LLVM API change (DINamespace no longer takes line/file info).
> 
> rdar://problem/17484998
> https://reviews.llvm.org/D32648
> 
> Modified:
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
> cfe/trunk/test/Modules/ExtDebugInfo.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=301707&r1=301706&r2=301707&v
> iew=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 28 17:25:53 2017
> @@ -4034,11 +4034,9 @@ CGDebugInfo::getOrCreateNameSpace(const
>if (I != NameSpaceCache.end())
>  return cast(I->second);
> 
> -  unsigned LineNo = getLineNumber(NSDecl->getLocation());
> -  llvm::DIFile *FileD = getOrCreateFile(NSDecl->getLocation());
>llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
> -  llvm::DINamespace *NS = DBuilder.createNameSpace(
> -  Context, NSDecl->getName(), FileD, LineNo, NSDecl->isInline());
> +  llvm::DINamespace *NS =
> +  DBuilder.createNameSpace(Context, NSDecl->getName(),
> + NSDecl->isInline());
>NameSpaceCache[NSDecl].reset(NS);
>return NS;
>  }
> 
> Modified: cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-
> namespace.cpp?rev=301707&r1=301706&r2=301707&view=diff
> ==
> --- cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp Fri Apr 28
> +++ 17:25:53 2017
> @@ -53,21 +53,27 @@ inline namespace I {  int var_i;  }  } -void B::func_fwd()
> {}
> +namespace {
> +int anonymous;
> +}
> +void B::func_fwd() {
> +  anonymous = 0;
> +}
> +
> 
>  // This should work even if 'i' and 'func' were declarations & not
> definitions,  // but it doesn't yet.
> 
>  // CHECK: [[I:![0-9]+]] = distinct !DIGlobalVariable(name: "i",{{.*}} scope:
> [[NS:![0-9]+]], -// CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-
> 9]+]], file: [[FOOCPP:![0-9]+]], line: 1) -// CHECK: [[FOOCPP]] =
> !DIFile(filename: "foo.cpp"
> -// CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null, file: [[FILE:![0-
> 9]+]], line: 5) -// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-
> namespace.cpp",
> +// CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]]) //
> +CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null) // CHECK:
> +[[FOOCPP:.*]] = !DIFile(filename: "foo.cpp"
>  // CHECK: [[VAR_FWD:![0-9]+]] = distinct !DIGlobalVariable(name:
> "var_fwd",{{.*}} scope: [[NS]],
>  // CHECK-SAME: line: 44
>  // CHECK-SAME: isDefinition: true
>  // CHECK: distinct !DIGlobalVariable(name: "var_i",{{.*}} scope:
> [[INLINE:![0-9]+]], -// CHECK: [[INLINE]] = !DINamespace(name: "I", scope:
> [[CTXT]], file: [[FOOCPP]], line: 46, exportSymbols: true)
> +// CHECK: [[INLINE]] = !DINamespace(name: "I", scope: [[CTXT]],
> +exportSymbols: true) // CHECK: !DINamespace(scope: null)
>  // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
>  // CHECK-SAME:imports: [[MODULES:![0-9]*]]
>  // CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]],
> [[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-
> 9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]],
> [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], [[M17:![0-
> 9]+]]} @@ -106,7 +112,7 @@ void B::func_fwd() {}
>  // CHECK-SAME:  scope: [[NS]], file: [[FOOCPP]],
> line: 9
>  // CHECK: [[M15]] = !DIImportedEntity(tag: DW_TAG_imported_declaration,
> scope: [[FUNC]], entity: [[VAR_FWD:![0-9]+]]  // CHECK: [[M16]] =
> !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity:
> [[FUNC_FWD:![0-9]+]] -// CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name:
> "func_fwd",{{.*}} line: 50,{{.*}} isDefinition: tr

[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-28 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 97182.
yamaguchi added a comment.

Update testcase. Made it minimal.


https://reviews.llvm.org/D32646

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/warn-missing-braces.c


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} 
expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,17 +885,22 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system 
header.
 if (T->isArrayType() || T->isRecordType()) {
-  SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
-   diag::warn_missing_braces)
-  << StructuredSubobjectInitList->getSourceRange()
-  << FixItHint::CreateInsertion(
- StructuredSubobjectInitList->getLocStart(), "{")
-  << FixItHint::CreateInsertion(
- SemaRef.getLocForEndOfToken(
- StructuredSubobjectInitList->getLocEnd()),
- "}");
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {
+SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
+ diag::warn_missing_braces)
+<< StructuredSubobjectInitList->getSourceRange()
+<< FixItHint::CreateInsertion(
+   StructuredSubobjectInitList->getLocStart(), "{")
+<< FixItHint::CreateInsertion(
+   SemaRef.getLocForEndOfToken(
+   StructuredSubobjectInitList->getLocEnd()),
+   "}");
+  }
 }
   }
 }


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,17 +885,22 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system header.
 if (T->isArrayType() || T->isRecordType()) {
-  SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
-   diag::warn_missing_braces)
-  << StructuredSubobjectInitList->getSourceRange()
-  << FixItHint::CreateInsertion(
- StructuredSubobjectInitList->getLocStart(), "{")
-  << FixItHint::CreateInsertion(
- SemaRef.getLocForEndOfToken(
- StructuredSubobjectInitList->getLocEnd()),
- "}");
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {
+SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
+ diag::warn_missing_braces)
+<< StructuredSubobjectInitList->getSourceRange()
+<< FixItHint::CreateInsertion(
+   StructuredSubobjectInitList->getLocStart(), "{")
+<< FixItHint::CreateInsertion(
+   SemaRef.getLocForEndOfToken(
+   StructuredSubobjectInitList->getLocEnd()),
+   "}");
+  }
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits