Re: [PATCH] D12793: Three new security overflow builtins with generic argument types

2015-09-24 Thread David Grayson via cfe-commits
DavidEGrayson removed rL LLVM as the repository for this revision.
DavidEGrayson updated this revision to Diff 35592.
DavidEGrayson added a comment.

I have changed the patch to incorporate most of John McCall's feedback.   The 
only thing I didn't act on was the suggestion to change the names of the 
variables XITy, YITy, RITy, and EITy, because I could not think of anything 
better.


http://reviews.llvm.org/D12793

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins-overflow-error.c
  test/CodeGen/builtins-overflow.c

Index: test/CodeGen/builtins-overflow.c
===
--- test/CodeGen/builtins-overflow.c
+++ test/CodeGen/builtins-overflow.c
@@ -11,7 +11,159 @@
 extern int IntErrorCode;
 extern long LongErrorCode;
 extern long long LongLongErrorCode;
+void overflowed(void);
 
+unsigned test_add_overflow_uint_uint_uint(unsigned x, unsigned y) {
+  // CHECK: @test_add_overflow_uint_uint_uint
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  unsigned r;
+  if (__builtin_add_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_add_overflow_int_int_int(int x, int y) {
+  // CHECK: @test_add_overflow_int_int_int
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  int r;
+  if (__builtin_add_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+unsigned test_sub_overflow_uint_uint_uint(unsigned x, unsigned y) {
+  // CHECK: @test_sub_overflow_uint_uint_uint
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  unsigned r;
+  if (__builtin_sub_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_sub_overflow_int_int_int(int x, int y) {
+  // CHECK: @test_sub_overflow_int_int_int
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  int r;
+  if (__builtin_sub_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+unsigned test_mul_overflow_uint_uint_uint(unsigned x, unsigned y) {
+  // CHECK: @test_mul_overflow_uint_uint_uint
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  unsigned r;
+  if (__builtin_mul_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_mul_overflow_int_int_int(int x, int y) {
+  // CHECK: @test_mul_overflow_int_int_int
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}})
+  // CHECK-DAG: [[C:%.+]] = extractvalue { i32, i1 } [[S]], 1
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i32, i1 } [[S]], 0
+  // CHECK: store i32 [[Q]], i32* %r
+  // CHECK: br i1 [[C]]
+  int r;
+  if (__builtin_mul_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+int test_add_overflow_uint_int_int(unsigned x, int y) {
+  // CHECK: @test_add_overflow_uint_int_int
+  // CHECK: [[XE:%.+]] = zext i32 %{{.+}} to i33
+  // CHECK: [[YE:%.+]] = sext i32 %{{.+}} to i33
+  // CHECK: [[S:%.+]] = call { i33, i1 } @llvm.sadd.with.overflow.i33(i33 [[XE]], i33 [[YE]])
+  // CHECK-DAG: [[Q:%.+]] = extractvalue { i33, i1 } [[S]], 0
+  // CHECK-DAG: [[C1:%.+]] = extractvalue { i33, i1 } [[S]], 1
+  // CHECK: [[QT:%.+]] = trunc i33 [[Q]] to i32
+  // CHECK: [[QTE:%.+]] = sext i32 [[QT]] to i33
+  // CHECK: [[C2:%.+]] = icmp ne i33 [[Q]], [[QTE]]
+  // CHECK: [[C3:%.+]] = or i1 [[C1]], [[C2]]
+  // CHECK: store i32 [[QT]], i32* %r
+  // CHECK: br i1 [[C3]]
+  int r;
+  if (__builtin_add_overflow(x, y, ))
+overflowed();
+  return r;
+}
+
+_Bool test_add_overflow_uint_uint_bool(unsigned x, unsigned y) {
+  // CHECK: @test_add_overflow_uint_uint_bool
+  // CHECK-NOT: ext
+  // CHECK: [[S:%.+]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %{{.+}}, i32 

Re: [PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

2015-09-24 Thread Sean Eveson via cfe-commits
seaneveson added a comment.

Thank you for looking at the patch and all your comments.

In http://reviews.llvm.org/D13099#252492, @xazax.hun wrote:

> One more note. Do we want to support const_cast for this? A possible way to 
> do that is to invalidate this, when a const cast appears in the body of the 
> function. (However the body might not be available. It is only my opinion, 
> but I would be ok to accept this patch without const cast support, but it is 
> something that we might want to document somewhere as a caveat.


IMO it is reasonable to assume that a const method wont modify non-mutable 
members. While it is possible to use casts or other pointers to make changes, 
I'm not sure it is worth checking for these cases.



Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:409
@@ +408,3 @@
+  if (const CXXMethodDecl *D = cast_or_null(getDecl())) {
+if(D->getCanonicalDecl()->isConst()) {
+  // Check if the containing class/struct has mutable members

xazax.hun wrote:
> Do we need to get the cannonical decl here? When one declaration is const, 
> all of them supposed to be const.
I was getting a strange case where the PR21606 test didn't work without 
getCanonical, but when testing it now it seems to be fine. Perhaps something 
was fixed elsewhere? Regardless I'll remove the call. Thanks.


Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:412
@@ +411,3 @@
+  const MemRegion *ThisRegion = getCXXThisVal().getAsRegion();
+  if (ThisRegion) {
+MemRegionManager *MemMgr = ThisRegion->getMemRegionManager();

xazax.hun wrote:
> Is it possible to fail to get ThisRegion? Should this be an assert?
I put the test in because getCXXThisVal can return an UnknownVal, but on closer 
inspection I don't think this will ever happen for a CXXMemberCall, so I will 
change this to an assert. Thanks.


Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:415
@@ +414,3 @@
+const CXXRecordDecl *Parent = D->getParent();
+for (const auto *I : Parent->fields()) {
+  if (I->isMutable()) {

xazax.hun wrote:
> What about the mutable fields of base classes? Are they covered here?
Good point, I don't think they are so I'll work on that.


http://reviews.llvm.org/D13099



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


Re: [PATCH] D12901: [Static Analyzer] Intersecting ranges and 64 bit to 32 bit truncations causing "System is over constrained." assertions.

2015-09-24 Thread pierre gousseau via cfe-commits
pgousseau updated this revision to Diff 35604.
pgousseau added a comment.

Following Gabor's review:

Add a test factoring 'index + 1' in an extra variable.

Let me know if this looks reasonable ?

Regards,

Pierre


http://reviews.llvm.org/D12901

Files:
  lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
  lib/StaticAnalyzer/Core/SimpleConstraintManager.h
  test/Analysis/range_casts.c

Index: test/Analysis/range_casts.c
===
--- /dev/null
+++ test/Analysis/range_casts.c
@@ -0,0 +1,158 @@
+// This test checks that intersecting ranges does not cause 'system is over constrained' assertions in the case of eg: 32 bits unsigned integers getting their range from 64 bits signed integers.
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify %s
+
+void clang_analyzer_warnIfReached();
+
+void f1(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index + 1 == 0) // because of foo range, index is in range [0; UINT_MAX]
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f2(unsigned long foo)
+{
+  int index = -1;
+  if (index < foo) index = foo; // index equals ULONG_MAX
+  if (index + 1 == 0)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // no-warning
+}
+
+void f3(unsigned long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index + 1 == 0)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f4(long foo)
+{
+  int index = -1;
+  if (index < foo) index = foo;
+  if (index + 1 == 0)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f5(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index == -1)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f6(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index == -1)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f7(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index - 1 == 0)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f8(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index + 1L == 0L)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f9(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index - 1L == 0L)
+// FIXME: should be reached
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f10(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index + 1 == 0L)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f11(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index + 1UL == 0L)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f12(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index - 1UL == 0L)
+// FIXME: should be reached
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f13(int foo)
+{
+  unsigned short index = -1;
+  if (index < foo) index = foo;
+  if (index + 1 == 0)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f14(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  long bar = foo;
+  if (index + 1 == 0)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void f15(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  unsigned int tmp = index + 1;
+  if (tmp == 0)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  else
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
Index: lib/StaticAnalyzer/Core/SimpleConstraintManager.h

Re: [Diffusion] rL248418: Fix loop-convert for const references to containers.

2015-09-24 Thread Alexander Kornienko via cfe-commits
alexfh added subscribers: angelgarcia, klimek, cfe-commits.
alexfh added a comment.

One trivial comment. Angel can probably fix this faster.


/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp:394 ```
// Handle references to containers.
CType = CType->getNonReferenceType();
```

Users:
  klimek (Author)

http://reviews.llvm.org/rL248418



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


Re: [PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 35608.
angelgarcia added a comment.

> No need to check the length. `endswith` handles this itself.


I am checking that it is strictly greater than one, because we don't want an 
empty identifier after removing the "s".


http://reviews.llvm.org/D13052

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/modernize/LoopConvertCheck.h
  clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tidy/modernize/LoopConvertUtils.h
  clang-tidy/modernize/ModernizeTidyModule.cpp
  test/clang-tidy/Inputs/modernize-loop-convert/structures.h
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-camelback.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp
  test/clang-tidy/modernize-loop-convert-lowercase.cpp
  test/clang-tidy/modernize-loop-convert-negative.cpp
  test/clang-tidy/modernize-loop-convert-uppercase.cpp

Index: test/clang-tidy/modernize-loop-convert-uppercase.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-loop-convert-uppercase.cpp
@@ -0,0 +1,49 @@
+// RUN: %python %S/check_clang_tidy.py %s modernize-loop-convert %t \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.NamingStyle, value: 'UPPER_CASE'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int N = 10;
+int ARR[N];
+int NUMS[N];
+
+void naming() {
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", ARR[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
+  // CHECK-FIXES: for (auto & ELEM : ARR)
+  // CHECK-FIXES-NEXT: printf("%d\n", ELEM);
+
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUM);
+
+  int NUM = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & ELEM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM);
+
+  int ELEM = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUMS_I : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUMS_I + NUM + ELEM);
+
+  int NUMS_I = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUMS_ELEM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I);
+}
Index: test/clang-tidy/modernize-loop-convert-negative.cpp
===
--- test/clang-tidy/modernize-loop-convert-negative.cpp
+++ test/clang-tidy/modernize-loop-convert-negative.cpp
@@ -8,47 +8,47 @@
 namespace Negative {
 
 const int N = 6;
-int arr[N] = {1, 2, 3, 4, 5, 6};
-int (*pArr)[N] = 
+int Arr[N] = {1, 2, 3, 4, 5, 6};
+int (*pArr)[N] = 
 int Sum = 0;
 
 // Checks for the Index start and end:
 void IndexStartAndEnd() {
   for (int I = 0; I < N + 1; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N - 1; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 1; I < N; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 1; I < N; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0;; ++I)
 Sum += (*pArr)[I];
 }
 
 // Checks for invalid increment steps:
 void increment() {
   for (int I = 0; I < N; --I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N; I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N;)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N; I += 2)
 Sum++;
 }
 
 // Checks to make sure that the Index isn't used outside of the array:
 void IndexUse() {
   for (int I = 0; I < N; ++I)
-arr[I] += 1 + I;
+Arr[I] += 1 + I;
 }
 
 // Check for loops that don't mention arrays
@@ -65,30 +65,30 @@
 
 // Checks for incorrect loop variables.
 void mixedVariables() {
-  int badIndex;
-  for (int I = 0; badIndex < N; ++I)
-Sum += arr[I];
+  int BadIndex;
+  for (int I = 0; BadIndex < N; ++I)
+Sum += Arr[I];
 
-  for (int I = 0; I < N; ++badIndex)
-Sum += arr[I];
+  for (int I = 0; I < N; ++BadIndex)
+Sum += Arr[I];
 
-  for (int I = 0; badIndex < N; ++badIndex)
-Sum += arr[I];
+  for (int I = 0; BadIndex < N; ++BadIndex)
+Sum += Arr[I];
 
-  for (int I = 0; badIndex < N; ++badIndex)
-Sum += arr[badIndex];
+  for (int I = 0; BadIndex < N; ++BadIndex)
+Sum += Arr[BadIndex];
 }
 
 // Checks for multiple arrays Indexed.
 void multipleArrays() {
-  int badArr[N];
+  int BadArr[N];
 
   for (int I = 0; I < N; ++I)
-Sum += arr[I] + 

r248480 - [ARM] Follow-up to fix crash "-target arm -mcpu=generic", without "-march="

2015-09-24 Thread Vladimir Sukharev via cfe-commits
Author: vsukharev
Date: Thu Sep 24 05:06:44 2015
New Revision: 248480

URL: http://llvm.org/viewvc/llvm-project?rev=248480=rev
Log:
[ARM] Follow-up to fix crash "-target arm -mcpu=generic", without "-march="

Fix of dangling StringRef after temporary std::string is destroyed

Follow-up to: http://reviews.llvm.org/rL248479

Reviewers: alexfh

Subscribers: cfe-commits


Modified:
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248480=248479=248480=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep 24 05:06:44 2015
@@ -6165,7 +6165,7 @@ StringRef arm::getLLVMArchSuffixForARM(S
const llvm::Triple ) {
   unsigned ArchKind;
   if (CPU == "generic") {
-StringRef ARMArch = tools::arm::getARMArch(Arch, Triple);
+std::string ARMArch = tools::arm::getARMArch(Arch, Triple);
 ArchKind = llvm::ARM::parseArch(ARMArch);
 if (ArchKind == llvm::ARM::AK_INVALID)
   // In case of generic Arch, i.e. "arm",


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


r248481 - [mips] Relax -mnan=2008 acceptance to permit MIPS32R2 and MIPS64R2.

2015-09-24 Thread Daniel Sanders via cfe-commits
Author: dsanders
Date: Thu Sep 24 05:22:17 2015
New Revision: 248481

URL: http://llvm.org/viewvc/llvm-project?rev=248481=rev
Log:
[mips] Relax -mnan=2008 acceptance to permit MIPS32R2 and MIPS64R2.

Summary:
Strictly speaking, the MIPS*R2 ISA's should not permit -mnan=2008 since this
feature was added in MIPS*R3. However, other toolchains permit this and we
should do the same.

Reviewers: atanasyan

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/CodeGen/mips-unsupported-nan.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248481=248480=248481=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep 24 05:22:17 2015
@@ -6191,6 +6191,9 @@ void arm::appendEBLinkFlags(const ArgLis
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef ) {
+  // Strictly speaking, mips32r2 and mips64r2 are NanLegacy-only since Nan2008
+  // was first introduced in Release 3. However, other compilers have
+  // traditionally allowed it for Release 2 so we should do the same.
   return (NanEncoding)llvm::StringSwitch(CPU)
   .Case("mips1", NanLegacy)
   .Case("mips2", NanLegacy)
@@ -6198,12 +6201,12 @@ mips::NanEncoding mips::getSupportedNanE
   .Case("mips4", NanLegacy)
   .Case("mips5", NanLegacy)
   .Case("mips32", NanLegacy)
-  .Case("mips32r2", NanLegacy)
+  .Case("mips32r2", NanLegacy | Nan2008)
   .Case("mips32r3", NanLegacy | Nan2008)
   .Case("mips32r5", NanLegacy | Nan2008)
   .Case("mips32r6", Nan2008)
   .Case("mips64", NanLegacy)
-  .Case("mips64r2", NanLegacy)
+  .Case("mips64r2", NanLegacy | Nan2008)
   .Case("mips64r3", NanLegacy | Nan2008)
   .Case("mips64r5", NanLegacy | Nan2008)
   .Case("mips64r6", Nan2008)

Modified: cfe/trunk/test/CodeGen/mips-unsupported-nan.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips-unsupported-nan.c?rev=248481=248480=248481=diff
==
--- cfe/trunk/test/CodeGen/mips-unsupported-nan.c (original)
+++ cfe/trunk/test/CodeGen/mips-unsupported-nan.c Thu Sep 24 05:22:17 2015
@@ -1,24 +1,44 @@
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips2 -emit-llvm 
-S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS2 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips3 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS3 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips4 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS4 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r2 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R2 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r3 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-NOT-MIPS32R3 
-check-prefix=CHECK-NAN2008 %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r6 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R6 
-check-prefix=CHECK-NAN2008 %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64r2 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R2 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=legacy -march=mips64r6 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R6 
-check-prefix=CHECK-NAN2008 %s
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips2 -emit-llvm 
-S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS2 %s < %t
+//
+// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips3 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS3 %s < %t
+//
+// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips4 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS4 %s < %t
+//
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS32 %s < %t
+//
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 

r248479 - [ARM] Follow-up to fix crash "-target arm -mcpu=generic", without "-march="

2015-09-24 Thread Vladimir Sukharev via cfe-commits
Author: vsukharev
Date: Thu Sep 24 04:55:08 2015
New Revision: 248479

URL: http://llvm.org/viewvc/llvm-project?rev=248479=rev
Log:
[ARM] Follow-up to fix crash "-target arm -mcpu=generic", without "-march="

Fix of dangling StringRef after temporary std::string is destroyed

Follow-up to: http://reviews.llvm.org/rL248370

Reviewers: alexfh

Subscribers: cfe-commits


Modified:
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248479=248478=248479=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep 24 04:55:08 2015
@@ -6164,13 +6164,13 @@ std::string arm::getARMTargetCPU(StringR
 StringRef arm::getLLVMArchSuffixForARM(StringRef CPU, StringRef Arch,
const llvm::Triple ) {
   unsigned ArchKind;
-  Arch = tools::arm::getARMArch(Arch, Triple);
   if (CPU == "generic") {
-ArchKind = llvm::ARM::parseArch(Arch);
+StringRef ARMArch = tools::arm::getARMArch(Arch, Triple);
+ArchKind = llvm::ARM::parseArch(ARMArch);
 if (ArchKind == llvm::ARM::AK_INVALID)
   // In case of generic Arch, i.e. "arm",
   // extract arch from default cpu of the Triple
-  ArchKind = llvm::ARM::parseCPUArch(Triple.getARMCPUForArch(Arch));
+  ArchKind = llvm::ARM::parseCPUArch(Triple.getARMCPUForArch(ARMArch));
   } else {
 ArchKind = llvm::ARM::parseCPUArch(CPU);
   }


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


Re: [PATCH] D13100: [mips] Separated mips specific -Wa options, so that they are not checked on other platforms.

2015-09-24 Thread Daniel Sanders via cfe-commits
dsanders added subscribers: rengolin, joerg.
dsanders added a comment.

+Renato and Joerg

I was going to say I think it's ok and the optimizer should be smart enough to 
factor out the common IsMips check but I've just realized there may be a better 
way. The current code is using an else after an (implicit) continue. If we made 
that continue explicit, we could make this code a bit neater and have a place 
to add target specific options.

I'm thinking something like:

  for (...) {
...
  
auto Arch = C.getDefaultToolChain().getArch();
  
if (C.getDefaultToolChain().getArch() == llvm::Triple::mips ||
C.getDefaultToolChain().getArch() == llvm::Triple::mipsel ||
C.getDefaultToolChain().getArch() == llvm::Triple::mips64 ||
C.getDefaultToolChain().getArch() == llvm::Triple::mips64el)
  if (mips::CollectArgsForIntegratedAssembler(...)
continue;
  
if (Value == "-force_cpusubtype_ALL")
  continue;
  
...
  
D.Diag(diag::err_drv_unsupported_option_argument)
<< A->getOption().getName() << Value;
  }

Thoughts?


http://reviews.llvm.org/D13100



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


[PATCH] D13127: [ARM] Upgrade codegen for vld[234] and vst[234] to to communicate a 0 address space

2015-09-24 Thread Jeroen Ketema via cfe-commits
jketema created this revision.
jketema added a reviewer: sbaranga.
jketema added a subscriber: cfe-commits.
Herald added subscribers: rengolin, aemerson.

This if the clang companion patch for http://reviews.llvm.org/D12985, which 
upgrades the vld[234] and vst[234] to take pointers annotated with an address 
space.

http://reviews.llvm.org/D13127

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/vld_dup.c

Index: test/CodeGen/vld_dup.c
===
--- test/CodeGen/vld_dup.c
+++ test/CodeGen/vld_dup.c
@@ -41,10 +41,10 @@
 // CHECK-NEXT: [[T190:%.*]] = insertvalue { <2 x i32>, <2 x i32>, <2 x i32>, 
<2 x i32> } [[T187]], <2 x i32> [[T189]], 3
 
 v4 = vld3_dup_s64(v6);
-// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64> } 
@llvm.arm.neon.vld3.v1i64(i8* {{.*}}, i32 {{[0-9]+}})
+// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64> } 
@llvm.arm.neon.vld3.v1i64.p0i8(i8* {{.*}}, i32 {{[0-9]+}})
 
 v5 = vld4_dup_s64(v7);
-// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64> } 
@llvm.arm.neon.vld4.v1i64(i8* {{.*}}, i32 {{[0-9]+}})
+// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64> } 
@llvm.arm.neon.vld4.v1i64.p0i8(i8* {{.*}}, i32 {{[0-9]+}})
 
 return 0;
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -2890,7 +2890,8 @@
   case NEON::BI__builtin_neon_vld3q_v:
   case NEON::BI__builtin_neon_vld4_v:
   case NEON::BI__builtin_neon_vld4q_v: {
-Function *F = CGM.getIntrinsic(LLVMIntrinsic, Ty);
+llvm::Type *Tys[] = {Ty, Int8PtrTy};
+Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys);
 Value *Align = getAlignmentValue32(PtrOp1);
 Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, NameHint);
 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
@@ -3019,14 +3020,18 @@
   case NEON::BI__builtin_neon_vshr_n_v:
   case NEON::BI__builtin_neon_vshrq_n_v:
 return EmitNeonRShiftImm(Ops[0], Ops[1], Ty, Usgn, "vshr_n");
-  case NEON::BI__builtin_neon_vst1_v:
-  case NEON::BI__builtin_neon_vst1q_v:
   case NEON::BI__builtin_neon_vst2_v:
   case NEON::BI__builtin_neon_vst2q_v:
   case NEON::BI__builtin_neon_vst3_v:
   case NEON::BI__builtin_neon_vst3q_v:
   case NEON::BI__builtin_neon_vst4_v:
-  case NEON::BI__builtin_neon_vst4q_v:
+  case NEON::BI__builtin_neon_vst4q_v: {
+llvm::Type *Tys[] = {Int8PtrTy, Ty};
+Ops.push_back(getAlignmentValue32(PtrOp0));
+return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "");
+  }
+  case NEON::BI__builtin_neon_vst1_v:
+  case NEON::BI__builtin_neon_vst1q_v:
   case NEON::BI__builtin_neon_vst2_lane_v:
   case NEON::BI__builtin_neon_vst2q_lane_v:
   case NEON::BI__builtin_neon_vst3_lane_v:
@@ -3794,7 +3799,8 @@
 break;
   default: llvm_unreachable("unknown vld_dup intrinsic?");
   }
-  Function *F = CGM.getIntrinsic(Int, Ty);
+  llvm::Type *Tys[] = {Ty, Int8PtrTy};
+  Function *F = CGM.getIntrinsic(Int, Tys);
   llvm::Value *Align = getAlignmentValue32(PtrOp1);
   Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, "vld_dup");
   Ty = llvm::PointerType::getUnqual(Ops[1]->getType());


Index: test/CodeGen/vld_dup.c
===
--- test/CodeGen/vld_dup.c
+++ test/CodeGen/vld_dup.c
@@ -41,10 +41,10 @@
 // CHECK-NEXT: [[T190:%.*]] = insertvalue { <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32> } [[T187]], <2 x i32> [[T189]], 3
 
 v4 = vld3_dup_s64(v6);
-// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld3.v1i64(i8* {{.*}}, i32 {{[0-9]+}})
+// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld3.v1i64.p0i8(i8* {{.*}}, i32 {{[0-9]+}})
 
 v5 = vld4_dup_s64(v7);
-// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld4.v1i64(i8* {{.*}}, i32 {{[0-9]+}})
+// CHECK: {{%.*}} = call { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64> } @llvm.arm.neon.vld4.v1i64.p0i8(i8* {{.*}}, i32 {{[0-9]+}})
 
 return 0;
 }
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -2890,7 +2890,8 @@
   case NEON::BI__builtin_neon_vld3q_v:
   case NEON::BI__builtin_neon_vld4_v:
   case NEON::BI__builtin_neon_vld4q_v: {
-Function *F = CGM.getIntrinsic(LLVMIntrinsic, Ty);
+llvm::Type *Tys[] = {Ty, Int8PtrTy};
+Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys);
 Value *Align = getAlignmentValue32(PtrOp1);
 Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, NameHint);
 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
@@ -3019,14 +3020,18 @@
   case NEON::BI__builtin_neon_vshr_n_v:
   case NEON::BI__builtin_neon_vshrq_n_v:
 return EmitNeonRShiftImm(Ops[0], Ops[1], Ty, Usgn, "vshr_n");
-  case NEON::BI__builtin_neon_vst1_v:
-  case 

Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-09-24 Thread Beren Minor via cfe-commits
berenm added a comment.

Well, the format on save setting is disabled by default, do you mean you had to 
enable it twice? Or you had it enabled without the C++ development tools, and 
after the installation you had to disable and enable it again?


http://reviews.llvm.org/D12407



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


Re: [PATCH] D13122: Enable SafeStack on all Linux platforms

2015-09-24 Thread Alexey Samsonov via cfe-commits
samsonov accepted this revision.
samsonov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

http://reviews.llvm.org/D13122



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


Re: [PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

2015-09-24 Thread Gábor Horváth via cfe-commits
xazax.hun added a comment.

One more note. Do we want to support const_cast for this? A possible way to do 
that is to invalidate this, when a const cast appears in the body of the 
function. (However the body might not be available. It is only my opinion, but 
I would be ok to accept this patch without const cast support, but it is 
something that we might want to document somewhere as a caveat.


http://reviews.llvm.org/D13099



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


Re: [Diffusion] rL248438: Fix loop-convert for trivially copyable types.

2015-09-24 Thread Alexander Kornienko via cfe-commits
alexfh added a subscriber: cfe-commits.
alexfh added a comment.

Test test test.

Let's see how adding subscribers from the comments form in Diffusion works.


/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp:621 
Testtesttest

Users:
  klimek (Author)

http://reviews.llvm.org/rL248438



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


Re: [Diffusion] rL248438: Fix loop-convert for trivially copyable types.

2015-09-24 Thread Alexander Kornienko via cfe-commits
On Thu, Sep 24, 2015 at 10:24 AM, Alexander Kornienko 
wrote:

> alexfh added a subscriber: cfe-commits.
> alexfh added a comment.
>
> Test test test.
>
> Let's see how adding subscribers from the comments form in Diffusion works.
>
>
> /clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp:621
> Testtesttest
>

Is there a Phabricator setting to include some diffs in the Diffusion
comment emails? Otherwise seems to work reasonably well.


>
> Users:
>   klimek (Author)
>
> http://reviews.llvm.org/rL248438
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D13126: New static analyzer checker for loss of sign/precision

2015-09-24 Thread Daniel Marjamäki via cfe-commits
danielmarjamaki created this revision.
danielmarjamaki added a reviewer: zaks.anna.
danielmarjamaki added a subscriber: cfe-commits.

This is a new static analyzer checker that warns when there is loss of sign and 
loss of precision.

It is similar in spirit to Wsign-compare/Wsign-conversion etc. But this checker 
uses proper analysis so the output is much more meaningful.

It has been tested on debian packages.

loss of precision results:
https://drive.google.com/file/d/0BykPmWrCOxt2WFV3NVhJdE94QUE/view
2195 projects, 1026 warnings

loss of sign results:
https://drive.google.com/file/d/0BykPmWrCOxt2cUpSQVlmUVJmR0k/view
2195 projects, 3613 warnigs

It seems to me that this checker shows that Clang does not properly track 
values. It seems to think that result of ! can be negative for instance.


http://reviews.llvm.org/D13126

Files:
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  test/Analysis/conversion.c

Index: test/Analysis/conversion.c
===
--- test/Analysis/conversion.c
+++ test/Analysis/conversion.c
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core.Conversion -Wno-constant-conversion -verify %s
+
+unsigned char U8;
+signed char S8;
+
+void assign(unsigned U, signed S) {
+  if (S < -10)
+U8 = S; // expected-warning {{Implicit conversion changes signedness (negative value)}}
+  if (U > 300)
+S8 = U; // expected-warning {{Loss of precision, value too high}}
+  if (S > 10)
+U8 = S;
+  if (U < 200)
+S8 = U;
+}
+
+void relational(unsigned U, signed S) {
+  if (S > 10) {
+if (U < S) {}
+  }
+  if (S < -10) {
+if (U < S) {} // expected-warning {{Implicit conversion changes signedness (negative value)}}
+  }
+}
+
+void multiplication(unsigned U, signed S) {
+  if (S > 5)
+S = U * S;
+  if (S < -10)
+S = U * S; // expected-warning {{Implicit conversion changes signedness (negative value)}}
+}
+
+void division(unsigned U, signed S) {
+  if (S > 5)
+S = U / S;
+  if (S < -10)
+S = U / S; // expected-warning {{Implicit conversion changes signedness (negative value)}}
+}
+
+void dontwarn1(unsigned U, signed S) {
+  U8 = S; // It might be known that S is always 0x00-0xff.
+  S8 = U; // It might be known that U is always 0x00-0xff.
+
+  U8 = -1; // Explicit conversion.
+  S8 = ~0U; // Explicit conversion.
+  if (U > 300)
+U8 &= U; // No loss of precision since there is &=.
+}
+
+void dontwarn2(int i) {
+  static unsigned char Buf[200] = {200,100,200};
+  int S;
+  for (int i = 0; i < 200; i++) {
+S = Buf[i];  // RHS is smaller than LHS
+  }
+}
+
+void dontwarn3(unsigned int U) {
+  if (U <= 4294967295) {}
+  if (U <= (2147483647 * 2U + 1U)) {}
+}
+
+void dontwarn4(int X) {
+  S8 = X ? 'a' : 'b';
+}
Index: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
@@ -0,0 +1,169 @@
+//=== ConversionChecker.cpp -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This defines ConversionChecker that warns about dangerous conversions where
+// there is possible loss of sign or loss of precision.
+//
+//===--===//
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class ConversionChecker : public Checker {
+  mutable std::unique_ptr BT;
+
+public:
+  void checkPreStmt(const BinaryOperator *B, CheckerContext ) const {
+BinaryOperator::Opcode Opc = B->getOpcode();
+if (Opc == BO_Assign || Opc == BO_MulAssign || Opc == BO_DivAssign) {
+  diagnoseLossOfSign(B, C);
+  diagnoseLossOfPrecision(B, C);
+} else if (B->isRelationalOp() || B->isMultiplicativeOp()) {
+  diagnoseLossOfSign(B, C);
+}
+  }
+
+private:
+  void diagnoseLossOfSign(const BinaryOperator *B, CheckerContext ) const;
+  void diagnoseLossOfPrecision(const BinaryOperator *B,
+   CheckerContext ) const;
+
+  void reportBug(CheckerContext , const char Msg[]) const {
+// Generate an error node.
+ExplodedNode *N = C.generateErrorNode(C.getState());
+if (!N)
+  return;
+
+if (!BT)
+  BT.reset(new BuiltinBug(this, "Conversion", "Loss of sign/precision."));
+
+// 

[PATCH] D13128: Fix backend crash on multiple close of stdout.

2015-09-24 Thread Alexey Bataev via cfe-commits
ABataev created this revision.
ABataev added a reviewer: chandlerc.
ABataev added a subscriber: cfe-commits.

If stdout is used as an output file for several outputs (like dep file, output 
file, etc.) , it causes a crash in llvm::raw_fd_ostream::~raw_fd_ostream(), 
when destructor tries to close file descriptor, which already is closed in 
another stream.
Here is the part of the code where it happens:
```
raw_fd_ostream::~raw_fd_ostream() {
  if (FD >= 0) {
flush();
if (ShouldClose && sys::Process::SafelyCloseFileDescriptor(FD))
  error_detected();
  }
...
  if (has_error())
report_fatal_error("IO failure on output stream.", /*GenCrashDiag=*/false);
}
```
if stdout is already closed sys::Process::SafelyCloseFileDescriptor() cannot 
close stdout for the second time and an error flag is set for the stream. It 
makes the destructor to emit `IO failure on output stream.` fatal error message.
Patch closes such streams manually and then clears (possibly set) error flags 
for the stream.

http://reviews.llvm.org/D13128

Files:
  include/clang/Frontend/CompilerInstance.h
  lib/Frontend/CompilerInstance.cpp
  test/Frontend/empty.cpp

Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -531,6 +531,12 @@
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
   for (OutputFile  : OutputFiles) {
 // Manually close the stream before we rename it.
+if (OF.OS && OF.ShouldClose) {
+  // Close the stream and clear error state for stdout.
+  auto *Stream = static_cast(OF.OS.get());
+  Stream->close();
+  Stream->clear_error();
+}
 OF.OS.reset();
 
 if (!OF.TempFilename.empty()) {
@@ -555,6 +561,11 @@
 
   }
   OutputFiles.clear();
+  if (NonSeekStream) {
+// Close the stream and clear error state for stdout.
+NonSeekStream->close();
+NonSeekStream->clear_error();
+  }
   NonSeekStream.reset();
 }
 
@@ -593,7 +604,8 @@
   // Add the output file -- but don't try to remove "-", since this means we 
are
   // using stdin.
   addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "",
-   TempPathName, std::move(OS)));
+   TempPathName, std::move(OS),
+   OutputPathName == "-" && !Binary));
 
   return Ret;
 }
Index: include/clang/Frontend/CompilerInstance.h
===
--- include/clang/Frontend/CompilerInstance.h
+++ include/clang/Frontend/CompilerInstance.h
@@ -153,14 +153,17 @@
 std::string Filename;
 std::string TempFilename;
 std::unique_ptr OS;
+/// \brief true if the file stream should be closed before to be destroyed.
+bool ShouldClose;
 
 OutputFile(std::string filename, std::string tempFilename,
-   std::unique_ptr OS)
+   std::unique_ptr OS, bool ShouldClose = false)
 : Filename(std::move(filename)), TempFilename(std::move(tempFilename)),
-  OS(std::move(OS)) {}
+  OS(std::move(OS)), ShouldClose(ShouldClose) {}
 OutputFile(OutputFile &)
 : Filename(std::move(O.Filename)),
-  TempFilename(std::move(O.TempFilename)), OS(std::move(O.OS)) {}
+  TempFilename(std::move(O.TempFilename)), OS(std::move(O.OS)),
+  ShouldClose(O.ShouldClose) {}
   };
 
   /// If the output doesn't support seeking (terminal, pipe). we switch
Index: test/Frontend/empty.cpp
===
--- test/Frontend/empty.cpp
+++ test/Frontend/empty.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -verify %s -x c++ -triple x86_64-unknown-linux-gnu 
-dependency-file - -MT - -emit-llvm -o - | FileCheck %s
+// Check that no additional error messages are generated.
+int main() {
+  return; // expected-error {{non-void function 'main' should return a value}}
+}
+// CHECK: -:


Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -531,6 +531,12 @@
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
   for (OutputFile  : OutputFiles) {
 // Manually close the stream before we rename it.
+if (OF.OS && OF.ShouldClose) {
+  // Close the stream and clear error state for stdout.
+  auto *Stream = static_cast(OF.OS.get());
+  Stream->close();
+  Stream->clear_error();
+}
 OF.OS.reset();
 
 if (!OF.TempFilename.empty()) {
@@ -555,6 +561,11 @@
 
   }
   OutputFiles.clear();
+  if (NonSeekStream) {
+// Close the stream and clear error state for stdout.
+NonSeekStream->close();
+NonSeekStream->clear_error();
+  }
   NonSeekStream.reset();
 }
 
@@ -593,7 +604,8 @@
   // Add the output file -- but don't try to remove "-", since this means we are
   // using stdin.
   

Re: [PATCH] D13100: [mips] Separated mips specific -Wa options, so that they are not checked on other platforms.

2015-09-24 Thread Joerg Sonnenberger via cfe-commits
On Thu, Sep 24, 2015 at 10:22:29AM +, Daniel Sanders via cfe-commits wrote:
> I'm thinking something like:

I think we really want to have an outer case, platform specific -Wa
options are quite common. Only x86 is mostly getting by without them so
far. I also think the switch is not that difficult to read.

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


[PATCH] D13129: Solve comment on rL248418.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: klimek, cfe-commits.

Solve comment on rL248418.

http://reviews.llvm.org/D13129

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp

Index: clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tidy/modernize/LoopConvertCheck.cpp
@@ -394,9 +394,7 @@
 // If VDec is a reference to a container, Dereference is false,
 // but we still need to check the const-ness of the underlying container
 // type.
-if (const auto  = CType->getAs()) {
-  CType = RT->getPointeeType();
-}
+CType = CType.getNonReferenceType();
 return CType.isConstQualified();
   }
   return false;


Index: clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tidy/modernize/LoopConvertCheck.cpp
@@ -394,9 +394,7 @@
 // If VDec is a reference to a container, Dereference is false,
 // but we still need to check the const-ness of the underlying container
 // type.
-if (const auto  = CType->getAs()) {
-  CType = RT->getPointeeType();
-}
+CType = CType.getNonReferenceType();
 return CType.isConstQualified();
   }
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [Diffusion] rL248438: Fix loop-convert for trivially copyable types.

2015-09-24 Thread Manuel Klimek via cfe-commits
The biggest problem is that those comments don't go on the cfe-commmits
thread that gets auto-triggered by commits, and we really want to not add
new threads.

On Thu, Sep 24, 2015 at 4:28 AM Alexander Kornienko 
wrote:

> alexfh added inline comments.
>
> /clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp:573
> test6
> /clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp:509
> test5
>
> Users:
>   klimek (Author)
>
> http://reviews.llvm.org/rL248438
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [Diffusion] rL248418: Fix loop-convert for const references to containers.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia added a comment.

I sent a patch with that.


Users:
  klimek (Author)

http://reviews.llvm.org/rL248418



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


Re: [PATCH] D13128: Fix backend crash on multiple close of stdout.

2015-09-24 Thread Yaron Keren via cfe-commits
yaron.keren added a subscriber: yaron.keren.
yaron.keren added a comment.

When stdout goes elsewhere the console, the shell creates the the output file 
(pipe) and will close it when clang terminates so  so why clang should close it 
at  all ? it did not open it.

Practically, we have been running locally

  Error(false), UseAtomicWrites(false) {
  if (FD < 0 ) {
ShouldClose = false;
return;
  }
  if (FD <= STDERR_FILENO)
ShouldClose = false;

and passing regression tests on Windows 7 and Linux, maybe this is required on 
other usage scenarios or OS.


http://reviews.llvm.org/D13128



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


Re: [PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

2015-09-24 Thread Gábor Horváth via cfe-commits
xazax.hun added a comment.

A general style comment: you could decrease the level of indentation using 
early returns. I have one more comment inline, otherwise it looks good to me.



Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:422
@@ +421,3 @@
+  // Check if this is a call to a const method.
+  if (const CXXMethodDecl *D = cast_or_null(getDecl())) {
+if(D->isConst()) {

Does this check work for member operators? I wonder what is the reason that 
getDecl returns a FunctionDecl instead of CXXMethodDecl. 


http://reviews.llvm.org/D13099



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


[PATCH] D13133: Remove dangling parenthesis.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: klimek, cfe-commits.

Remove parenthesis surrounding the new loop index.

http://reviews.llvm.org/D13133

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -267,16 +267,16 @@
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & MAXs_it : MAXs)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (MAXs_it).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", MAXs_it.x);
   // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
 
   for (S::const_iterator it = MAXs.begin(), e = MAXs.end(); it != e; ++it) {
 printf("s has value %d\n", (*it).x);
 printf("Max of 3 and 5: %d\n", MAX(3, 5));
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto MAXs_it : MAXs)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (MAXs_it).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", MAXs_it.x);
   // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
 
   T DEFs;
@@ -307,7 +307,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & __FUNCTION__s_elem : __FUNCTION__s)
-  // CHECK-FIXES-NEXT: int __FUNCTION__s_it = (__FUNCTION__s_elem).x + 2;
+  // CHECK-FIXES-NEXT: int __FUNCTION__s_it = __FUNCTION__s_elem.x + 2;
 }
 
 void typeConflict() {
@@ -457,7 +457,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : NestT)
-  // CHECK-FIXES-NEXT: for (T::iterator TI = (elem).begin(), TE = (elem).end(); TI != TE; ++TI)
+  // CHECK-FIXES-NEXT: for (T::iterator TI = elem.begin(), TE = elem.end(); TI != TE; ++TI)
   // CHECK-FIXES-NEXT: printf("%d", *TI);
 
   // The inner loop is also convertible.
@@ -469,7 +469,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto elem : NestS)
-  // CHECK-FIXES-NEXT: for (S::const_iterator SI = (elem).begin(), SE = (elem).end(); SI != SE; ++SI)
+  // CHECK-FIXES-NEXT: for (S::const_iterator SI = elem.begin(), SE = elem.end(); SI != SE; ++SI)
   // CHECK-FIXES-NEXT: printf("%d", *SI);
 
   for (Nested::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
@@ -557,15 +557,15 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   S *ps;
   for (S::iterator it = ps->begin(); it != ps->end(); ++it) {
 printf("s has value %d\n", (*it).x);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & p : *ps)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (p).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", p.x);
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
 printf("s has value %d\n", it->x);
@@ -586,7 +586,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: (elem).x = 3;
+  // CHECK-FIXES-NEXT: elem.x = 3;
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
 it->nonConstFun(4, 5);
@@ -608,7 +608,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : u)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   U::iterator A;
   for (U::iterator i = u.begin(); i != u.end(); ++i)
@@ -656,15 +656,15 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto elem : s)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   S *ps;
   for (S::const_iterator it = ps->begin(); it != ps->end(); ++it) {
 printf("s has value %d\n", (*it).x);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto p : *ps)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (p).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", p.x);
 
   // v.begin() returns a user-defined type 'iterator' which, since it's
   // different from const_iterator, disqualifies these loops from
Index: test/clang-tidy/modernize-loop-convert-basic.cpp
===
--- 

Re: [PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

2015-09-24 Thread Sean Eveson via cfe-commits
seaneveson updated this revision to Diff 35617.
seaneveson added a comment.

Removed unnecessary call to getCanonical.
Changed if statement checking getting ThisRegion to an assert.
Added code to handle mutable members of base classes.


http://reviews.llvm.org/D13099

Files:
  lib/StaticAnalyzer/Core/CallEvent.cpp
  test/Analysis/PR21606.cpp
  test/Analysis/method-call.cpp

Index: test/Analysis/method-call.cpp
===
--- test/Analysis/method-call.cpp
+++ test/Analysis/method-call.cpp
@@ -13,6 +13,25 @@
   int x;
 };
 
+struct C {
+  int x;
+  void foo() const;
+  void bar();
+};
+
+struct D {
+  mutable int x;
+  void foo() const;
+};
+
+struct Base {
+  mutable int x;
+};
+
+struct Derived : Base {
+  void foo() const;
+};
+
 void testNullObject(A *a) {
   clang_analyzer_eval(a); // expected-warning{{UNKNOWN}}
   (void)a->getx(); // assume we know what we're doing
@@ -45,3 +64,27 @@
   B t2(t);
   clang_analyzer_eval(t.x == 0); // expected-warning{{TRUE}}
 }
+
+void checkThatConstMethodWithoutDefinitionDoesNotInvalidateObject() {
+  C t;
+  t.x = 3;
+  t.foo();
+  clang_analyzer_eval(t.x == 3); // expected-warning{{TRUE}}
+  // Test non-const does invalidate
+  t.bar();
+  clang_analyzer_eval(t.x); // expected-warning{{UNKNOWN}}
+}
+
+void checkThatConstMethodDoesInvalidateMutableFields() {
+  D t;
+  t.x = 3;
+  t.foo();
+  clang_analyzer_eval(t.x); // expected-warning{{UNKNOWN}}
+}
+
+void checkThatConstMethodDoesInvalidateInheritedMutableFields() {
+  Derived t;
+  t.x = 3;
+  t.foo();
+  clang_analyzer_eval(t.x); // expected-warning{{UNKNOWN}}
+}
Index: test/Analysis/PR21606.cpp
===
--- test/Analysis/PR21606.cpp
+++ test/Analysis/PR21606.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core
+// PR21606
+
+struct s1 {
+void g(const int *i) const;
+};
+
+struct s2 {
+void f(int *i) {
+m_i = i;
+m_s.g(m_i);
+if (m_i)
+*i = 42; // no-warning
+}
+
+int *m_i;
+s1 m_s;
+};
+
+int main()
+{
+s2().f(0);
+}
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -403,7 +403,40 @@
   return getSVal(CE->getCallee()).getAsFunctionDecl();
 }
 
+/// Get all mutable fields of Record and its base classes.
+static void getMutableFields(const CXXRecordDecl *Record,
+ SmallVector ) {
+  if (Record == nullptr)
+return;
+  for (auto F : Record->fields()) {
+if (F->isMutable())
+  MutFields.push_back(F);
+  }
+  for (auto C : Record->bases()) {
+getMutableFields(C.getType()->getAsCXXRecordDecl(), MutFields);
+  }
+}
+
 void CXXInstanceCall::getExtraInvalidatedValues(ValueList ) const {
+  // Check if this is a call to a const method.
+  if (const CXXMethodDecl *D = cast_or_null(getDecl())) {
+if(D->isConst()) {
+  // Get any mutable members and invalidate them.
+  SmallVector MutableFields;
+  getMutableFields(D->getParent(), MutableFields);
+  if (!MutableFields.empty()) {
+const MemRegion *ThisRegion = getCXXThisVal().getAsRegion();
+assert(ThisRegion && "CXXThisVal was not a region");
+MemRegionManager *MemMgr = ThisRegion->getMemRegionManager();
+for (auto it = MutableFields.begin(), end = MutableFields.end();
+ it != end; ++it) {
+  const FieldRegion *FR = MemMgr->getFieldRegion(*it, ThisRegion);
+  Values.push_back(loc::MemRegionVal(FR));
+}
+  }
+  return;
+}
+  }
   Values.push_back(getCXXThisVal());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13128: Fix backend crash on multiple close of stdout.

2015-09-24 Thread Alexey Bataev via cfe-commits
ABataev added a comment.

In http://reviews.llvm.org/D13128#252630, @yaron.keren wrote:

> When stdout goes elsewhere the console, the shell creates the the output file 
> (pipe) and will close it when clang terminates so  so why clang should close 
> it at  all ? it did not open it.
>
> Practically, we have been running locally
>
>   Error(false), UseAtomicWrites(false) {
>   if (FD < 0 ) {
> ShouldClose = false;
> return;
>   }
>   if (FD <= STDERR_FILENO)
> ShouldClose = false;
>   
>
> and passing regression tests on Windows 7 and Linux, maybe this is required 
> on other usage scenarios or OS.


I thought about it. The problem is that few lines above there is a comment (in 
getFD()):

  // Handle "-" as stdout. Note that when we do this, we consider ourself
  // the owner of stdout. This means that we can do things like close the
  // file descriptor when we're done and set the "binary" flag globally.

and all such stream are created with ShouldClose flag explicitly set to `true`. 
Should we remove all this stuff?


http://reviews.llvm.org/D13128



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


r248496 - Drop useless const in for-range loops.

2015-09-24 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Thu Sep 24 09:48:49 2015
New Revision: 248496

URL: http://llvm.org/viewvc/llvm-project?rev=248496=rev
Log:
Drop useless const in for-range loops.

StringRefs always point to immutable memory so the const doesn't add value
here. Also quiets clang's -Wrange-loop-analysis which warns about the implicit
copying.

Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=248496=248495=248496=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Sep 24 09:48:49 2015
@@ -215,7 +215,7 @@ DerivedArgList *Driver::TranslateInputAr
   DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_Xlinker__no_demangle));
 
   // Add the remaining values as Xlinker arguments.
-  for (const StringRef Val : A->getValues())
+  for (StringRef Val : A->getValues())
 if (Val != "--no-demangle")
   DAL->AddSeparateArg(A, Opts->getOption(options::OPT_Xlinker), Val);
 
@@ -259,7 +259,7 @@ DerivedArgList *Driver::TranslateInputAr
 // Pick up inputs via the -- option.
 if (A->getOption().matches(options::OPT__DASH_DASH)) {
   A->claim();
-  for (const StringRef Val : A->getValues())
+  for (StringRef Val : A->getValues())
 DAL->append(MakeInputArg(*DAL, Opts, Val));
   continue;
 }

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=248496=248495=248496=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Sep 24 09:48:49 2015
@@ -1213,20 +1213,20 @@ void Generic_GCC::GCCInstallationDetecto
   for (const std::string  : Prefixes) {
 if (!llvm::sys::fs::exists(Prefix))
   continue;
-for (const StringRef Suffix : CandidateLibDirs) {
+for (StringRef Suffix : CandidateLibDirs) {
   const std::string LibDir = Prefix + Suffix.str();
   if (!llvm::sys::fs::exists(LibDir))
 continue;
-  for (const StringRef Candidate : ExtraTripleAliases) // Try these first.
+  for (StringRef Candidate : ExtraTripleAliases) // Try these first.
 ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
-  for (const StringRef Candidate : CandidateTripleAliases)
+  for (StringRef Candidate : CandidateTripleAliases)
 ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
 }
-for (const StringRef Suffix : CandidateBiarchLibDirs) {
+for (StringRef Suffix : CandidateBiarchLibDirs) {
   const std::string LibDir = Prefix + Suffix.str();
   if (!llvm::sys::fs::exists(LibDir))
 continue;
-  for (const StringRef Candidate : CandidateBiarchTripleAliases)
+  for (StringRef Candidate : CandidateBiarchTripleAliases)
 ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate,
/*NeedsBiarchSuffix=*/ true);
 }
@@ -3091,7 +3091,7 @@ static Distro DetectDistro(llvm::Triple:
 SmallVector Lines;
 Data.split(Lines, "\n");
 Distro Version = UnknownDistro;
-for (const StringRef Line : Lines)
+for (StringRef Line : Lines)
   if (Version == UnknownDistro && Line.startswith("DISTRIB_CODENAME="))
 Version = llvm::StringSwitch(Line.substr(17))
   .Case("hardy", UbuntuHardy)

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248496=248495=248496=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep 24 09:48:49 2015
@@ -1935,7 +1935,7 @@ static bool DecodeAArch64Features(const
   SmallVector Split;
   text.split(Split, StringRef("+"), -1, false);
 
-  for (const StringRef Feature : Split) {
+  for (StringRef Feature : Split) {
 const char *result = llvm::StringSwitch(Feature)
  .Case("fp", "+fp-armv8")
  .Case("simd", "+neon")
@@ -2344,7 +2344,7 @@ static void CollectArgsForIntegratedAsse
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
 A->claim();
 
-for (const StringRef Value : A->getValues()) {
+for (StringRef Value : A->getValues()) {
   if (TakeNextArg) {
 CmdArgs.push_back(Value.data());
 TakeNextArg = false;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
URL: 

Re: [PATCH] D12571: [Analyzer] Fix assertions in commit r246345 (pr22954).

2015-09-24 Thread pierre gousseau via cfe-commits
pgousseau added a comment.

In http://reviews.llvm.org/D12571#252366, @dcoughlin wrote:

> Looks good to me! Thanks Pierre! I will commit.


Much appreciated thanks !


http://reviews.llvm.org/D12571



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


Re: [PATCH] D13133: Remove dangling parenthesis.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 35629.
angelgarcia added a comment.

Add comment.


http://reviews.llvm.org/D13133

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -267,16 +267,16 @@
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & MAXs_it : MAXs)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (MAXs_it).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", MAXs_it.x);
   // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
 
   for (S::const_iterator it = MAXs.begin(), e = MAXs.end(); it != e; ++it) {
 printf("s has value %d\n", (*it).x);
 printf("Max of 3 and 5: %d\n", MAX(3, 5));
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto MAXs_it : MAXs)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (MAXs_it).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", MAXs_it.x);
   // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
 
   T DEFs;
@@ -307,7 +307,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & __FUNCTION__s_elem : __FUNCTION__s)
-  // CHECK-FIXES-NEXT: int __FUNCTION__s_it = (__FUNCTION__s_elem).x + 2;
+  // CHECK-FIXES-NEXT: int __FUNCTION__s_it = __FUNCTION__s_elem.x + 2;
 }
 
 void typeConflict() {
@@ -457,7 +457,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : NestT)
-  // CHECK-FIXES-NEXT: for (T::iterator TI = (elem).begin(), TE = (elem).end(); TI != TE; ++TI)
+  // CHECK-FIXES-NEXT: for (T::iterator TI = elem.begin(), TE = elem.end(); TI != TE; ++TI)
   // CHECK-FIXES-NEXT: printf("%d", *TI);
 
   // The inner loop is also convertible.
@@ -469,7 +469,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto elem : NestS)
-  // CHECK-FIXES-NEXT: for (S::const_iterator SI = (elem).begin(), SE = (elem).end(); SI != SE; ++SI)
+  // CHECK-FIXES-NEXT: for (S::const_iterator SI = elem.begin(), SE = elem.end(); SI != SE; ++SI)
   // CHECK-FIXES-NEXT: printf("%d", *SI);
 
   for (Nested::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
@@ -557,15 +557,15 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   S *ps;
   for (S::iterator it = ps->begin(); it != ps->end(); ++it) {
 printf("s has value %d\n", (*it).x);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & p : *ps)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (p).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", p.x);
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
 printf("s has value %d\n", it->x);
@@ -586,7 +586,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: (elem).x = 3;
+  // CHECK-FIXES-NEXT: elem.x = 3;
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
 it->nonConstFun(4, 5);
@@ -608,7 +608,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : u)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   U::iterator A;
   for (U::iterator i = u.begin(); i != u.end(); ++i)
@@ -656,15 +656,15 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto elem : s)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   S *ps;
   for (S::const_iterator it = ps->begin(); it != ps->end(); ++it) {
 printf("s has value %d\n", (*it).x);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto p : *ps)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (p).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", p.x);
 
   // v.begin() returns a user-defined type 'iterator' which, since it's
   // different from const_iterator, disqualifies these loops from
Index: test/clang-tidy/modernize-loop-convert-basic.cpp
===
--- test/clang-tidy/modernize-loop-convert-basic.cpp
+++ 

Re: [PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 35630.
angelgarcia added a comment.

Done!


http://reviews.llvm.org/D13052

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/modernize/LoopConvertCheck.h
  clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tidy/modernize/LoopConvertUtils.h
  clang-tidy/modernize/ModernizeTidyModule.cpp
  test/clang-tidy/Inputs/modernize-loop-convert/structures.h
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-camelback.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp
  test/clang-tidy/modernize-loop-convert-lowercase.cpp
  test/clang-tidy/modernize-loop-convert-negative.cpp
  test/clang-tidy/modernize-loop-convert-uppercase.cpp

Index: test/clang-tidy/modernize-loop-convert-uppercase.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-loop-convert-uppercase.cpp
@@ -0,0 +1,65 @@
+// RUN: %python %S/check_clang_tidy.py %s modernize-loop-convert %t \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.NamingStyle, value: 'UPPER_CASE'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int N = 10;
+int ARR[N];
+int NUMS[N];
+
+void naming() {
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", ARR[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
+  // CHECK-FIXES: for (auto & ELEM : ARR)
+  // CHECK-FIXES-NEXT: printf("%d\n", ELEM);
+
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUM);
+
+  int NUM = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & ELEM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM);
+
+  int ELEM = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUMS_I : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUMS_I + NUM + ELEM);
+
+  int NUMS_I = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUMS_ELEM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I);
+
+  int NUMS_ELEM = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & GIVE_ME_NAME_0 : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + NUM + ELEM + NUMS_I + NUMS_ELEM);
+
+  int GIVE_ME_NAME_0 = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & GIVE_ME_NAME_1 : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
+}
Index: test/clang-tidy/modernize-loop-convert-negative.cpp
===
--- test/clang-tidy/modernize-loop-convert-negative.cpp
+++ test/clang-tidy/modernize-loop-convert-negative.cpp
@@ -8,47 +8,47 @@
 namespace Negative {
 
 const int N = 6;
-int arr[N] = {1, 2, 3, 4, 5, 6};
-int (*pArr)[N] = 
+int Arr[N] = {1, 2, 3, 4, 5, 6};
+int (*pArr)[N] = 
 int Sum = 0;
 
 // Checks for the Index start and end:
 void IndexStartAndEnd() {
   for (int I = 0; I < N + 1; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N - 1; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 1; I < N; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 1; I < N; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0;; ++I)
 Sum += (*pArr)[I];
 }
 
 // Checks for invalid increment steps:
 void increment() {
   for (int I = 0; I < N; --I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N; I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N;)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N; I += 2)
 Sum++;
 }
 
 // Checks to make sure that the Index isn't used outside of the array:
 void IndexUse() {
   for (int I = 0; I < N; ++I)
-arr[I] += 1 + I;
+Arr[I] += 1 + I;
 }
 
 // Check for loops that don't mention arrays
@@ -65,30 +65,30 @@
 
 // Checks for incorrect loop variables.
 void mixedVariables() {
-  int badIndex;
-  for (int I = 0; badIndex < N; ++I)
-Sum += arr[I];
+  int BadIndex;
+  for (int I = 0; BadIndex < N; ++I)
+Sum += 

Re: [PATCH] D13128: Fix backend crash on multiple close of stdout.

2015-09-24 Thread Yaron Keren via cfe-commits
yaron.keren added a subscriber: sunfish.
yaron.keren added a comment.

The original commit 
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20100816/106268.html 
by Dan Ghoman says:

"Make raw_fd_ostream consider itself the owner of STDOUT_FILENO when
constructed with an output filename of "-". In particular, allow the
file descriptor to be closed, and close the file descriptor in the
destructor if it hasn't been explicitly closed already, to ensure
that any write errors are detected."

Closing stdout causes not only this problem in the 2nd close (which may be 
worked around) but potentially losing text output depending on who gets to 
close the stream first. Is it normal behaviour for console programs to close 
their stdout?


http://reviews.llvm.org/D13128



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


Re: [PATCH] D13133: Remove dangling parenthesis.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 35626.
angelgarcia added a comment.

Added a test where the parenthesis must not be removed, and one where they 
should.


http://reviews.llvm.org/D13133

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -267,16 +267,16 @@
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & MAXs_it : MAXs)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (MAXs_it).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", MAXs_it.x);
   // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
 
   for (S::const_iterator it = MAXs.begin(), e = MAXs.end(); it != e; ++it) {
 printf("s has value %d\n", (*it).x);
 printf("Max of 3 and 5: %d\n", MAX(3, 5));
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto MAXs_it : MAXs)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (MAXs_it).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", MAXs_it.x);
   // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
 
   T DEFs;
@@ -307,7 +307,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & __FUNCTION__s_elem : __FUNCTION__s)
-  // CHECK-FIXES-NEXT: int __FUNCTION__s_it = (__FUNCTION__s_elem).x + 2;
+  // CHECK-FIXES-NEXT: int __FUNCTION__s_it = __FUNCTION__s_elem.x + 2;
 }
 
 void typeConflict() {
@@ -457,7 +457,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : NestT)
-  // CHECK-FIXES-NEXT: for (T::iterator TI = (elem).begin(), TE = (elem).end(); TI != TE; ++TI)
+  // CHECK-FIXES-NEXT: for (T::iterator TI = elem.begin(), TE = elem.end(); TI != TE; ++TI)
   // CHECK-FIXES-NEXT: printf("%d", *TI);
 
   // The inner loop is also convertible.
@@ -469,7 +469,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto elem : NestS)
-  // CHECK-FIXES-NEXT: for (S::const_iterator SI = (elem).begin(), SE = (elem).end(); SI != SE; ++SI)
+  // CHECK-FIXES-NEXT: for (S::const_iterator SI = elem.begin(), SE = elem.end(); SI != SE; ++SI)
   // CHECK-FIXES-NEXT: printf("%d", *SI);
 
   for (Nested::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
@@ -557,15 +557,15 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   S *ps;
   for (S::iterator it = ps->begin(); it != ps->end(); ++it) {
 printf("s has value %d\n", (*it).x);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & p : *ps)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (p).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", p.x);
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
 printf("s has value %d\n", it->x);
@@ -586,7 +586,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: (elem).x = 3;
+  // CHECK-FIXES-NEXT: elem.x = 3;
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
 it->nonConstFun(4, 5);
@@ -608,7 +608,7 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : u)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   U::iterator A;
   for (U::iterator i = u.begin(); i != u.end(); ++i)
@@ -656,15 +656,15 @@
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto elem : s)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   S *ps;
   for (S::const_iterator it = ps->begin(); it != ps->end(); ++it) {
 printf("s has value %d\n", (*it).x);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto p : *ps)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (p).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", p.x);
 
   // v.begin() returns a user-defined type 'iterator' which, since it's
   // different from const_iterator, disqualifies these loops from
Index: test/clang-tidy/modernize-loop-convert-basic.cpp
===
--- 

Re: [PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-24 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good with a comment. Thank you!



Comment at: test/clang-tidy/modernize-loop-convert-uppercase.cpp:48
@@ +47,3 @@
+  // CHECK-FIXES: for (auto & NUMS_ELEM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I);
+}

Please add a test for GIVE_ME_NAME_{0,1}. Same for other styles.


http://reviews.llvm.org/D13052



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


r248495 - [Driver] Don't implicitly copy std::strings in for-range loop.

2015-09-24 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Thu Sep 24 09:48:37 2015
New Revision: 248495

URL: http://llvm.org/viewvc/llvm-project?rev=248495=rev
Log:
[Driver] Don't implicitly copy std::strings in for-range loop.

Found by -Wrange-loop-analysis.

Modified:
cfe/trunk/lib/Driver/ToolChains.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=248495=248494=248495=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Sep 24 09:48:37 2015
@@ -1497,7 +1497,7 @@ Generic_GCC::CudaInstallationDetector::i
 CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0");
   }
 
-  for (const auto CudaPath : CudaPathCandidates) {
+  for (const auto  : CudaPathCandidates) {
 if (CudaPath.empty() || !llvm::sys::fs::exists(CudaPath))
   continue;
 


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


Re: [PATCH] D13133: Remove dangling parenthesis.

2015-09-24 Thread Angel Garcia via cfe-commits
angelgarcia added a comment.

Usage.Expression can be:
-CXXMemberCallExpr: "container.at(i)"
-CXXOperatorCallExpr: "*it" or "container[i]"
-ArraySubscripExpr: "Arr[i]"
-UnaryOperator: "*ptr"
-MemberExpr: "it->member" (we only replace "it->" with "elem." in this
case).

The point is that all of them except the last one will be replaced by
"elem" (or any other identifier), so it will be a DeclRefExpr after the
change, and the parenthesis can always be removed. I can add a comment
explaining this.


http://reviews.llvm.org/D13133



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


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-24 Thread Richard Barton via cfe-commits
richard.barton.arm added inline comments.


Comment at: lib/Frontend/CompilerInvocation.cpp:1711
@@ -1710,1 +1710,3 @@
   Args.hasArg(OPT_cl_fast_relaxed_math);
+  Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
+  Args.hasArg(OPT_cl_unsafe_math_optimizations) ||

What happens if I do -menable-unsafe-fp-math then -mno-enable-unsafe-fp-math? I 
don't think you have enough regression tests.


http://reviews.llvm.org/D12633



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


Re: [Diffusion] rL248438: Fix loop-convert for trivially copyable types.

2015-09-24 Thread Alexander Kornienko via cfe-commits
Too bad. Making these two kinds of mails go to the same thread is hardly a
trivial thing. And completely switching commit notifications to Phabricator
is something not very realistic, I guess (at least, at this point).

Giving up.

On Thu, Sep 24, 2015 at 3:24 PM, Manuel Klimek  wrote:

> The biggest problem is that those comments don't go on the cfe-commmits
> thread that gets auto-triggered by commits, and we really want to not add
> new threads.
>
> On Thu, Sep 24, 2015 at 4:28 AM Alexander Kornienko 
> wrote:
>
>> alexfh added inline comments.
>>
>> /clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp:573
>> test6
>> /clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp:509
>> test5
>>
>> Users:
>>   klimek (Author)
>>
>> http://reviews.llvm.org/rL248438
>>
>>
>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [Diffusion] rL248438: Fix loop-convert for trivially copyable types.

2015-09-24 Thread Manuel Klimek via cfe-commits
Yep, as I said, I would love to do that, but it would require significant
effort :(

On Thu, Sep 24, 2015 at 7:03 AM Alexander Kornienko 
wrote:

> Too bad. Making these two kinds of mails go to the same thread is hardly a
> trivial thing. And completely switching commit notifications to Phabricator
> is something not very realistic, I guess (at least, at this point).
>
> Giving up.
>
>
> On Thu, Sep 24, 2015 at 3:24 PM, Manuel Klimek  wrote:
>
>> The biggest problem is that those comments don't go on the cfe-commmits
>> thread that gets auto-triggered by commits, and we really want to not add
>> new threads.
>>
>> On Thu, Sep 24, 2015 at 4:28 AM Alexander Kornienko 
>> wrote:
>>
>>> alexfh added inline comments.
>>>
>>> /clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp:573
>>> test6
>>> /clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp:509
>>> test5
>>>
>>> Users:
>>>   klimek (Author)
>>>
>>> http://reviews.llvm.org/rL248438
>>>
>>>
>>>
>>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13133: Remove dangling parenthesis.

2015-09-24 Thread Manuel Klimek via cfe-commits
klimek added a comment.

Can you add a test where we need the parens? (where the element is of ** type 
or something)


http://reviews.llvm.org/D13133



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


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-24 Thread Alexandros Lamprineas via cfe-commits
labrinea updated this revision to Diff 35628.
labrinea added a comment.

@t.p.northover I think we should not be defining _ARM_FP_FENV_ROUNDING on 
neither of ARM and AArch64 targets since "-frounding-math" is not available on 
clang: clang/llvm don't support C99 FP rounding mode pragmas (FENV_ACCESS etc) 


@rengolin Clang translates frontend GCC compliant flags to cc1 flags:

- -fno-honor-infinities => -menable-no-infs
- -fno-honor-nans => -menable-no-nans
- AND( -fassociative-math, -freciprocal-math, -fno-signed-zeros, 
-fno-trapping-math, -fno-math-errno ) => -menable-unsafe-fp-math

Those flags seem to affect an LLVM IR in two ways:

- function attributes (no-infs-fp-math = yes|no, no-nans-fp-math = yes|no, 
unsafe-fp-math = yes|no)
- fast-math flags used with generated fp-math operators (this doc summarizes 
the LLVM-IR fast-math flags )

I think we should not be checking **Opts.FiniteMathOnly** since it only 
indicates whether optimizations assume the arguments and result to be +/-inf. 
We should not be checking **Opts.FastMath** either since it might be the case 
where //-menable-unsafe-fp-math// is set but //-ffast-math// is not set. Then 
the user would rely on _ARM_FP_FAST being absent but in reality the backend 
would emit unsafe fp math IR. My patch introduces a new lang option to handle 
this case.


http://reviews.llvm.org/D12633

Files:
  include/clang/Basic/LangOptions.def
  lib/Basic/Targets.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Preprocessor/aarch64-target-features.c
  test/Preprocessor/arm-target-features.c

Index: test/Preprocessor/arm-target-features.c
===
--- test/Preprocessor/arm-target-features.c
+++ test/Preprocessor/arm-target-features.c
@@ -32,6 +32,7 @@
 // CHECK-V8-BAREHF: __ARM_FEATURE_DIRECTED_ROUNDING 1
 // CHECK-V8-BAREHF: __ARM_FEATURE_NUMERIC_MAXMIN 1
 // CHECK-V8-BAREHF: __ARM_NEON__ 1
+// CHECK-V8-BAREHF: __ARM_PCS_VFP 1
 // CHECK-V8-BAREHF: __VFP_FP__ 1
 
 // RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=fp-armv8 -x c -E -dM %s | FileCheck --check-prefix=CHECK-V8-BAREHF-FP %s
@@ -85,9 +86,17 @@
 // THUMBV8A-EABI:#define __ARM_ARCH_EXT_IDIV__ 1
 
 // RUN: %clang -target arm-none-linux-gnu -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-DEFS %s
+// CHECK-DEFS:#define __ARM_PCS 1
 // CHECK-DEFS:#define __ARM_SIZEOF_MINIMAL_ENUM 4
 // CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4
 
+// RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\
+// RUN:-fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN:-x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
+// RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\
+// RUN:| FileCheck --check-prefix=CHECK-FASTMATH %s
+// CHECK-FASTMATH: __ARM_FP_FAST 1
+
 // RUN: %clang -target arm-none-linux-gnu -fshort-wchar -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SHORTWCHAR %s
 // CHECK-SHORTWCHAR:#define __ARM_SIZEOF_WCHAR_T 2
 
Index: test/Preprocessor/aarch64-target-features.c
===
--- test/Preprocessor/aarch64-target-features.c
+++ test/Preprocessor/aarch64-target-features.c
@@ -30,10 +30,11 @@
 // CHECK: __ARM_FP16_ARGS 1
 // CHECK: __ARM_FP16_FORMAT_IEEE 1
 // CHECK-NOT: __ARM_FP_FAST 1
-// CHECK: __ARM_FP_FENV_ROUNDING 1
 // CHECK: __ARM_NEON 1
 // CHECK: __ARM_NEON_FP 0xE
 // CHECK: __ARM_PCS_AAPCS64 1
+// CHECK-NOT: __ARM_PCS 1
+// CHECK-NOT: __ARM_PCS_VFP 1
 // CHECK-NOT: __ARM_SIZEOF_MINIMAL_ENUM 1
 // CHECK-NOT: __ARM_SIZEOF_WCHAR_T 2
 
@@ -50,6 +51,9 @@
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+crc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
 // CHECK-CRC32: __ARM_FEATURE_CRC32 1
 
+// RUN: %clang -target aarch64-none-linux-gnu -fno-math-errno -fno-signed-zeros\
+// RUN:-fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN:-x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target aarch64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target arm64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
 // CHECK-FASTMATH: __ARM_FP_FAST 1
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1708,6 +1708,9 @@
   Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only) ||
   Args.hasArg(OPT_cl_finite_math_only) ||
   Args.hasArg(OPT_cl_fast_relaxed_math);
+  Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
+  Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
+  Args.hasArg(OPT_cl_fast_relaxed_math);
 
   

Re: [PATCH] D12359: New warning -Wnonconst-parameter when a pointer parameter can be const

2015-09-24 Thread Aaron Ballman via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a comment.

Thank you for continuing to work on this, I think it's a good diagnostic to 
have.

There are still quite a few unanswered questions in the phab thread. Also, the 
patch appears to be missing tests, which might help to clarify some of the 
confusion I have regarding why some operations are considered "writes."

Thanks!

~Aaron



Comment at: include/clang/AST/DeclBase.h:279
@@ +278,3 @@
+  /// be "const".
+  unsigned Written : 1;
+

Should this bit be sunk all the way down into Decl? What does it mean for a 
TypedefNameDecl or LabelDecl to be written? This seems like it belongs more 
with something like VarDecl (but you might need FieldDecl for C++ support, so 
perhaps ValueDecl?), but I'm not certain.

I'm still a bit confused by "written" in the name (here and with the 
isWritten(), etc) -- It refers to is whether the declaration is used as a 
non-const lvalue, not whether the variable is spelled out in code (as opposed 
to an implicit variable, such as ones used by range-based for loops). Perhaps 
HasNonConstUse, or something a bit more descriptive?


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:201
@@ -200,1 +200,3 @@
+def warn_nonconst_parameter : Warning<"parameter %0 can be const">,
+  InGroup, DefaultIgnore;
 def warn_unused_variable : Warning<"unused variable %0">,

Off-by-default warnings aren't something we usually want to add to the 
frontend. They add to the cost of every compile, and are rarely enabled by 
users. From what I understand (and I could be wrong), we generally only add 
DefaultIgnore diagnostics if we are emulating GCC behavior.


Comment at: lib/Parse/ParseExpr.cpp:176
@@ +175,3 @@
+  if (auto *B = dyn_cast(ER.get())) {
+if (B->isAssignmentOp() || B->isAdditiveOp()) {
+  MarkWritten(B->getLHS());

I do not understand why addition is included here.


Comment at: lib/Parse/ParseExpr.cpp:181
@@ +180,3 @@
+  } else if (isa(ER.get()) ||
+ isa(ER.get()) ||
+ isa(ER.get())) {

Or why a conditional expression is included along with unary operators.


Comment at: lib/Parse/ParseExprCXX.cpp:2831
@@ -2830,1 +2830,3 @@
 
+  MarkWritten(Operand.get());
+

Why does this count as a write? Also, if you are not including support for C++ 
yet, perhaps this should be removed regardless.


http://reviews.llvm.org/D12359



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


[PATCH] D13134: [analyzer] Add keyboard shortcuts to report.html

2015-09-24 Thread Karl Skomski via cfe-commits
skomski created this revision.
skomski added reviewers: dcoughlin, krememek, jordan_rose.
skomski added a subscriber: cfe-commits.
skomski set the repository for this revision to rL LLVM.

Adds three keyboard shortcuts to report.html
to make navigation faster:

Jump to next path: j
Jump to previous path: k
Show Help: ?

Repository:
  rL LLVM

http://reviews.llvm.org/D13134

Files:
  lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  tools/scan-build/keyboard-shortcuts.js
  tools/scan-build/scan-build

Index: tools/scan-build/scan-build
===
--- tools/scan-build/scan-build
+++ tools/scan-build/scan-build
@@ -459,28 +459,20 @@
 ####
 
 sub CopyFiles {
-
   my $Dir = shift;
+  my @Files = ("sorttable.js", "keyboard-shortcuts.js", "scanview.css");
 
-  my $JS = Cwd::realpath("$RealBin/sorttable.js");
-
-  DieDiag("Cannot find 'sorttable.js'.\n")
-if (! -r $JS);
-
-  copy($JS, "$Dir");
+  foreach my $FileName (@Files) {
+my $File = Cwd::realpath("$RealBin/$FileName");
 
-  DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
-if (! -r "$Dir/sorttable.js");
+DieDiag("Cannot find '$FileName'.\n")
+  if (! -r $File);
 
-  my $CSS = Cwd::realpath("$RealBin/scanview.css");
+copy($File, "$Dir");
 
-  DieDiag("Cannot find 'scanview.css'.\n")
-if (! -r $CSS);
-
-  copy($CSS, "$Dir");
-
-  DieDiag("Could not copy 'scanview.css' to '$Dir'.\n")
-if (! -r $CSS);
+DieDiag("Could not copy '$FileName' to '$Dir'.\n")
+  if (! -r "$Dir/$FileName");
+  }
 }
 
 ####
Index: tools/scan-build/keyboard-shortcuts.js
===
--- /dev/null
+++ tools/scan-build/keyboard-shortcuts.js
@@ -0,0 +1,41 @@
+(function () {
+
+function Jump(matchTarget, lastBlock) {
+  var match = document.location.hash.match(/Path\d+|EndPath/)[0];
+  var matches = document.querySelectorAll('#' + match + ' .PathNav')
+  if (matches.length == 2) {
+document.location = matches[matchTarget].children[0].href;
+  } else {
+if (!document.location.hash.includes(lastBlock)) {
+  document.location = matches[0].children[0].href;
+}
+  }
+};
+
+function ShowHelp() {
+  alert("Keyboard shortcuts:\n\n" +
+"Jump to next path: j\n"  +
+"Jump to previous path: k\n");
+}
+
+const KEYS = {
+  J: 74,
+  K: 75,
+  SLASH: 191
+}
+
+document.onkeydown = function (e) {
+  switch(e.keyCode) {
+case KEYS.J:
+  Jump(1, '#EndPath');
+  break;
+case KEYS.K:
+  Jump(0, '#Path1');
+  break;
+case KEYS.SLASH:
+  ShowHelp();
+  break;
+  }
+};
+
+}());
Index: lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -263,6 +263,13 @@
 R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str());
   }
 
+  {
+std::string s;
+llvm::raw_string_ostream os(s);
+os << "";
+R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str());
+  }
+
   // Add CSS, header, and footer.
 
   html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13133: Remove dangling parenthesis.

2015-09-24 Thread Manuel Klimek via cfe-commits
klimek added inline comments.


Comment at: clang-tidy/modernize/LoopConvertCheck.cpp:482
@@ +481,3 @@
+auto Parents = Context->getParents(*Usage.Expression);
+if (Parents.size() == 1) {
+  if (const auto *Paren = Parents[0].get())

Perhaps add a comment (or correct me if I'm wrong ;)
// Usage.Expression contains the DeclRefExpr from the point of usage.
// Parens around a simple DeclRefExpr can always be removed.

(can Usage.Expression be something more complex?)


http://reviews.llvm.org/D13133



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


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-24 Thread Alexandros Lamprineas via cfe-commits
labrinea added inline comments.


Comment at: lib/Frontend/CompilerInvocation.cpp:1711
@@ -1710,1 +1710,3 @@
   Args.hasArg(OPT_cl_fast_relaxed_math);
+  Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
+  Args.hasArg(OPT_cl_unsafe_math_optimizations) ||

richard.barton.arm wrote:
> What happens if I do -menable-unsafe-fp-math then -mno-enable-unsafe-fp-math? 
> I don't think you have enough regression tests.
Well there is no such flag (-mno-enable-unsafe-fp-math) but probably what you 
want to say is that the order of the front-end flags matters. In 
**llvm/tools/clang/test/Driver/fast-math.c** there are tests checking whether 
"-menable-unsafe-fp-math" is correctly set depending on the order of the 
front-end flags. I could modify my tests so that they pass cc1 flags. Then we 
would be checking if _ARM_FP_FAST gets defined in the presence of 
"-menable-unsafe-fp-math". Would that be preferable?


http://reviews.llvm.org/D12633



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


Re: [PATCH] D12996: Driver: support ARM/HF on a single toolchain

2015-09-24 Thread Jonathan Roelofs via cfe-commits
jroelofs added a comment.

Oh, yeah, true.


http://reviews.llvm.org/D12996



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


Re: [PATCH] D13133: Remove dangling parenthesis.

2015-09-24 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG


http://reviews.llvm.org/D13133



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


[clang-tools-extra] r248507 - Remove dangling parenthesis.

2015-09-24 Thread Angel Garcia Gomez via cfe-commits
Author: angelgarcia
Date: Thu Sep 24 10:29:46 2015
New Revision: 248507

URL: http://llvm.org/viewvc/llvm-project?rev=248507=rev
Log:
Remove dangling parenthesis.

Summary: Remove parenthesis surrounding the new loop index.

Reviewers: klimek

Subscribers: cfe-commits, klimek

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=248507=248506=248507=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Thu Sep 
24 10:29:46 2015
@@ -472,11 +472,21 @@ void LoopConvertCheck::doConversion(
 // variable.
 for (const auto  : Usages) {
   std::string ReplaceText;
+  SourceRange Range = Usage.Range;
   if (Usage.Expression) {
 // If this is an access to a member through the arrow operator, after
 // the replacement it must be accessed through the '.' operator.
 ReplaceText = Usage.Kind == Usage::UK_MemberThroughArrow ? VarName + 
"."
  : VarName;
+auto Parents = Context->getParents(*Usage.Expression);
+if (Parents.size() == 1) {
+  if (const auto *Paren = Parents[0].get()) {
+// Usage.Expression will be replaced with the new index variable,
+// and parenthesis around a simple DeclRefExpr can always be
+// removed.
+Range = Paren->getSourceRange();
+  }
+}
   } else {
 // The Usage expression is only null in case of lambda captures (which
 // are VarDecl). If the index is captured by value, add '&' to capture
@@ -486,7 +496,7 @@ void LoopConvertCheck::doConversion(
   }
   TUInfo->getReplacedVars().insert(std::make_pair(Loop, IndexVar));
   Diag << FixItHint::CreateReplacement(
-  CharSourceRange::getTokenRange(Usage.Range), ReplaceText);
+  CharSourceRange::getTokenRange(Range), ReplaceText);
 }
   }
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp?rev=248507=248506=248507=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp 
Thu Sep 24 10:29:46 2015
@@ -199,7 +199,7 @@ void f() {
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   S *ps;
   for (S::iterator it = ps->begin(), e = ps->end(); it != e; ++it) {
@@ -207,7 +207,7 @@ void f() {
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & p : *ps)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (p).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", p.x);
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
 printf("s has value %d\n", it->x);
@@ -228,7 +228,7 @@ void f() {
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : s)
-  // CHECK-FIXES-NEXT: (elem).x = 3;
+  // CHECK-FIXES-NEXT: elem.x = 3;
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
 it->nonConstFun(4, 5);
@@ -250,7 +250,7 @@ void f() {
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & elem : u)
-  // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x);
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x);
 
   U::iterator A;
   for (U::iterator i = u.begin(), e = u.end(); i != e; ++i)
@@ -321,6 +321,21 @@ void f() {
   (void) *I;
 }
   }
+
+  dependent dpp;
+  for (dependent::iterator I = dpp.begin(), E = dpp.end(); I != E; ++I) 
{
+printf("%d\n", (**I).x);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & elem : dpp)
+  // CHECK-FIXES-NEXT: printf("%d\n", (*elem).x);
+
+  for (dependent::iterator I = dpp.begin(), E = dpp.end(); I != E; ++I) 
{
+printf("%d\n", (*I)->x);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & 

r248510 - Debug Info: Use the module pointer as key for the module cache.

2015-09-24 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Thu Sep 24 11:10:04 2015
New Revision: 248510

URL: http://llvm.org/viewvc/llvm-project?rev=248510=rev
Log:
Debug Info: Use the module pointer as key for the module cache.
This way we don't need to rebuild the full module name for every decl.

Modified:
cfe/trunk/include/clang/AST/ExternalASTSource.h
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/include/clang/AST/ExternalASTSource.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTSource.h?rev=248510=248509=248510=diff
==
--- cfe/trunk/include/clang/AST/ExternalASTSource.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h Thu Sep 24 11:10:04 2015
@@ -163,6 +163,7 @@ public:
 StringRef getPath() const { return Path; }
 StringRef getASTFile() const { return ASTFile; }
 uint64_t getSignature() const { return Signature; }
+const Module *getModuleOrNull() const { return ClangModule; }
   };
 
   /// Return a descriptor for the corresponding module, if one exists.

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=248510=248509=248510=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Sep 24 11:10:04 2015
@@ -1676,8 +1676,11 @@ llvm::DIType *CGDebugInfo::CreateType(co
 llvm::DIModule *
 CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
   bool CreateSkeletonCU) {
-  std::string FullModuleName = Mod.getFullModuleName();
-  auto  = ModuleRefCache[FullModuleName];
+  // Use the Module pointer as the key into the cache. This is a
+  // nullptr if the "Module" is a PCH, which is safe because we don't
+  // support chained PCH debug info, so there can only be a single PCH.
+  const Module *M = Mod.getModuleOrNull();
+  auto  = ModuleCache[M];
   if (ModRef)
 return cast(ModRef);
 
@@ -1704,6 +1707,7 @@ CGDebugInfo::getOrCreateModuleRef(Extern
 }
   }
 
+  std::string FullModuleName = Mod.getFullModuleName();
   if (CreateSkeletonCU) {
 llvm::DIBuilder DIB(CGM.getModule());
 DIB.createCompileUnit(TheCU->getSourceLanguage(), FullModuleName,
@@ -1712,11 +1716,11 @@ CGDebugInfo::getOrCreateModuleRef(Extern
   llvm::DIBuilder::FullDebug, Mod.getSignature());
 DIB.finalize();
   }
-  llvm::DIModule *M =
+  llvm::DIModule *DIMod =
   DBuilder.createModule(TheCU, FullModuleName, ConfigMacros, Mod.getPath(),
 CGM.getHeaderSearchOpts().Sysroot);
-  ModRef.reset(M);
-  return M;
+  ModRef.reset(DIMod);
+  return DIMod;
 }
 
 llvm::DIType *CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty,

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=248510=248509=248510=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Sep 24 11:10:04 2015
@@ -96,7 +96,7 @@ class CGDebugInfo {
   llvm::SmallVector ObjCInterfaceCache;
 
   /// Cache of references to clang modules and precompiled headers.
-  llvm::StringMap ModuleRefCache;
+  llvm::DenseMap ModuleCache;
 
   /// List of interfaces we want to keep even if orphaned.
   std::vector RetainedTypes;


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


r248511 - Module Debugging: Emit submodules as nested DW_TAG_modules.

2015-09-24 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Thu Sep 24 11:10:10 2015
New Revision: 248511

URL: http://llvm.org/viewvc/llvm-project?rev=248511=rev
Log:
Module Debugging: Emit submodules as nested DW_TAG_modules.

Added:
cfe/trunk/test/Modules/DebugInfoSubmoduleImport.c
Modified:
cfe/trunk/include/clang/AST/ExternalASTSource.h
cfe/trunk/lib/AST/ExternalASTSource.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/Modules/DebugInfoSubmodules.c

Modified: cfe/trunk/include/clang/AST/ExternalASTSource.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTSource.h?rev=248511=248510=248511=diff
==
--- cfe/trunk/include/clang/AST/ExternalASTSource.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h Thu Sep 24 11:10:10 2015
@@ -159,7 +159,7 @@ public:
 : PCHModuleName(std::move(Name)), Path(std::move(Path)),
   ASTFile(std::move(ASTFile)), Signature(Signature){};
 ASTSourceDescriptor(const Module );
-std::string getFullModuleName() const;
+std::string getModuleName() const;
 StringRef getPath() const { return Path; }
 StringRef getASTFile() const { return ASTFile; }
 uint64_t getSignature() const { return Signature; }

Modified: cfe/trunk/lib/AST/ExternalASTSource.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTSource.cpp?rev=248511=248510=248511=diff
==
--- cfe/trunk/lib/AST/ExternalASTSource.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTSource.cpp Thu Sep 24 11:10:10 2015
@@ -36,9 +36,9 @@ ExternalASTSource::ASTSourceDescriptor::
 ASTFile = File->getName();
 }
 
-std::string ExternalASTSource::ASTSourceDescriptor::getFullModuleName() const {
+std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const {
   if (ClangModule)
-return ClangModule->getFullModuleName();
+return ClangModule->Name;
   else
 return PCHModuleName;
 }

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=248511=248510=248511=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Sep 24 11:10:10 2015
@@ -1707,18 +1707,23 @@ CGDebugInfo::getOrCreateModuleRef(Extern
 }
   }
 
-  std::string FullModuleName = Mod.getFullModuleName();
-  if (CreateSkeletonCU) {
+  bool IsRootModule = M ? !M->Parent : true;
+  if (CreateSkeletonCU && IsRootModule) {
 llvm::DIBuilder DIB(CGM.getModule());
-DIB.createCompileUnit(TheCU->getSourceLanguage(), FullModuleName,
+DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.getModuleName(),
   Mod.getPath(), TheCU->getProducer(), true,
   StringRef(), 0, Mod.getASTFile(),
   llvm::DIBuilder::FullDebug, Mod.getSignature());
 DIB.finalize();
   }
+  llvm::DIModule *Parent =
+  IsRootModule ? nullptr
+   : getOrCreateModuleRef(
+ ExternalASTSource::ASTSourceDescriptor(*M->Parent),
+ CreateSkeletonCU);
   llvm::DIModule *DIMod =
-  DBuilder.createModule(TheCU, FullModuleName, ConfigMacros, Mod.getPath(),
-CGM.getHeaderSearchOpts().Sysroot);
+  DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
+Mod.getPath(), CGM.getHeaderSearchOpts().Sysroot);
   ModRef.reset(DIMod);
   return DIMod;
 }

Added: cfe/trunk/test/Modules/DebugInfoSubmoduleImport.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/DebugInfoSubmoduleImport.c?rev=248511=auto
==
--- cfe/trunk/test/Modules/DebugInfoSubmoduleImport.c (added)
+++ cfe/trunk/test/Modules/DebugInfoSubmoduleImport.c Thu Sep 24 11:10:10 2015
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodule-format=obj -g -dwarf-ext-refs \
+// RUN: -fimplicit-module-maps -x c -fmodules-cache-path=%t -I %S/Inputs \
+// RUN: %s -emit-llvm -o - | FileCheck %s
+#include "DebugSubmoduleA.h"
+#include "DebugSubmoduleB.h"
+
+// CHECK: !DICompileUnit
+// CHECK-NOT: !DICompileUnit
+// CHECK: !DIModule(scope: ![[PARENT:.*]], name: "DebugSubmoduleA"
+// CHECK: [[PARENT]] = !DIModule(scope: null, name: "DebugSubmodules"
+// CHECK: !DIModule(scope: ![[PARENT]], name: "DebugSubmoduleB"
+// CHECK: !DICompileUnit({{.*}}splitDebugFilename: {{.*}}DebugSubmodules
+// CHECK-SAME: dwoId:
+// CHECK-NOT: !DICompileUnit

Modified: cfe/trunk/test/Modules/DebugInfoSubmodules.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/DebugInfoSubmodules.c?rev=248511=248510=248511=diff

Re: [PATCH] D13079: [clang-tidy] Code factorization and cleanup in IdentifierNamingCheck

2015-09-24 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Please add more context to the diffs.



Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:508
@@ +507,3 @@
+  auto  = Failures[Decl];
+  for (const auto  : Failure.Usages) {
+if (R == Range)

berenm wrote:
> Hopefully the number of ranges in Usages will stay low. If not, `Usages` 
> should be an hash table instead, but it looks like SourceRange isn't hashable 
> as is.
If the ranges represent unique variable usages, then there definitely will be 
corner cases that will make this code run slwly. I'd prefer this to be a 
llvm::SmallSet<>, llvm::DenseSet<>, std::unordered_set, std::set, 
std::multimap or anything else providing a 
sub-linear lookup time. I'd probably go with llvm::SmallSet<> with a custom 
comparer for SourceRange.


http://reviews.llvm.org/D13079



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


Re: [PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-24 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Still looks good.


http://reviews.llvm.org/D13052



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


Re: [libcxxabi] r248129 - Let cxa_demangle.cpp compile with gcc/libstdc++ 4.8 and clang-cl/MSVC2013's STL.

2015-09-24 Thread Nico Weber via cfe-commits
On Thu, Sep 24, 2015 at 4:20 AM, Yaron Keren via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Visual C++ 2013 update 5 (latest) does not appear to compile this, mainly
> due to missing support for constexpr.
>
>   https://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
>
> Visual C++ 2013 CTP has constexpr, but MS did not further update this
> branch since Nov 2013.
> The "regular" branch of 2013 update 5 is from Jul 2015.
>
> Worth mentioning that either 2013 CTP or 2015 is required.
>

Right the commit message hints at this with "clang-cl/MSVC2013's STL" –
with this change, _clang-cl_ can compile this file with the MSVC2013
headers. cl.exe can't. cl.exe 2015 can, except for that one
__attribute__((visibiliiy("default"))) line. If that's changed to go
`#ifdef _MSC_VER __declspec(dllexport) #else __attr... #endif` then it
compiles with 2015. (I want to send out something for this soon too.)


>
>
> 2015-09-20 21:10 GMT+03:00 Nico Weber via cfe-commits <
> cfe-commits@lists.llvm.org>:
>
>> Author: nico
>> Date: Sun Sep 20 13:10:46 2015
>> New Revision: 248129
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=248129=rev
>> Log:
>> Let cxa_demangle.cpp compile with gcc/libstdc++ 4.8 and
>> clang-cl/MSVC2013's STL.
>>
>> libstdc++ needs a few typedefs in malloc_alloc. MSVC's STL needs rebind(),
>> construct(), destroy().  MSVC2013 also has no snprintf, but it exists in
>> 2015.
>>
>> Modified:
>> libcxxabi/trunk/src/cxa_demangle.cpp
>>
>> Modified: libcxxabi/trunk/src/cxa_demangle.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=248129=248128=248129=diff
>>
>> ==
>> --- libcxxabi/trunk/src/cxa_demangle.cpp (original)
>> +++ libcxxabi/trunk/src/cxa_demangle.cpp Sun Sep 20 13:10:46 2015
>> @@ -18,6 +18,13 @@
>>  #include 
>>  #include 
>>
>> +#ifdef _MSC_VER
>> +// snprintf is implemented in VS 2015
>> +#if _MSC_VER < 1900
>> +#define snprintf _snprintf_s
>> +#endif
>> +#endif
>> +
>>  namespace __cxxabiv1
>>  {
>>
>> @@ -4818,6 +4825,12 @@ class malloc_alloc
>>  {
>>  public:
>>  typedef T value_type;
>> +typedef T& reference;
>> +typedef const T& const_reference;
>> +typedef T* pointer;
>> +typedef const T* const_pointer;
>> +typedef std::size_t size_type;
>> +typedef std::ptrdiff_t difference_type;
>>
>>  malloc_alloc() = default;
>>  template  malloc_alloc(const malloc_alloc&) noexcept {}
>> @@ -4830,6 +4843,17 @@ public:
>>  {
>>  std::free(p);
>>  }
>> +
>> +template  struct rebind { using other = malloc_alloc; };
>> +template 
>> +void construct(U* p, Args&&... args)
>> +{
>> +::new ((void*)p) U(std::forward(args)...);
>> +}
>> +void destroy(T* p)
>> +{
>> +p->~T();
>> +}
>>  };
>>
>>  template 
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13117: [DarwinDriver] Use -lto_library to specify the path for libLTO.dylib

2015-09-24 Thread Bruno Cardoso Lopes via cfe-commits
bruno updated this revision to Diff 35664.
bruno added a comment.

Added test per Duncan's comment.


Repository:
  rL LLVM

http://reviews.llvm.org/D13117

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/Tools.cpp
  test/Driver/darwin-ld.c

Index: test/Driver/darwin-ld.c
===
--- test/Driver/darwin-ld.c
+++ test/Driver/darwin-ld.c
@@ -110,6 +110,14 @@
 // LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}}
 // LINK_OBJECT_LTO_PATH: "-object_path_lto"
 
+// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN:   -mlinker-version=133 -flto 2> %t.log
+// RUN: cat %t.log
+// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s < %t.log
+//
+// LINK_LTOLIB_PATH: {{ld(.exe)?"}}
+// LINK_LTOLIB_PATH: "-lto_library"
+
 // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \
 // RUN:   -force_load a -force_load b 2> %t.log
 // RUN: cat %t.log
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6501,15 +6501,34 @@
options::OPT_fno_application_extension, false))
 CmdArgs.push_back("-application_extension");
 
-  // If we are using LTO, then automatically create a temporary file path for
-  // the linker to use, so that it's lifetime will extend past a possible
-  // dsymutil step.
-  if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) {
-const char *TmpPath = C.getArgs().MakeArgString(
-D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object)));
-C.addTempFile(TmpPath);
-CmdArgs.push_back("-object_path_lto");
-CmdArgs.push_back(TmpPath);
+  if (D.IsUsingLTO(Args)) {
+// If we are using LTO, then automatically create a temporary file path for
+// the linker to use, so that it's lifetime will extend past a possible
+// dsymutil step.
+if (Version[0] >= 116 && NeedsTempPath(Inputs)) {
+  const char *TmpPath = C.getArgs().MakeArgString(
+  D.GetTemporaryPath("cc", 
types::getTypeTempSuffix(types::TY_Object)));
+  C.addTempFile(TmpPath);
+  CmdArgs.push_back("-object_path_lto");
+  CmdArgs.push_back(TmpPath);
+}
+
+// Use -lto_library option to specify the libLTO.dylib path. Try to find
+// it in clang installed libraries. If not found, the option is not used
+// and 'ld' will use its default mechanism to search for libLTO.dylib.
+if (Version[0] >= 133) {
+  // Search for libLTO in /../lib/libLTO.dylib
+  StringRef P = llvm::sys::path::parent_path(D.getInstalledDir());
+  SmallString<128> LibLTOPath(P);
+  llvm::sys::path::append(LibLTOPath, "lib");
+  llvm::sys::path::append(LibLTOPath, "libLTO.dylib");
+  if (llvm::sys::fs::exists(LibLTOPath)) {
+CmdArgs.push_back("-lto_library");
+CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
+  } else {
+D.Diag(diag::warn_lto_libpath);
+  }
+}
   }
 
   // Derived from the "link" spec.
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -117,6 +117,7 @@
 def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, 
please use [no]simd instead">;
 
 def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup;
+def warn_lto_libpath : Warning<"libLTO.dylib relative to clang installed dir 
not found; using 'ld' default search path instead">;
 def warn_drv_optimization_value : Warning<"optimization level '%0' is not 
supported; using '%1%2' instead">,
   InGroup;
 def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not 
supported">,


Index: test/Driver/darwin-ld.c
===
--- test/Driver/darwin-ld.c
+++ test/Driver/darwin-ld.c
@@ -110,6 +110,14 @@
 // LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}}
 // LINK_OBJECT_LTO_PATH: "-object_path_lto"
 
+// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN:   -mlinker-version=133 -flto 2> %t.log
+// RUN: cat %t.log
+// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s < %t.log
+//
+// LINK_LTOLIB_PATH: {{ld(.exe)?"}}
+// LINK_LTOLIB_PATH: "-lto_library"
+
 // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \
 // RUN:   -force_load a -force_load b 2> %t.log
 // RUN: cat %t.log
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6501,15 +6501,34 @@
options::OPT_fno_application_extension, false))
 CmdArgs.push_back("-application_extension");
 
-  // If we are using LTO, then automatically create a temporary file path for
-  // the linker to use, so that it's lifetime will extend past a possible
-  // dsymutil step.
-  if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) {
-

Re: [PATCH] D13079: [clang-tidy] Code factorization and cleanup in IdentifierNamingCheck

2015-09-24 Thread Beren Minor via cfe-commits
berenm updated this revision to Diff 35669.
berenm added a comment.

Reformatting with clang-format


http://reviews.llvm.org/D13079

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -68,6 +68,8 @@
 // FIXME: name, declaration contexts, forward declarations, etc, are correctly
 // FIXME: checked and renamed
 
+// clang-format off
+
 namespace FOO_NS {
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}namespace foo_ns {{{$}}
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -62,20 +62,20 @@
 }
   };
 
-private:
-  std::vector NamingStyles;
-  bool IgnoreFailedSplit;
-
   struct NamingCheckFailure {
 std::string KindName;
 std::string Fixup;
 bool ShouldFix;
-std::vector Usages;
+llvm::DenseSet RawUsageLocs;
 
 NamingCheckFailure() : ShouldFix(true) {}
   };
+  typedef llvm::DenseMap NamingCheckFailureMap;
 
-  llvm::DenseMap NamingCheckFailures;
+private:
+  std::vector NamingStyles;
+  bool IgnoreFailedSplit;
+  NamingCheckFailureMap NamingCheckFailures;
 };
 
 } // namespace readability
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -21,6 +21,7 @@
 namespace tidy {
 namespace readability {
 
+// clang-format off
 #define NAMING_KEYS(m) \
 m(Namespace) \
 m(InlineNamespace) \
@@ -80,6 +81,7 @@
 };
 
 #undef NAMING_KEYS
+// clang-format on
 
 IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
  ClangTidyContext *Context)
@@ -134,10 +136,10 @@
 }
 
 void IdentifierNamingCheck::registerMatchers(MatchFinder *Finder) {
-// FIXME: For now, only Decl and DeclRefExpr nodes are visited for checking and
-// replacement. There is a lot of missing cases, such as references to a class
-// name (as in 'const int CMyClass::kClassConstant = 4;'), to an enclosing
-// context (namespace, class, etc).
+  // FIXME: For now, only Decl and DeclRefExpr nodes are visited for checking
+  // and replacement. There is a lot of missing cases, such as references to a
+  // class name (as in 'const int CMyClass::kClassConstant = 4;'), to an
+  // enclosing context (namespace, class, etc).
 
   Finder->addMatcher(namedDecl().bind("decl"), this);
   Finder->addMatcher(declRefExpr().bind("declref"), this);
@@ -499,23 +501,24 @@
   return SK_Invalid;
 }
 
+static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap ,
+ const NamedDecl *Decl, SourceRange Range,
+ const SourceManager *SM) {
+  auto  = Failures[Decl];
+  if (!Failure.RawUsageLocs.insert(Range.getBegin().getRawEncoding()).second)
+return;
+
+  Failure.ShouldFix = Failure.ShouldFix && SM->isInMainFile(Range.getBegin()) &&
+  SM->isInMainFile(Range.getEnd()) &&
+  !Range.getBegin().isMacroID() &&
+  !Range.getEnd().isMacroID();
+}
+
 void IdentifierNamingCheck::check(const MatchFinder::MatchResult ) {
   if (const auto *DeclRef = Result.Nodes.getNodeAs("declref")) {
-auto It = NamingCheckFailures.find(DeclRef->getDecl());
-if (It == NamingCheckFailures.end())
-  return;
-
-NamingCheckFailure  = It->second;
 SourceRange Range = DeclRef->getNameInfo().getSourceRange();
-
-Failure.Usages.push_back(Range);
-Failure.ShouldFix = Failure.ShouldFix &&
-Result.SourceManager->isInMainFile(Range.getBegin()) &&
-Result.SourceManager->isInMainFile(Range.getEnd()) &&
-!Range.getBegin().isMacroID() &&
-!Range.getEnd().isMacroID();
-
-return;
+return addUsage(NamingCheckFailures, DeclRef->getDecl(), Range,
+Result.SourceManager);
   }
 
   if (const auto *Decl = Result.Nodes.getNodeAs("decl")) {
@@ -550,11 +553,7 @@
 
   Failure.Fixup = std::move(Fixup);
   Failure.KindName = std::move(KindName);
-  Failure.ShouldFix =
-  Failure.ShouldFix &&
-  Result.SourceManager->isInMainFile(Range.getBegin()) &&
-  Result.SourceManager->isInMainFile(Range.getEnd()) &&
-  !Range.getBegin().isMacroID() && !Range.getEnd().isMacroID();
+  addUsage(NamingCheckFailures, Decl, Range, Result.SourceManager);
 }
   }
 }
@@ -564,19 

Re: [libcxxabi] r248129 - Let cxa_demangle.cpp compile with gcc/libstdc++ 4.8 and clang-cl/MSVC2013's STL.

2015-09-24 Thread Yaron Keren via cfe-commits
Ah, OK. Maybe it would compile with VC 2013 by using LLVM_CONSTEXPR instead
of constexpr. It's not available now in libcxx but the definition from
Compiler.h is trivial.




2015-09-24 19:28 GMT+03:00 Nico Weber :

> On Thu, Sep 24, 2015 at 4:20 AM, Yaron Keren via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Visual C++ 2013 update 5 (latest) does not appear to compile this, mainly
>> due to missing support for constexpr.
>>
>>   https://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
>>
>> Visual C++ 2013 CTP has constexpr, but MS did not further update this
>> branch since Nov 2013.
>> The "regular" branch of 2013 update 5 is from Jul 2015.
>>
>> Worth mentioning that either 2013 CTP or 2015 is required.
>>
>
> Right the commit message hints at this with "clang-cl/MSVC2013's STL" –
> with this change, _clang-cl_ can compile this file with the MSVC2013
> headers. cl.exe can't. cl.exe 2015 can, except for that one
> __attribute__((visibiliiy("default"))) line. If that's changed to go
> `#ifdef _MSC_VER __declspec(dllexport) #else __attr... #endif` then it
> compiles with 2015. (I want to send out something for this soon too.)
>
>
>>
>>
>> 2015-09-20 21:10 GMT+03:00 Nico Weber via cfe-commits <
>> cfe-commits@lists.llvm.org>:
>>
>>> Author: nico
>>> Date: Sun Sep 20 13:10:46 2015
>>> New Revision: 248129
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=248129=rev
>>> Log:
>>> Let cxa_demangle.cpp compile with gcc/libstdc++ 4.8 and
>>> clang-cl/MSVC2013's STL.
>>>
>>> libstdc++ needs a few typedefs in malloc_alloc. MSVC's STL needs
>>> rebind(),
>>> construct(), destroy().  MSVC2013 also has no snprintf, but it exists in
>>> 2015.
>>>
>>> Modified:
>>> libcxxabi/trunk/src/cxa_demangle.cpp
>>>
>>> Modified: libcxxabi/trunk/src/cxa_demangle.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=248129=248128=248129=diff
>>>
>>> ==
>>> --- libcxxabi/trunk/src/cxa_demangle.cpp (original)
>>> +++ libcxxabi/trunk/src/cxa_demangle.cpp Sun Sep 20 13:10:46 2015
>>> @@ -18,6 +18,13 @@
>>>  #include 
>>>  #include 
>>>
>>> +#ifdef _MSC_VER
>>> +// snprintf is implemented in VS 2015
>>> +#if _MSC_VER < 1900
>>> +#define snprintf _snprintf_s
>>> +#endif
>>> +#endif
>>> +
>>>  namespace __cxxabiv1
>>>  {
>>>
>>> @@ -4818,6 +4825,12 @@ class malloc_alloc
>>>  {
>>>  public:
>>>  typedef T value_type;
>>> +typedef T& reference;
>>> +typedef const T& const_reference;
>>> +typedef T* pointer;
>>> +typedef const T* const_pointer;
>>> +typedef std::size_t size_type;
>>> +typedef std::ptrdiff_t difference_type;
>>>
>>>  malloc_alloc() = default;
>>>  template  malloc_alloc(const malloc_alloc&) noexcept {}
>>> @@ -4830,6 +4843,17 @@ public:
>>>  {
>>>  std::free(p);
>>>  }
>>> +
>>> +template  struct rebind { using other = malloc_alloc; };
>>> +template 
>>> +void construct(U* p, Args&&... args)
>>> +{
>>> +::new ((void*)p) U(std::forward(args)...);
>>> +}
>>> +void destroy(T* p)
>>> +{
>>> +p->~T();
>>> +}
>>>  };
>>>
>>>  template 
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-24 Thread Tim Northover via cfe-commits
On 24 September 2015 at 07:53, Alexandros Lamprineas
 wrote:
> @t.p.northover I think we should not be defining _ARM_FP_FENV_ROUNDING on 
> neither of ARM and AArch64 targets since "-frounding-math" is not available 
> on clang: clang/llvm don't support C99 FP rounding mode pragmas (FENV_ACCESS 
> etc) 

Ah, that constant folding is definitely a problem. Changing it sounds
reasonable.

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


LLVM buildmaster will be restarted tonight

2015-09-24 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be restarted after 6 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


Re: [PATCH] D13090: [clang-tidy] IdentifierNamingCheck should only emit warnings when declaration or usage is outside of macros

2015-09-24 Thread Beren Minor via cfe-commits
berenm added a comment.

This will also disable all warnings for declaration / usages outside of the 
main file.

It might be better to disable the warnings and fixes whenever a macro is 
involved (in the declaration or any usage), but at least keep the warning 
across files, even if we don't offer fixes. I think the most common use-case 
will be to have some declaration in a header file and usages in multiple source 
files, and in this case warnings are interesting.

I'm assuming here that "main file" in clang tooling framework means the .cpp 
file from which the ast is built.


http://reviews.llvm.org/D13090



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


r248521 - Recommit r248154: [ARM] Handle DSP feature as an ArchExtKind

2015-09-24 Thread Artyom Skrobov via cfe-commits
Author: askrobov
Date: Thu Sep 24 12:34:05 2015
New Revision: 248521

URL: http://llvm.org/viewvc/llvm-project?rev=248521=rev
Log:
Recommit r248154: [ARM] Handle DSP feature as an ArchExtKind

Currently, the availability of DSP instructions (ACLE 6.4.7) is handled in
a hand-rolled tricky condition block in lib/Basic/Targets.cpp, with a FIXME:
attached.

http://reviews.llvm.org/D12937 moved the handling of the DSP feature over to
ARMTargetParser.def in LLVM, to be in line with other architecture extensions.

This is the corresponding patch to clang, to clear the FIXME: and update
the tests.

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


Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGen/arm-target-features.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=248521=248520=248521=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep 24 12:34:05 2015
@@ -4121,6 +4121,7 @@ class ARMTargetInfo : public TargetInfo
 
   unsigned CRC : 1;
   unsigned Crypto : 1;
+  unsigned DSP : 1;
   unsigned Unaligned : 1;
 
   enum {
@@ -4472,6 +4473,7 @@ public:
 FPU = 0;
 CRC = 0;
 Crypto = 0;
+DSP = 0;
 Unaligned = 1;
 SoftFloat = SoftFloatABI = false;
 HWDiv = 0;
@@ -4507,6 +4509,8 @@ public:
 CRC = 1;
   } else if (Feature == "+crypto") {
 Crypto = 1;
+  } else if (Feature == "+t2dsp") {
+DSP = 1;
   } else if (Feature == "+fp-only-sp") {
 HW_FP_remove |= HW_FP_DP | HW_FP_HP;
   } else if (Feature == "+strict-align") {
@@ -4742,25 +4746,19 @@ public:
 }
 
 // ACLE 6.4.7 DSP instructions
-bool hasDSP = false;
-bool is5EOrAbove = (ArchVersion >= 6 ||
-   (ArchVersion == 5 && CPUAttr.count('E')));
-// FIXME: We are not getting all 32-bit ARM architectures
-bool is32Bit = (!isThumb() || supportsThumb2());
-if (is5EOrAbove && is32Bit && (CPUProfile != "M" || CPUAttr  == "7EM")) {
+if (DSP) {
   Builder.defineMacro("__ARM_FEATURE_DSP", "1");
-  hasDSP = true;
 }
 
 // ACLE 6.4.8 Saturation instructions
-bool hasSAT = false;
+bool SAT = false;
 if ((ArchVersion == 6 && CPUProfile != "M") || ArchVersion > 6 ) {
   Builder.defineMacro("__ARM_FEATURE_SAT", "1");
-  hasSAT = true;
+  SAT = true;
 }
 
 // ACLE 6.4.6 Q (saturation) flag
-if (hasDSP || hasSAT)
+if (DSP || SAT)
   Builder.defineMacro("__ARM_FEATURE_QBIT", "1");
   }
 

Modified: cfe/trunk/test/CodeGen/arm-target-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-target-features.c?rev=248521=248520=248521=diff
==
--- cfe/trunk/test/CodeGen/arm-target-features.c (original)
+++ cfe/trunk/test/CodeGen/arm-target-features.c Thu Sep 24 12:34:05 2015
@@ -1,15 +1,15 @@
 // REQUIRES: arm-registered-target
 
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu cortex-a8 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3
-// CHECK-VFP3: "target-features"="+neon,+vfp3"
+// CHECK-VFP3: "target-features"="+neon,+t2dsp,+vfp3"
 
 
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabi -target-cpu cortex-a9 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP3-FP16
-// CHECK-VFP3-FP16: "target-features"="+fp16,+neon,+vfp3"
+// CHECK-VFP3-FP16: "target-features"="+fp16,+neon,+t2dsp,+vfp3"
 
 
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu cortex-a5 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4
-// CHECK-VFP4: "target-features"="+neon,+vfp4"
+// CHECK-VFP4: "target-features"="+neon,+t2dsp,+vfp4"
 
 
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu cortex-a7 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-DIV
@@ -18,39 +18,41 @@
 // RUN: %clang_cc1 -triple armv7-linux-gnueabihf -target-cpu cortex-a17 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-DIV
 // RUN: %clang_cc1 -triple thumbv7s-linux-gnueabi -target-cpu swift -emit-llvm 
-o - %s | FileCheck %s --check-prefix=CHECK-VFP4-DIV
 // RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -target-cpu krait 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-VFP4-DIV
-// CHECK-VFP4-DIV: "target-features"="+hwdiv,+hwdiv-arm,+neon,+vfp4"
+// CHECK-VFP4-DIV: "target-features"="+hwdiv,+hwdiv-arm,+neon,+t2dsp,+vfp4"
 
 
 // RUN: %clang_cc1 -triple thumbv7s-apple-ios7.0 -target-cpu cyclone 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // RUN: %clang_cc1 -triple armv8-linux-gnueabi -target-cpu cortex-a53 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu cortex-a57 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // RUN: %clang_cc1 

Re: [PATCH] D13122: Enable SafeStack on all Linux platforms

2015-09-24 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

Thanks, committed as r248518 with a test.


Repository:
  rL LLVM

http://reviews.llvm.org/D13122



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


r248518 - Enable SafeStack on all Linux platforms.

2015-09-24 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Thu Sep 24 12:22:46 2015
New Revision: 248518

URL: http://llvm.org/viewvc/llvm-project?rev=248518=rev
Log:
Enable SafeStack on all Linux platforms.

Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=248518=248517=248518=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Sep 24 12:22:46 2015
@@ -3800,6 +3800,7 @@ SanitizerMask Linux::getSupportedSanitiz
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::KernelAddress;
   Res |= SanitizerKind::Vptr;
+  Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64)
@@ -3810,7 +3811,6 @@ SanitizerMask Linux::getSupportedSanitiz
 Res |= SanitizerKind::Memory;
   if (IsX86 || IsX86_64) {
 Res |= SanitizerKind::Function;
-Res |= SanitizerKind::SafeStack;
   }
   return Res;
 }

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=248518=248517=248518=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Thu Sep 24 12:22:46 2015
@@ -282,6 +282,8 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP-ASAN
 // RUN: %clang -target x86_64-linux-gnu -fstack-protector 
-fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
+// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP
+// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP
 // SP-NOT: stack-protector
 // SP: "-fsanitize=safe-stack"
 // SP-ASAN-NOT: stack-protector


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


Re: [PATCH] D13079: [clang-tidy] Code factorization and cleanup in IdentifierNamingCheck

2015-09-24 Thread Beren Minor via cfe-commits
berenm marked 2 inline comments as done.
berenm added a comment.

http://reviews.llvm.org/D13079



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


Re: [PATCH] D13117: [DarwinDriver] Use -lto_library to specify the path for libLTO.dylib

2015-09-24 Thread Duncan P. N. Exon Smith via cfe-commits
dexonsmith added a comment.

Sorry for the review fragmentation, but I just noticed there's no test
for the new warning.  Can you add one?  After that, LGTM.


Repository:
  rL LLVM

http://reviews.llvm.org/D13117



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


Re: [PATCH] D11279: Initial patch for PS4 toolchain

2015-09-24 Thread Katya Romanova via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248546: This patch adds missing pieces to clang, including 
the PS4 toolchain (authored by kromanova).

Changed prior to commit:
  http://reviews.llvm.org/D11279?vs=34522=35681#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D11279

Files:
  cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Driver/Tools.h
  cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
  cfe/trunk/test/Driver/Inputs/scei-ps4_tree/target/include/.keep
  cfe/trunk/test/Driver/Inputs/scei-ps4_tree/target/include_common/.keep
  cfe/trunk/test/Driver/debug-options.c
  cfe/trunk/test/Driver/ps4-header-search.c
  cfe/trunk/test/Driver/ps4-linker-non-win.c
  cfe/trunk/test/Driver/ps4-linker-win.c
  cfe/trunk/test/Driver/ps4-pic.c
  cfe/trunk/test/Driver/ps4-sdk-root.c
  cfe/trunk/test/Driver/rtti-options.cpp
  cfe/trunk/test/Driver/stack-protector.c

Index: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td
@@ -820,3 +820,7 @@
 
 // A warning group for things that will change semantics in the future.
 def FutureCompat : DiagGroup<"future-compat">;
+
+def InvalidOrNonExistentDirectory : DiagGroup<"invalid-or-nonexistent-directory">;
+
+def OptionIgnored : DiagGroup<"option-ignored">;
Index: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
@@ -192,4 +192,18 @@
 def warn_target_unsupported_nanlegacy : Warning<
   "ignoring '-mnan=legacy' option because the '%0' architecture does not support it">,
   InGroup;
+
+def warn_drv_unable_to_find_directory_expected : Warning<
+  "unable to find %0 directory, expected to be in '%1'">,
+  InGroup;
+
+def warn_drv_ps4_force_pic : Warning<
+  "option '%0' was ignored by the PS4 toolchain, using '-fPIC'">,
+  InGroup;
+
+def warn_drv_ps4_sdk_dir : Warning<
+  "environment variable SCE_PS4_SDK_DIR is set, but points to invalid or nonexistent directory '%0'">,
+  InGroup;
+
+def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker option">;
 }
Index: cfe/trunk/test/Driver/ps4-linker-non-win.c
===
--- cfe/trunk/test/Driver/ps4-linker-non-win.c
+++ cfe/trunk/test/Driver/ps4-linker-non-win.c
@@ -0,0 +1,18 @@
+// UNSUPPORTED: system-windows
+// REQUIRES: x86-registered-target
+
+// RUN: touch %T/ps4-ld
+
+// RUN: env "PATH=%T" %clang -### -target x86_64-scei-ps4  %s -linker=gold 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-LINKER %s
+// RUN: env "PATH=%T" %clang -### -target x86_64-scei-ps4  %s -shared 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-LINKER %s
+
+// RUN: env "PATH=%T" %clang -### -target x86_64-scei-ps4  %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-LINKER %s
+// RUN: env "PATH=%T" %clang -### -target x86_64-scei-ps4  %s -linker=ps4 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-LINKER %s
+// RUN: env "PATH=%T" %clang -### -target x86_64-scei-ps4  %s -shared \
+// RUN: -linker=ps4 2>&1 | FileCheck --check-prefix=CHECK-PS4-LINKER %s
+
+// CHECK-PS4-LINKER: ps4-ld
Index: cfe/trunk/test/Driver/ps4-linker-win.c
===
--- cfe/trunk/test/Driver/ps4-linker-win.c
+++ cfe/trunk/test/Driver/ps4-linker-win.c
@@ -0,0 +1,26 @@
+// The full path to the gold linker was not found on Windows because the
+// driver fails to add an .exe extension to the name.
+// We check that gold linker's full name (with an extension) is specified
+// on the command line if -linker=gold, or -shared with no -linker option
+// are passed. Otherwise, we check that the PS4's linker's full name is
+// specified.
+
+// REQUIRES: system-windows, x86-registered-target
+
+// RUN: touch %T/ps4-ld.exe
+// RUN: touch %T/ps4-ld.gold.exe
+
+// RUN: env "PATH=%T" %clang -target x86_64-scei-ps4  %s -linker=gold -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-GOLD %s
+// RUN: env "PATH=%T" %clang -target x86_64-scei-ps4  %s -shared -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-GOLD %s
+
+// RUN: env "PATH=%T" %clang -target x86_64-scei-ps4  %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-LINKER %s
+// RUN: env "PATH=%T" %clang -target x86_64-scei-ps4  %s -linker=ps4 -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PS4-LINKER %s
+// RUN: env "PATH=%T" %clang -target x86_64-scei-ps4  %s -shared \
+// RUN: -linker=ps4 -### 2>&1 | FileCheck 

Re: [PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

2015-09-24 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

The analyzer has a notion of ConstPointerEscape, see checkConstPointerEscape 
callback.
All the pointers to const parameters are escaped this way. The implementation 
for that is in CallEvent::invalidateRegions, right below the code you've added:

for (unsigned Idx = 0, Count = getNumArgs(); Idx != Count; ++Idx) {

// Mark this region for invalidation.  We batch invalidate regions
// below for efficiency.
if (PreserveArgs.count(Idx))
  if (const MemRegion *MR = getArgSVal(Idx).getAsRegion())
ETraits.setTrait(MR->StripCasts(), 
RegionAndSymbolInvalidationTraits::TK_PreserveContents);
// TODO: Factor this out + handle the lower level const pointers.
  
ValuesToInvalidate.push_back(getArgSVal(Idx));
  }

I think we should const escape all non-mutable fields as well as 'this'.

(A motivation behind this callback is that one can call delete on pointers of 
const *void type.)


http://reviews.llvm.org/D13099



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


Re: [PATCH] D13105: [OpenCL] Enable program scope variables for OpenCL2.0

2015-09-24 Thread Alexey Bader via cfe-commits
bader added a subscriber: bader.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7472-7473
@@ -7469,4 +7471,4 @@
   "sampler type cannot be used with the __local and __global address space 
qualifiers">;
 def err_opencl_global_invalid_addr_space : Error<
-  "global variables must have a constant address space qualifier">;
+  "program scope variables has wrong address space qualifier">;
 def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 
'main'">;

I think we can do better diagnostics. Original message hinted on way to fix 
that error - add 'constant' qualifier.

In our implementation we have 4 kinds of diagnostics (probably we need only 2 
of them):
def err_opencl_global_invalid_addr_space : Error<
"program scope variables must reside in constant address space">;
def err_opencl20_global_invalid_addr_space : Error<
"program scope variables must reside in global or constant address space">;
def err_program_scope_variable_non_constant : Error<
"program scope variables are required to be declared in constant address 
space">;
def err_program_scope_variable_non_constant_or_global : Error<
"program scope variables are required to be declared either in constant or 
global address space">;

They used for OpenCL 1.2 and OpenCL 2.0 sources correspondingly.


Comment at: test/SemaOpenCL/storageclass.cl:9-11
@@ +8,5 @@
+global int G2 = 0;
+#ifndef CL20
+// expected-error@-2{{program scope variables has wrong address space 
qualifier}}
+#endif
+

Don't you think it's better to put OpenCL 2.0 test into separate file?


http://reviews.llvm.org/D13105



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


Re: [PATCH] D12407: [clang-format-vs] Add an option to reformat source code when file is saved to disk

2015-09-24 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

I went back and retested VS2010, VS2013 and VS2015. so in all cases I

1. start Visual studio
2. open a .h file (with incorrect style) - (via the recent file menu)
3. make a minor edit of whitespace
4. hit save file

In allcases it does NOT reformat the file

Now do

Tools->Options->LLVM/CLang
The setting is currently True for reformat on save
Turn it to False press OK
Tools->Options->LLVM/CLang
The setting is now False
Turn it to True press ok

now return to the file and press save

The file will now be reformatted.

After this point any subsequent edits and save will reformat the page, perhaps 
others can try.


http://reviews.llvm.org/D12407



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


Re: [PATCH] D12821: Allow for C's "writing off the end" idiom in __builtin_object_size

2015-09-24 Thread George Burgess IV via cfe-commits
george.burgess.iv added a comment.

Friendly ping :)


http://reviews.llvm.org/D12821



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


r248546 - This patch adds missing pieces to clang, including the PS4 toolchain

2015-09-24 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Thu Sep 24 17:06:52 2015
New Revision: 248546

URL: http://llvm.org/viewvc/llvm-project?rev=248546=rev
Log:
This patch adds missing pieces to clang, including the PS4 toolchain
definition, added warnings, PS4 defaults, and Driver changes needed for
our compiler.

A patch by Filipe Cabecinhas, Pierre Gousseau and Katya Romanova!

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


Added:
cfe/trunk/test/Driver/Inputs/scei-ps4_tree/
cfe/trunk/test/Driver/Inputs/scei-ps4_tree/target/
cfe/trunk/test/Driver/Inputs/scei-ps4_tree/target/include/
cfe/trunk/test/Driver/Inputs/scei-ps4_tree/target/include/.keep
cfe/trunk/test/Driver/Inputs/scei-ps4_tree/target/include_common/
cfe/trunk/test/Driver/Inputs/scei-ps4_tree/target/include_common/.keep
cfe/trunk/test/Driver/ps4-header-search.c
cfe/trunk/test/Driver/ps4-linker-non-win.c
cfe/trunk/test/Driver/ps4-linker-win.c
cfe/trunk/test/Driver/ps4-pic.c
cfe/trunk/test/Driver/ps4-sdk-root.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Driver/Tools.h
cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
cfe/trunk/test/Driver/debug-options.c
cfe/trunk/test/Driver/rtti-options.cpp
cfe/trunk/test/Driver/stack-protector.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=248546=248545=248546=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Sep 24 17:06:52 
2015
@@ -192,4 +192,18 @@ def warn_target_unsupported_nan2008 : Wa
 def warn_target_unsupported_nanlegacy : Warning<
   "ignoring '-mnan=legacy' option because the '%0' architecture does not 
support it">,
   InGroup;
+
+def warn_drv_unable_to_find_directory_expected : Warning<
+  "unable to find %0 directory, expected to be in '%1'">,
+  InGroup;
+
+def warn_drv_ps4_force_pic : Warning<
+  "option '%0' was ignored by the PS4 toolchain, using '-fPIC'">,
+  InGroup;
+
+def warn_drv_ps4_sdk_dir : Warning<
+  "environment variable SCE_PS4_SDK_DIR is set, but points to invalid or 
nonexistent directory '%0'">,
+  InGroup;
+
+def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker 
option">;
 }

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=248546=248545=248546=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Sep 24 17:06:52 2015
@@ -820,3 +820,7 @@ def CudaCompat : DiagGroup<"cuda-compat"
 
 // A warning group for things that will change semantics in the future.
 def FutureCompat : DiagGroup<"future-compat">;
+
+def InvalidOrNonExistentDirectory : 
DiagGroup<"invalid-or-nonexistent-directory">;
+
+def OptionIgnored : DiagGroup<"option-ignored">;

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=248546=248545=248546=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Sep 24 17:06:52 2015
@@ -2254,6 +2254,9 @@ const ToolChain ::getToolChain(co
 case llvm::Triple::CUDA:
   TC = new toolchains::CudaToolChain(*this, Target, Args);
   break;
+case llvm::Triple::PS4:
+  TC = new toolchains::PS4CPU(*this, Target, Args);
+  break;
 default:
   // Of these targets, Hexagon is the only one that might have
   // an OS of Linux, in which case it got handled above already.

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=248546=248545=248546=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Sep 24 17:06:52 2015
@@ -4065,3 +4065,69 @@ void WebAssembly::addClangTargetOptions(
  options::OPT_fno_use_init_array, true))
 CC1Args.push_back("-fuse-init-array");
 }
+
+PS4CPU::PS4CPU(const Driver , const llvm::Triple , const ArgList 
)
+: Generic_ELF(D, Triple, Args) {
+  if (Args.hasArg(options::OPT_static))
+D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4";
+
+  // Determine where to find the PS4 libraries. We use SCE_PS4_SDK_DIR
+  // if it exists; otherwise use the driver's installation 

r248539 - Move the darwin define static function to be close to the OS define.

2015-09-24 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Thu Sep 24 16:17:04 2015
New Revision: 248539

URL: http://llvm.org/viewvc/llvm-project?rev=248539=rev
Log:
Move the darwin define static function to be close to the OS define.

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

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=248539=248538=248539=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep 24 16:17:04 2015
@@ -84,6 +84,28 @@ public:
 
 };
 
+// CloudABI Target
+template 
+class CloudABITargetInfo : public OSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions , const llvm::Triple ,
+MacroBuilder ) const override {
+Builder.defineMacro("__CloudABI__");
+Builder.defineMacro("__ELF__");
+
+// CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
+Builder.defineMacro("__STDC_ISO_10646__", "201206L");
+Builder.defineMacro("__STDC_UTF_16__");
+Builder.defineMacro("__STDC_UTF_32__");
+  }
+
+public:
+  CloudABITargetInfo(const llvm::Triple )
+  : OSTargetInfo(Triple) {
+this->UserLabelPrefix = "";
+  }
+};
+
 static void getDarwinDefines(MacroBuilder , const LangOptions ,
  const llvm::Triple ,
  StringRef ,
@@ -148,8 +170,7 @@ static void getDarwinDefines(MacroBuilde
 Str[3] = '0' + (Rev / 10);
 Str[4] = '0' + (Rev % 10);
 Str[5] = '\0';
-Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__",
-Str);
+Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
   } else if (Triple.isMacOSX()) {
 // Note that the Driver allows versions which aren't representable in the
 // define (because we only get a single digit for the minor and micro
@@ -183,28 +204,6 @@ static void getDarwinDefines(MacroBuilde
   PlatformMinVersion = VersionTuple(Maj, Min, Rev);
 }
 
-// CloudABI Target
-template 
-class CloudABITargetInfo : public OSTargetInfo {
-protected:
-  void getOSDefines(const LangOptions , const llvm::Triple ,
-MacroBuilder ) const override {
-Builder.defineMacro("__CloudABI__");
-Builder.defineMacro("__ELF__");
-
-// CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
-Builder.defineMacro("__STDC_ISO_10646__", "201206L");
-Builder.defineMacro("__STDC_UTF_16__");
-Builder.defineMacro("__STDC_UTF_32__");
-  }
-
-public:
-  CloudABITargetInfo(const llvm::Triple )
-  : OSTargetInfo(Triple) {
-this->UserLabelPrefix = "";
-  }
-};
-
 template
 class DarwinTargetInfo : public OSTargetInfo {
 protected:


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


r248538 - Use just one larger anonymous namespace instead of a lot of smaller ones.

2015-09-24 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Thu Sep 24 16:17:02 2015
New Revision: 248538

URL: http://llvm.org/viewvc/llvm-project?rev=248538=rev
Log:
Use just one larger anonymous namespace instead of a lot of smaller ones.

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

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=248538=248537=248538=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Sep 24 16:17:02 2015
@@ -83,8 +83,6 @@ public:
   }
 
 };
-} // end anonymous namespace
-
 
 static void getDarwinDefines(MacroBuilder , const LangOptions ,
  const llvm::Triple ,
@@ -185,7 +183,6 @@ static void getDarwinDefines(MacroBuilde
   PlatformMinVersion = VersionTuple(Maj, Min, Rev);
 }
 
-namespace {
 // CloudABI Target
 template 
 class CloudABITargetInfo : public OSTargetInfo {
@@ -735,7 +732,6 @@ public:
   }
 };
 
-namespace {
 // WebAssembly target
 template 
 class WebAssemblyOSTargetInfo : public OSTargetInfo {
@@ -762,7 +758,6 @@ public:
 this->TheCXXABI.set(TargetCXXABI::WebAssembly);
   }
 };
-} // end anonymous namespace
 
 
//===--===//
 // Specific target implementations.
@@ -3719,7 +3714,6 @@ public:
 Builder.defineMacro("_M_IX86", "600");
   }
 };
-} // end anonymous namespace
 
 static void addCygMingDefines(const LangOptions , MacroBuilder ) {
   // Mingw and cygwin define __declspec(a) to __attribute__((a)).  Clang 
supports
@@ -3751,7 +3745,6 @@ static void addMinGWDefines(const LangOp
   addCygMingDefines(Opts, Builder);
 }
 
-namespace {
 // x86-32 MinGW target
 class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
 public:
@@ -7125,15 +7118,12 @@ protected:
   }
 };
 
-} // end anonymous namespace.
-
 const Builtin::Info Le64TargetInfo::BuiltinInfo[] = {
 #define BUILTIN(ID, TYPE, ATTRS)   
\
   { #ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr },
 #include "clang/Basic/BuiltinsLe64.def"
 };
 
-namespace {
 static const unsigned SPIRAddrSpaceMap[] = {
 1, // opencl_global
 3, // opencl_local
@@ -7286,9 +7276,7 @@ const Builtin::Info XCoreTargetInfo::Bui
   { #ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr },
 #include "clang/Basic/BuiltinsXCore.def"
 };
-} // end anonymous namespace.
 
-namespace {
 // x86_32 Android target
 class AndroidX86_32TargetInfo : public LinuxTargetInfo {
 public:
@@ -7299,9 +7287,7 @@ public:
 LongDoubleFormat = ::APFloat::IEEEdouble;
   }
 };
-} // end anonymous namespace
 
-namespace {
 // x86_64 Android target
 class AndroidX86_64TargetInfo : public LinuxTargetInfo {
 public:
@@ -7316,7 +7302,6 @@ public:
 };
 } // end anonymous namespace
 
-
 
//===--===//
 // Driver code
 
//===--===//


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


Re: [PATCH] D13117: [DarwinDriver] Use -lto_library to specify the path for libLTO.dylib

2015-09-24 Thread Duncan P. N. Exon Smith via cfe-commits
Sorry for the review fragmentation, but I just noticed there's no test
for the new warning.  Can you add one?  After that, LGTM.

> On 2015-Sep-24, at 11:57, Bruno Cardoso Lopes  wrote:
> 
> bruno updated this revision to Diff 35664.
> bruno added a comment.
> 
> Added test per Duncan's comment.
> 
> 
> Repository:
>  rL LLVM
> 
> http://reviews.llvm.org/D13117
> 
> Files:
>  include/clang/Basic/DiagnosticDriverKinds.td
>  lib/Driver/Tools.cpp
>  test/Driver/darwin-ld.c
> 
> Index: test/Driver/darwin-ld.c
> ===
> --- test/Driver/darwin-ld.c
> +++ test/Driver/darwin-ld.c
> @@ -110,6 +110,14 @@
> // LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}}
> // LINK_OBJECT_LTO_PATH: "-object_path_lto"
> 
> +// RUN: %clang -target x86_64-apple-darwin10 -### %s \
> +// RUN:   -mlinker-version=133 -flto 2> %t.log
> +// RUN: cat %t.log
> +// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s < %t.log
> +//
> +// LINK_LTOLIB_PATH: {{ld(.exe)?"}}
> +// LINK_LTOLIB_PATH: "-lto_library"
> +
> // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \
> // RUN:   -force_load a -force_load b 2> %t.log
> // RUN: cat %t.log
> Index: lib/Driver/Tools.cpp
> ===
> --- lib/Driver/Tools.cpp
> +++ lib/Driver/Tools.cpp
> @@ -6501,15 +6501,34 @@
>options::OPT_fno_application_extension, false))
> CmdArgs.push_back("-application_extension");
> 
> -  // If we are using LTO, then automatically create a temporary file path for
> -  // the linker to use, so that it's lifetime will extend past a possible
> -  // dsymutil step.
> -  if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) {
> -const char *TmpPath = C.getArgs().MakeArgString(
> -D.GetTemporaryPath("cc", 
> types::getTypeTempSuffix(types::TY_Object)));
> -C.addTempFile(TmpPath);
> -CmdArgs.push_back("-object_path_lto");
> -CmdArgs.push_back(TmpPath);
> +  if (D.IsUsingLTO(Args)) {
> +// If we are using LTO, then automatically create a temporary file path 
> for
> +// the linker to use, so that it's lifetime will extend past a possible
> +// dsymutil step.
> +if (Version[0] >= 116 && NeedsTempPath(Inputs)) {
> +  const char *TmpPath = C.getArgs().MakeArgString(
> +  D.GetTemporaryPath("cc", 
> types::getTypeTempSuffix(types::TY_Object)));
> +  C.addTempFile(TmpPath);
> +  CmdArgs.push_back("-object_path_lto");
> +  CmdArgs.push_back(TmpPath);
> +}
> +
> +// Use -lto_library option to specify the libLTO.dylib path. Try to find
> +// it in clang installed libraries. If not found, the option is not used
> +// and 'ld' will use its default mechanism to search for libLTO.dylib.
> +if (Version[0] >= 133) {
> +  // Search for libLTO in /../lib/libLTO.dylib
> +  StringRef P = llvm::sys::path::parent_path(D.getInstalledDir());
> +  SmallString<128> LibLTOPath(P);
> +  llvm::sys::path::append(LibLTOPath, "lib");
> +  llvm::sys::path::append(LibLTOPath, "libLTO.dylib");
> +  if (llvm::sys::fs::exists(LibLTOPath)) {
> +CmdArgs.push_back("-lto_library");
> +CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
> +  } else {
> +D.Diag(diag::warn_lto_libpath);
> +  }
> +}
>   }
> 
>   // Derived from the "link" spec.
> Index: include/clang/Basic/DiagnosticDriverKinds.td
> ===
> --- include/clang/Basic/DiagnosticDriverKinds.td
> +++ include/clang/Basic/DiagnosticDriverKinds.td
> @@ -117,6 +117,7 @@
> def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, 
> please use [no]simd instead">;
> 
> def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup;
> +def warn_lto_libpath : Warning<"libLTO.dylib relative to clang installed dir 
> not found; using 'ld' default search path instead">;

^ This warning.

> def warn_drv_optimization_value : Warning<"optimization level '%0' is not 
> supported; using '%1%2' instead">,
>   InGroup;
> def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not 
> supported">,
> 
> 
> 

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


Re: [PATCH] D13081: [clang-tidy] Implement FixitHints for identifier references in IdentifierNamingCheck

2015-09-24 Thread Beren Minor via cfe-commits
berenm updated this revision to Diff 35672.
berenm added a comment.

- Do not check for identifier names from system headers
- Check for SourceLocation validity before modifying them


http://reviews.llvm.org/D13081

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -64,12 +64,11 @@
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
 // RUN:   ]}' -- -std=c++11 -fno-delayed-template-parsing
 
-// FIXME: There should be more test cases for checking that references to class
-// FIXME: name, declaration contexts, forward declarations, etc, are correctly
-// FIXME: checked and renamed
-
 // clang-format off
 
+#include 
+// Expect NO warnings or errors from system headers, it shouldn't even be checked
+
 namespace FOO_NS {
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for namespace 'FOO_NS' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}namespace foo_ns {{{$}}
@@ -104,6 +103,9 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_class'
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
 my_class();
+// CHECK-FIXES: {{^}}CMyClass();{{$}}
+~my_class();
+// CHECK-FIXES: {{^}}~CMyClass();{{$}}
 
   const int MEMBER_one_1 = ConstExpr_variable;
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: invalid case style for constant member 'MEMBER_one_1'
@@ -137,15 +139,36 @@
 
 const int my_class::classConstant = 4;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class constant 'classConstant'
-// CHECK-FIXES: {{^}}const int my_class::kClassConstant = 4;{{$}}
-// FIXME: The fixup should reflect class name fixups as well:
-// FIXME: {{^}}const int CMyClass::kClassConstant = 4;{{$}}
+// CHECK-FIXES: {{^}}const int CMyClass::kClassConstant = 4;{{$}}
 
 int my_class::ClassMember_2 = 5;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class member 'ClassMember_2'
-// CHECK-FIXES: {{^}}int my_class::ClassMember2 = 5;{{$}}
-// FIXME: The fixup should reflect class name fixups as well:
-// FIXME: {{^}}int CMyClass::ClassMember2 = 5;{{$}}
+// CHECK-FIXES: {{^}}int CMyClass::ClassMember2 = 5;{{$}}
+
+class my_derived_class : public virtual my_class {};
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_derived_class'
+// CHECK-FIXES: {{^}}class CMyDerivedClass : public virtual CMyClass {};{{$}}
+
+class CMyWellNamedClass {};
+// No warning expected as this class is well named.
+
+template
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for type template parameter 'T'
+// CHECK-FIXES: {{^}}template{{$}}
+class my_templated_class : CMyWellNamedClass {};
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_templated_class'
+// CHECK-FIXES: {{^}}class CMyTemplatedClass : CMyWellNamedClass {};{{$}}
+
+template
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for type template parameter 'T'
+// CHECK-FIXES: {{^}}template{{$}}
+class my_other_templated_class : my_templated_class, private my_derived_class {};
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for class 'my_other_templated_class'
+// CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass, private CMyDerivedClass {};{{$}}
+
+template
+using MYSUPER_TPL = my_other_templated_class<::FOO_NS::my_class>;
+// CHECK-FIXES: {{^}}using MYSUPER_TPL = CMyOtherTemplatedClass<::foo_ns::CMyClass>;{{$}}
 
 const int global_Constant = 6;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global constant 'global_Constant'
@@ -186,7 +209,7 @@
 void Global_Fun(TYPE_parameters... PARAMETER_PACK) {
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for global function 'Global_Fun'
 // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: invalid case style for parameter pack 'PARAMETER_PACK'
-// CHECK-FIXES: {{^}}void GlobalFun(TYPE_parameters... parameterPack) {{{$}}
+// CHECK-FIXES: {{^}}void GlobalFun(typeParameters_t... parameterPack) {{{$}}
 global_function(1, 2);
 // CHECK-FIXES: {{^}}GlobalFunction(1, 2);{{$}}
 FOO_bar = Global_variable;
@@ -214,6 +237,8 @@
 void non_Virtual_METHOD() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for private method 'non_Virtual_METHOD'
 // CHECK-FIXES: {{^}}void __non_Virtual_METHOD() {}{{$}}
+
+public:
 static void CLASS_METHOD() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for class method 'CLASS_METHOD'
 // CHECK-FIXES: {{^}}static void classMethod() {}{{$}}
@@ -244,23 +269,28 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: invalid case style for struct 'THIS___Structure'
 // CHECK-FIXES: {{^}}struct this_structure {{{$}}
 

r248537 - fix typos; NFC

2015-09-24 Thread Sanjay Patel via cfe-commits
Author: spatel
Date: Thu Sep 24 16:11:52 2015
New Revision: 248537

URL: http://llvm.org/viewvc/llvm-project?rev=248537=rev
Log:
fix typos; NFC

Modified:
cfe/trunk/include/clang/Lex/PPCallbacks.h

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=248537=248536=248537=diff
==
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Thu Sep 24 16:11:52 2015
@@ -201,19 +201,19 @@ public:
  PragmaMessageKind Kind, StringRef Str) {
   }
 
-  /// \brief Callback invoked when a \#pragma gcc dianostic push directive
+  /// \brief Callback invoked when a \#pragma gcc diagnostic push directive
   /// is read.
   virtual void PragmaDiagnosticPush(SourceLocation Loc,
 StringRef Namespace) {
   }
 
-  /// \brief Callback invoked when a \#pragma gcc dianostic pop directive
+  /// \brief Callback invoked when a \#pragma gcc diagnostic pop directive
   /// is read.
   virtual void PragmaDiagnosticPop(SourceLocation Loc,
StringRef Namespace) {
   }
 
-  /// \brief Callback invoked when a \#pragma gcc dianostic directive is read.
+  /// \brief Callback invoked when a \#pragma gcc diagnostic directive is read.
   virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
 diag::Severity mapping, StringRef Str) {}
 


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


r248516 - [analyzer] When memcpy'ing into a fixed-size array, do not invalidate entire region.

2015-09-24 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Thu Sep 24 11:52:56 2015
New Revision: 248516

URL: http://llvm.org/viewvc/llvm-project?rev=248516=rev
Log:
[analyzer] When memcpy'ing into a fixed-size array, do not invalidate entire 
region.

Change the analyzer's modeling of memcpy to be more precise when copying into 
fixed-size
array fields. With this change, instead of invalidating the entire containing 
region the
analyzer now invalidates only offsets for the array itself when it can show 
that the
memcpy stays within the bounds of the array.

This addresses false positive memory leak warnings of the kind reported by
krzysztof in https://llvm.org/bugs/show_bug.cgi?id=22954

(This is the second attempt, now with assertion failures resolved.)

A patch by Pierre Gousseau!

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

Added:
cfe/trunk/test/Analysis/pr22954.c
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h?rev=248516=248515=248516=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h Thu 
Sep 24 11:52:56 2015
@@ -46,7 +46,7 @@ class RegionOffset {
   /// The base region.
   const MemRegion *R;
 
-  /// The bit offset within the base region. It shouldn't be negative.
+  /// The bit offset within the base region. Can be negative.
   int64_t Offset;
 
 public:
@@ -1333,7 +1333,9 @@ public:
 /// Tells that a region's contents is not changed.
 TK_PreserveContents = 0x1,
 /// Suppress pointer-escaping of a region.
-TK_SuppressEscape = 0x2
+TK_SuppressEscape = 0x2,
+// Do not invalidate super region.
+TK_DoNotInvalidateSuperRegion = 0x4
 
 // Do not forget to extend StorageTypeForKinds if number of traits exceed 
 // the number of bits StorageTypeForKinds can store.

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=248516=248515=248516=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Thu Sep 24 
11:52:56 2015
@@ -145,7 +145,8 @@ public:
   static ProgramStateRef InvalidateBuffer(CheckerContext ,
   ProgramStateRef state,
   const Expr *Ex, SVal V,
-  bool IsSourceBuffer);
+  bool IsSourceBuffer,
+  const Expr *Size);
 
   static bool SummarizeRegion(raw_ostream , ASTContext ,
   const MemRegion *MR);
@@ -193,6 +194,14 @@ public:
 ProgramStateRef state,
 NonLoc left,
 NonLoc right) const;
+
+  // Return true if the destination buffer of the copy function may be in 
bound.
+  // Expects SVal of Size to be positive and unsigned.
+  // Expects SVal of FirstBuf to be a FieldRegion.
+  static bool IsFirstBufInBound(CheckerContext ,
+ProgramStateRef state,
+const Expr *FirstBuf,
+const Expr *Size);
 };
 
 } //end anonymous namespace
@@ -814,10 +823,74 @@ const StringLiteral *CStringChecker::get
   return strRegion->getStringLiteral();
 }
 
+bool CStringChecker::IsFirstBufInBound(CheckerContext ,
+   ProgramStateRef state,
+   const Expr *FirstBuf,
+   const Expr *Size) {
+  // If we do not know that the buffer is long enough we return 'true'.
+  // Otherwise the parent region of this field region would also get
+  // invalidated, which would lead to warnings based on an unknown state.
+
+  // Originally copied from CheckBufferAccess and CheckLocation.
+  SValBuilder  = C.getSValBuilder();
+  ASTContext  = svalBuilder.getContext();
+  const LocationContext *LCtx = C.getLocationContext();
+
+  QualType sizeTy = Size->getType();
+  QualType PtrTy = Ctx.getPointerType(Ctx.CharTy);
+  SVal BufVal = state->getSVal(FirstBuf, LCtx);
+
+  SVal LengthVal = state->getSVal(Size, LCtx);
+  Optional Length = LengthVal.getAs();
+  if (!Length)
+return true; // cf top comment.
+
+  // Compute the offset of the last element to be accessed: 

Re: [PATCH] D12571: [Analyzer] Fix assertions in commit r246345 (pr22954).

2015-09-24 Thread Devin Coughlin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248516: [analyzer] When memcpy'ing into a fixed-size array, 
do not invalidate entire… (authored by dcoughlin).

Changed prior to commit:
  http://reviews.llvm.org/D12571?vs=35505=35644#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12571

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/pr22954.c

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -145,7 +145,8 @@
   static ProgramStateRef InvalidateBuffer(CheckerContext ,
   ProgramStateRef state,
   const Expr *Ex, SVal V,
-  bool IsSourceBuffer);
+  bool IsSourceBuffer,
+  const Expr *Size);
 
   static bool SummarizeRegion(raw_ostream , ASTContext ,
   const MemRegion *MR);
@@ -193,6 +194,14 @@
 ProgramStateRef state,
 NonLoc left,
 NonLoc right) const;
+
+  // Return true if the destination buffer of the copy function may be in bound.
+  // Expects SVal of Size to be positive and unsigned.
+  // Expects SVal of FirstBuf to be a FieldRegion.
+  static bool IsFirstBufInBound(CheckerContext ,
+ProgramStateRef state,
+const Expr *FirstBuf,
+const Expr *Size);
 };
 
 } //end anonymous namespace
@@ -814,10 +823,74 @@
   return strRegion->getStringLiteral();
 }
 
+bool CStringChecker::IsFirstBufInBound(CheckerContext ,
+   ProgramStateRef state,
+   const Expr *FirstBuf,
+   const Expr *Size) {
+  // If we do not know that the buffer is long enough we return 'true'.
+  // Otherwise the parent region of this field region would also get
+  // invalidated, which would lead to warnings based on an unknown state.
+
+  // Originally copied from CheckBufferAccess and CheckLocation.
+  SValBuilder  = C.getSValBuilder();
+  ASTContext  = svalBuilder.getContext();
+  const LocationContext *LCtx = C.getLocationContext();
+
+  QualType sizeTy = Size->getType();
+  QualType PtrTy = Ctx.getPointerType(Ctx.CharTy);
+  SVal BufVal = state->getSVal(FirstBuf, LCtx);
+
+  SVal LengthVal = state->getSVal(Size, LCtx);
+  Optional Length = LengthVal.getAs();
+  if (!Length)
+return true; // cf top comment.
+
+  // Compute the offset of the last element to be accessed: size-1.
+  NonLoc One = svalBuilder.makeIntVal(1, sizeTy).castAs();
+  NonLoc LastOffset =
+  svalBuilder.evalBinOpNN(state, BO_Sub, *Length, One, sizeTy)
+  .castAs();
+
+  // Check that the first buffer is sufficiently long.
+  SVal BufStart = svalBuilder.evalCast(BufVal, PtrTy, FirstBuf->getType());
+  Optional BufLoc = BufStart.getAs();
+  if (!BufLoc)
+return true; // cf top comment.
+
+  SVal BufEnd =
+  svalBuilder.evalBinOpLN(state, BO_Add, *BufLoc, LastOffset, PtrTy);
+
+  // Check for out of bound array element access.
+  const MemRegion *R = BufEnd.getAsRegion();
+  if (!R)
+return true; // cf top comment.
+
+  const ElementRegion *ER = dyn_cast(R);
+  if (!ER)
+return true; // cf top comment.
+
+  assert(ER->getValueType() == C.getASTContext().CharTy &&
+ "IsFirstBufInBound should only be called with char* ElementRegions");
+
+  // Get the size of the array.
+  const SubRegion *superReg = cast(ER->getSuperRegion());
+  SVal Extent =
+  svalBuilder.convertToArrayIndex(superReg->getExtent(svalBuilder));
+  DefinedOrUnknownSVal ExtentSize = Extent.castAs();
+
+  // Get the index of the accessed element.
+  DefinedOrUnknownSVal Idx = ER->getIndex().castAs();
+
+  ProgramStateRef StInBound = state->assumeInBound(Idx, ExtentSize, true);
+
+  return static_cast(StInBound);
+}
+
 ProgramStateRef CStringChecker::InvalidateBuffer(CheckerContext ,
  ProgramStateRef state,
  const Expr *E, SVal V,
- bool IsSourceBuffer) {
+ bool IsSourceBuffer,
+ const Expr *Size) {
   Optional L = V.getAs();
   if (!L)
 return state;
@@ -847,6 +920,16 @@

Re: [PATCH] D13128: Fix backend crash on multiple close of stdout.

2015-09-24 Thread Alexey Bataev via cfe-commits
ABataev updated the summary for this revision.
ABataev updated this revision to Diff 35698.
ABataev added a comment.

Reworked patch after some discussion


http://reviews.llvm.org/D13128

Files:
  lib/Support/raw_ostream.cpp
  test/Other/empty.ll

Index: lib/Support/raw_ostream.cpp
===
--- lib/Support/raw_ostream.cpp
+++ lib/Support/raw_ostream.cpp
@@ -490,8 +490,8 @@
 static int getFD(StringRef Filename, std::error_code ,
  sys::fs::OpenFlags Flags) {
   // Handle "-" as stdout. Note that when we do this, we consider ourself
-  // the owner of stdout. This means that we can do things like close the
-  // file descriptor when we're done and set the "binary" flag globally.
+  // the owner of stdout. This means that we can do things like set the 
"binary"
+  // flag globally.
   if (Filename == "-") {
 EC = std::error_code();
 // If user requested binary then put stdout into binary mode if
@@ -523,6 +523,10 @@
 return;
   }
 
+  // Do not close standard input/output streams.
+  if (FD <= STDERR_FILENO)
+ShouldClose = false;
+
   // Get the starting position.
   off_t loc = ::lseek(FD, 0, SEEK_CUR);
 #ifdef LLVM_ON_WIN32
Index: test/Other/empty.ll
===
--- test/Other/empty.ll
+++ test/Other/empty.ll
@@ -0,0 +1,2 @@
+; RUN: /export/bpart/_users/abataev/development/llvm_commit3/build/bin/opt 
-analyze -time-passes -rewrite-map-file=- -stats -info-output-file=- %s 2>&1 | 
FileCheck %s
+; CHECK: Total Execution Time


Index: lib/Support/raw_ostream.cpp
===
--- lib/Support/raw_ostream.cpp
+++ lib/Support/raw_ostream.cpp
@@ -490,8 +490,8 @@
 static int getFD(StringRef Filename, std::error_code ,
  sys::fs::OpenFlags Flags) {
   // Handle "-" as stdout. Note that when we do this, we consider ourself
-  // the owner of stdout. This means that we can do things like close the
-  // file descriptor when we're done and set the "binary" flag globally.
+  // the owner of stdout. This means that we can do things like set the "binary"
+  // flag globally.
   if (Filename == "-") {
 EC = std::error_code();
 // If user requested binary then put stdout into binary mode if
@@ -523,6 +523,10 @@
 return;
   }
 
+  // Do not close standard input/output streams.
+  if (FD <= STDERR_FILENO)
+ShouldClose = false;
+
   // Get the starting position.
   off_t loc = ::lseek(FD, 0, SEEK_CUR);
 #ifdef LLVM_ON_WIN32
Index: test/Other/empty.ll
===
--- test/Other/empty.ll
+++ test/Other/empty.ll
@@ -0,0 +1,2 @@
+; RUN: /export/bpart/_users/abataev/development/llvm_commit3/build/bin/opt -analyze -time-passes -rewrite-map-file=- -stats -info-output-file=- %s 2>&1 | FileCheck %s
+; CHECK: Total Execution Time
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D13157: Teach -Wtautological-overlap-compare about enums

2015-09-24 Thread George Burgess IV via cfe-commits
george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rtrieu.
george.burgess.iv added a subscriber: cfe-commits.

Currently, -Wtautological-overlap-compare only emits warnings if the 
comparisons are between integer literals and variables. This patch adds support 
for comparison between variables and enums if the user's intent seems 
moderately obvious.

Richard -- I chose you for review because it looks like you touched the code 
last. If you're busy, I'm happy to petition others :)

http://reviews.llvm.org/D13157

Files:
  lib/Analysis/CFG.cpp
  test/Sema/warn-overlap.c

Index: test/Sema/warn-overlap.c
===
--- test/Sema/warn-overlap.c
+++ test/Sema/warn-overlap.c
@@ -2,6 +2,16 @@
 
 #define mydefine 2
 
+enum Choices {
+  CHOICE_0 = 0,
+  CHOICE_1 = 1
+};
+
+enum Unchoices {
+  UNCHOICE_0 = 0,
+  UNCHOICE_1 = 1
+};
+
 void f(int x) {
   int y = 0;
 
@@ -54,6 +64,30 @@
 
   if (x == mydefine && x > 3) { }
   if (x == (mydefine + 1) && x > 3) { }
+
+  if (x != CHOICE_0 || x != CHOICE_1) { } // expected-warning {{overlapping comparisons always evaluate to true}}
+  if (x == CHOICE_0 && x == CHOICE_1) { } // expected-warning {{overlapping comparisons always evaluate to false}}
+
+  // Don't warn if comparing x to different types
+  if (x == CHOICE_0 && x == 1) { }
+  if (x != CHOICE_0 || x != 1) { }
+
+  // "Different types" includes different enums
+  if (x == CHOICE_0 && x == UNCHOICE_1) { }
+  if (x != CHOICE_0 || x != UNCHOICE_1) { }
+}
+
+void enums(enum Choices c) {
+  if (c != CHOICE_0 || c != CHOICE_1) { } // expected-warning {{overlapping comparisons always evaluate to true}}
+  if (c == CHOICE_0 && c == CHOICE_1) { } // expected-warning {{overlapping comparisons always evaluate to false}}
+
+  // Don't warn if comparing x to different types
+  if (c == CHOICE_0 && c == 1) { }
+  if (c != CHOICE_0 || c != 1) { }
+
+  // "Different types" includes different enums
+  if (c == CHOICE_0 && c == UNCHOICE_1) { }
+  if (c != CHOICE_0 || c != UNCHOICE_1) { }
 }
 
 // Don't generate a warning here.
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -39,6 +39,69 @@
   return D->getLocation();
 }
 
+/// Tries to interpret a binary operator into `Decl Op Expr` form, if Expr is
+/// an integer literal or an enum constant.
+///
+/// If this fails, at least one of the returned DeclRefExpr or Expr will be
+/// null.
+static std::tuple
+tryNormalizeBinaryOperator(const BinaryOperator *B) {
+  auto TryTransformToIntOrEnumConstant = [](const Expr *E) -> const Expr * {
+E = E->IgnoreParens();
+if (isa(E))
+  return E;
+auto *DR = dyn_cast(E->IgnoreParenImpCasts());
+if (DR == nullptr)
+  return nullptr;
+return isa(DR->getDecl()) ? DR : nullptr;
+  };
+
+  BinaryOperatorKind Op = B->getOpcode();
+
+  const Expr *MaybeDecl = B->getLHS();
+  const Expr *Constant = TryTransformToIntOrEnumConstant(B->getRHS());
+  // Expr looked like `0 == Foo` instead of `Foo == 0`
+  if (Constant == nullptr) {
+// Flip the operator
+if (Op == BO_GT)
+  Op = BO_LT;
+else if (Op == BO_GE)
+  Op = BO_LE;
+else if (Op == BO_LT)
+  Op = BO_GT;
+else if (Op == BO_LE)
+  Op = BO_GE;
+
+MaybeDecl = B->getRHS();
+Constant = TryTransformToIntOrEnumConstant(B->getLHS());
+  }
+
+  auto *D = dyn_cast(MaybeDecl->IgnoreParenImpCasts());
+  return std::make_tuple(D, Op, Constant);
+}
+
+/// For an expression `x == Foo && x == Bar`, this determines whether the
+/// `Foo` and `Bar` are either of the same enumeration type, or both integer
+/// literals.
+static bool areExprTypesCompatible(const Expr *A, const Expr *B) {
+  // User intent isn't clear if they're mixing int literals with enum
+  // constants.
+  if (isa(A) != isa(B))
+return false;
+
+  // Integer literal comparisons, regardless of literal type, are acceptable.
+  if (isa(A))
+return true;
+
+  // Currently we're only given EnumConstantDecls or IntegerLiterals
+  auto *C1 = cast(cast(A)->getDecl());
+  auto *C2 = cast(cast(B)->getDecl());
+
+  const TagDecl *E1 = TagDecl::castFromDeclContext(C1->getDeclContext());
+  const TagDecl *E2 = TagDecl::castFromDeclContext(C2->getDeclContext());
+  return E1 == E2;
+}
+
 class CFGBuilder;
   
 /// The CFG builder uses a recursive algorithm to build the CFG.  When
@@ -694,56 +757,35 @@
 if (!LHS->isComparisonOp() || !RHS->isComparisonOp())
   return TryResult();
 
-BinaryOperatorKind BO1 = LHS->getOpcode();
-const DeclRefExpr *Decl1 =
-dyn_cast(LHS->getLHS()->IgnoreParenImpCasts());
-const IntegerLiteral *Literal1 =
-dyn_cast(LHS->getRHS()->IgnoreParens());
-if (!Decl1 && !Literal1) {
-  if (BO1 == BO_GT)
-BO1 = BO_LT;
-  else if (BO1 == BO_GE)
-BO1 = BO_LE;
-  else if (BO1 == BO_LT)
-BO1 = BO_GT;
-  else if