[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-16 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 161165.
mgrang edited the summary of this revision.
mgrang added a comment.

Added checks for more algorithms: stable_sort, is_sorted, partial_sort, 
partition, stable_partition, nth_element.


https://reviews.llvm.org/D50488

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
  test/Analysis/ptr-sort.cpp

Index: test/Analysis/ptr-sort.cpp
===
--- /dev/null
+++ test/Analysis/ptr-sort.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.nondeterminism.PointerSorting %s -analyzer-output=text -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+namespace std {
+  template
+  bool is_sorted(ForwardIt first, ForwardIt last);
+
+  template 
+  void nth_element(RandomIt first, RandomIt nth, RandomIt last);
+
+  template
+  void partial_sort(RandomIt first, RandomIt middle, RandomIt last);
+
+  template
+  void sort (RandomIt first, RandomIt last);
+
+  template
+  void stable_sort(RandomIt first, RandomIt last);
+
+  template
+  BidirIt partition(BidirIt first, BidirIt last, UnaryPredicate p);
+
+  template
+  BidirIt stable_partition(BidirIt first, BidirIt last, UnaryPredicate p);
+}
+
+bool f (int x) { return true; }
+bool g (int *x) { return true; }
+
+void PointerSorting() {
+  int a = 1, b = 2, c = 3;
+  std::vector V1 = {a, b};
+  std::vector V2 = {, };
+
+  std::is_sorted(V1.begin(), V1.end());// no-warning
+  std::nth_element(V1.begin(), V1.begin() + 1, V1.end());  // no-warning
+  std::partial_sort(V1.begin(), V1.begin() + 1, V1.end()); // no-warning
+  std::sort(V1.begin(), V1.end()); // no-warning
+  std::stable_sort(V1.begin(), V1.end());  // no-warning
+  std::partition(V1.begin(), V1.end(), f); // no-warning
+  std::stable_partition(V1.begin(), V1.end(), g);  // no-warning
+
+  std::is_sorted(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::nth_element(V2.begin(), V2.begin() + 1, V2.end()); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::partial_sort(V2.begin(), V2.begin() + 1, V2.end()); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::stable_sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::partition(V2.begin(), V2.end(), f); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  std::stable_partition(V2.begin(), V2.end(), g); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+}
Index: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
===
--- /dev/null
+++ lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
@@ -0,0 +1,110 @@
+//===-- PointerSortingChecker.cpp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file defines PointerSortingChecker which checks for non-determinism
+// caused due to sorting containers with pointer-like elements.
+//

[PATCH] D50883: [clang-tidy] Handle unique owning smart pointers in ExprMutationAnalyzer

2018-08-16 Thread Shuai Wang via Phabricator via cfe-commits
shuaiwang created this revision.
shuaiwang added a reviewer: hokein.
Herald added subscribers: cfe-commits, Szelethus, a.sidorin, xazax.hun.
Herald added a reviewer: george.karpenkov.

For smart pointers like std::unique_ptr which uniquely owns the
underlying object, treat the mutation of the pointee as mutation of the
smart pointer itself.

This gives better behavior for cases like this:

  void f(std::vector> v) { // undesirable analyze result 
of `v` as not mutated.
for (auto& p : v) {
p->mutate(); // only const member function `operator->` is invoked on 
`p`
}
  }


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50883

Files:
  clang-tidy/utils/ExprMutationAnalyzer.cpp
  unittests/clang-tidy/ExprMutationAnalyzerTest.cpp

Index: unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
===
--- unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
+++ unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
@@ -606,6 +606,59 @@
   EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.f()"));
 }
 
+TEST(ExprMutationAnalyzerTest, UniquePtr) {
+  const std::string UniquePtrDef =
+  "template  struct UniquePtr {"
+  "  UniquePtr();"
+  "  UniquePtr(const UniquePtr&) = delete;"
+  "  UniquePtr(UniquePtr&&);"
+  "  UniquePtr& operator=(const UniquePtr&) = delete;"
+  "  UniquePtr& operator=(UniquePtr&&);"
+  "  T& operator*() const;"
+  "  T* operator->() const;"
+  "};";
+
+  auto AST = tooling::buildASTFromCode(
+  UniquePtrDef + "void f() { UniquePtr x; *x = 10; }");
+  auto Results =
+  match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("* x = 10"));
+
+  AST = tooling::buildASTFromCode(UniquePtrDef +
+  "void f() { UniquePtr x; *x; }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+
+  AST = tooling::buildASTFromCode(UniquePtrDef +
+  "void f() { UniquePtr x; *x; }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+
+  AST = tooling::buildASTFromCode(UniquePtrDef +
+  "struct S { int v; };"
+  "void f() { UniquePtr x; x->v; }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x"));
+
+  AST = tooling::buildASTFromCode(UniquePtrDef +
+  "struct S { int v; };"
+  "void f() { UniquePtr x; x->v; }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+
+  AST = tooling::buildASTFromCode(UniquePtrDef +
+  "struct S { void mf(); };"
+  "void f() { UniquePtr x; x->mf(); }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x"));
+
+  AST = tooling::buildASTFromCode(
+  UniquePtrDef + "struct S { void mf() const; };"
+ "void f() { UniquePtr x; x->mf(); }");
+  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  EXPECT_FALSE(isMutated(Results, AST.get()));
+}
+
 } // namespace test
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/utils/ExprMutationAnalyzer.cpp
===
--- clang-tidy/utils/ExprMutationAnalyzer.cpp
+++ clang-tidy/utils/ExprMutationAnalyzer.cpp
@@ -51,6 +51,20 @@
   return referenceType(pointee(unless(isConstQualified(;
 };
 
+const auto nonConstPointerType = [] {
+  return pointerType(pointee(unless(isConstQualified(;
+};
+
+const auto isMoveOnly = [] {
+  return cxxRecordDecl(
+  hasMethod(cxxConstructorDecl(isMoveConstructor(), unless(isDeleted(,
+  hasMethod(cxxMethodDecl(isMoveAssignmentOperator(), unless(isDeleted(,
+  unless(anyOf(hasMethod(cxxConstructorDecl(isCopyConstructor(),
+unless(isDeleted(,
+   hasMethod(cxxMethodDecl(isCopyAssignmentOperator(),
+   unless(isDeleted()));
+};
+
 } // namespace
 
 const Stmt *ExprMutationAnalyzer::findMutation(const Expr *Exp) {
@@ -163,6 +177,15 @@
   const auto AsPointerFromArrayDecay =
   castExpr(hasCastKind(CK_ArrayToPointerDecay),
unless(hasParent(arraySubscriptExpr())), has(equalsNode(Exp)));
+  // Treat calling `operator->()` of move-only classes as taking address.
+  // These are typically smart pointers with unique ownership so we treat
+  // mutation of pointee as mutation of the smart pointer 

[PATCH] D50882: [ThinLTO] Correct documentation on default number of threads

2018-08-16 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini accepted this revision.
mehdi_amini added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D50882



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


r339979 - [hexagon] restore -fuse-cxa-atexit by default

2018-08-16 Thread Brian Cain via cfe-commits
Author: bcain
Date: Thu Aug 16 20:53:51 2018
New Revision: 339979

URL: http://llvm.org/viewvc/llvm-project?rev=339979=rev
Log:
[hexagon] restore -fuse-cxa-atexit by default

"-fno-use-cxa-atexit" was a default provided by the initial
commit offering hexagon support.  This is no longer required.

Reviewers: bcahoon, sidneym

Subscribers: llvm-commits

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


Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/cxa-atexit.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=339979=339978=339979=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Aug 16 20:53:51 2018
@@ -4225,7 +4225,6 @@ void Clang::ConstructJob(Compilation ,
   options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
   !RawTriple.isOSWindows() &&
   RawTriple.getOS() != llvm::Triple::Solaris &&
-  getToolChain().getArch() != llvm::Triple::hexagon &&
   getToolChain().getArch() != llvm::Triple::xcore &&
   ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||

Modified: cfe/trunk/test/Driver/cxa-atexit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cxa-atexit.cpp?rev=339979=339978=339979=diff
==
--- cfe/trunk/test/Driver/cxa-atexit.cpp (original)
+++ cfe/trunk/test/Driver/cxa-atexit.cpp Thu Aug 16 20:53:51 2018
@@ -20,7 +20,7 @@
 
 // CHECK-WINDOWS: "-fno-use-cxa-atexit"
 // CHECK-SOLARIS: "-fno-use-cxa-atexit"
-// CHECK-HEXAGON: "-fno-use-cxa-atexit"
+// CHECK-HEXAGON-NOT: "-fno-use-cxa-atexit"
 // CHECK-XCORE: "-fno-use-cxa-atexit"
 // CHECK-MTI: "-fno-use-cxa-atexit"
 // CHECK-MIPS-NOT: "-fno-use-cxa-atexit"


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


[PATCH] D50882: [ThinLTO] Correct documentation on default number of threads

2018-08-16 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: pcc.
Herald added subscribers: dexonsmith, steven_wu, eraman, inglorion, mehdi_amini.

The number of threads used for ThinLTO backend parallelism was
dropped to the number of cores in r284618 to avoid oversubscribing
physical cores due to hyperthreading. This updates the documentation
to reflect that change.

Fixes PR38610.


Repository:
  rC Clang

https://reviews.llvm.org/D50882

Files:
  docs/ThinLTO.rst


Index: docs/ThinLTO.rst
===
--- docs/ThinLTO.rst
+++ docs/ThinLTO.rst
@@ -105,7 +105,9 @@
 ---
 .. _parallelism:
 
-By default, the ThinLTO link step will launch up to
+By default, the ThinLTO link step will launch as many
+threads in parallel as there are cores. If the number of
+cores can't be computed for the architecture, then it will launch
 ``std::thread::hardware_concurrency`` number of threads in parallel.
 For machines with hyper-threading, this is the total number of
 virtual cores. For some applications and machine configurations this


Index: docs/ThinLTO.rst
===
--- docs/ThinLTO.rst
+++ docs/ThinLTO.rst
@@ -105,7 +105,9 @@
 ---
 .. _parallelism:
 
-By default, the ThinLTO link step will launch up to
+By default, the ThinLTO link step will launch as many
+threads in parallel as there are cores. If the number of
+cores can't be computed for the architecture, then it will launch
 ``std::thread::hardware_concurrency`` number of threads in parallel.
 For machines with hyper-threading, this is the total number of
 virtual cores. For some applications and machine configurations this
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50816: [hexagon] restore -fuse-cxa-atexit by default

2018-08-16 Thread Brian Cain via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339979: [hexagon] restore -fuse-cxa-atexit by default 
(authored by bcain, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50816?vs=160928=161160#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50816

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/cxa-atexit.cpp


Index: test/Driver/cxa-atexit.cpp
===
--- test/Driver/cxa-atexit.cpp
+++ test/Driver/cxa-atexit.cpp
@@ -20,7 +20,7 @@
 
 // CHECK-WINDOWS: "-fno-use-cxa-atexit"
 // CHECK-SOLARIS: "-fno-use-cxa-atexit"
-// CHECK-HEXAGON: "-fno-use-cxa-atexit"
+// CHECK-HEXAGON-NOT: "-fno-use-cxa-atexit"
 // CHECK-XCORE: "-fno-use-cxa-atexit"
 // CHECK-MTI: "-fno-use-cxa-atexit"
 // CHECK-MIPS-NOT: "-fno-use-cxa-atexit"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4225,7 +4225,6 @@
   options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
   !RawTriple.isOSWindows() &&
   RawTriple.getOS() != llvm::Triple::Solaris &&
-  getToolChain().getArch() != llvm::Triple::hexagon &&
   getToolChain().getArch() != llvm::Triple::xcore &&
   ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||


Index: test/Driver/cxa-atexit.cpp
===
--- test/Driver/cxa-atexit.cpp
+++ test/Driver/cxa-atexit.cpp
@@ -20,7 +20,7 @@
 
 // CHECK-WINDOWS: "-fno-use-cxa-atexit"
 // CHECK-SOLARIS: "-fno-use-cxa-atexit"
-// CHECK-HEXAGON: "-fno-use-cxa-atexit"
+// CHECK-HEXAGON-NOT: "-fno-use-cxa-atexit"
 // CHECK-XCORE: "-fno-use-cxa-atexit"
 // CHECK-MTI: "-fno-use-cxa-atexit"
 // CHECK-MIPS-NOT: "-fno-use-cxa-atexit"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4225,7 +4225,6 @@
   options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
   !RawTriple.isOSWindows() &&
   RawTriple.getOS() != llvm::Triple::Solaris &&
-  getToolChain().getArch() != llvm::Triple::hexagon &&
   getToolChain().getArch() != llvm::Triple::xcore &&
   ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50766: Fix false positive unsequenced access and modification warning in array subscript expression.

2018-08-16 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete requested changes to this revision.
Rakete added a comment.
This revision now requires changes to proceed.

Your patch breaks a lot of stuff in the test suite. For example:

  void f() {
int A = 0;
(A++, A) = 1; // warning from this patch, but this is perfectly valid since 
forever.
  }

Also, you don't take into account the fact that the rule you mention was added 
in C++17. In versions prior to that (and C!), the warning is not a false 
positive.


https://reviews.llvm.org/D50766



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


[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 161155.
ahatanak marked an inline comment as done.
ahatanak added a comment.

Mark the block descriptor global variable as `unnamed_addr`.


Repository:
  rC Clang

https://reviews.llvm.org/D50783

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBlocks.h
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/CGObjCRuntime.h
  test/CodeGenCXX/blocks.cpp
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
  test/CodeGenObjC/fragile-arc.m
  test/CodeGenObjC/noescape.m

Index: test/CodeGenObjC/noescape.m
===
--- test/CodeGenObjC/noescape.m
+++ test/CodeGenObjC/noescape.m
@@ -17,7 +17,11 @@
 // helper functions.
 
 // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK: @[[BLOCK_DESCIPTOR_TMP_2:.*]] = internal constant { i64, i64, i8*, i64 } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
+
+// When the block is non-escaping, copy/dispose helpers aren't generated, so the
+// block layout string must include information about __strong captures.
+
+// CHECK: @[[BLOCK_DESCIPTOR_TMP_2:.*ls32l8"]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i64 } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
 
 // CHECK-LABEL: define void @test0(
 // CHECK: call void @noescapeFunc0({{.*}}, {{.*}} nocapture {{.*}})
Index: test/CodeGenObjC/fragile-arc.m
===
--- test/CodeGenObjC/fragile-arc.m
+++ test/CodeGenObjC/fragile-arc.m
@@ -126,13 +126,13 @@
 extern void useBlock(void (^block)(void));
 
 //  256 == 0x100 == starts with 1 strong
-// GLOBALS: @__block_descriptor_tmp{{.*}} = internal constant {{.*}}, i32 256 }
+// GLOBALS: @"__block_descriptor{{.*}} = linkonce_odr hidden {{.*}}, i32 256 }
 void testBlockLayoutStrong(id x) {
   useBlock(^{ (void) x; });
 }
 
 //  1   == 0x001 == starts with 1 weak
-// GLOBALS: @__block_descriptor_tmp{{.*}} = internal constant {{.*}}, i32 1 }
+// GLOBALS: @"__block_descriptor{{.*}} = linkonce_odr hidden {{.*}}, i32 1 }
 void testBlockLayoutWeak(__weak id x) {
   useBlock(^{ (void) x; });
 }
Index: test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
===
--- test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
+++ test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
@@ -30,7 +30,8 @@
   void (^block4)() = ^{ printf("%c %#lx", ch, fourByte); NSLog(@"%@", strong); };
 
   // Test5
-  // CHECK: Inline block variable layout: 0x0100, BL_STRONG:1, BL_OPERATOR:0
+  // Nothing gets printed here since the descriptor of this block is merged with
+  // the descriptor of Test3's block.
   void (^block5)() = ^{ NSLog(@"%@", strong); printf("%c %#llx", ch, eightByte); };
 
   // Test6
Index: test/CodeGenObjC/arc-blocks.m
===
--- test/CodeGenObjC/arc-blocks.m
+++ test/CodeGenObjC/arc-blocks.m
@@ -2,15 +2,10 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-UNOPT -check-prefix=CHECK-COMMON %s
 
 // CHECK-COMMON: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, align 8
-// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8

Buildbot numbers for the week of 8/05/2018 - 8/11/2018

2018-08-16 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the last week of 8/05/2018 - 8/11/2018.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
   buildername| was_red
--+-
 clang-x86_64-linux-selfhost-modules  | 30:22:42
 clang-x64-ninja-win7 | 28:55:54
 aosp-O3-polly-before-vectorizer-unprofitable | 27:20:19
 clang-lld-x86_64-2stage  | 26:49:33
 lld-x86_64-darwin13  | 24:20:25
 clang-cmake-aarch64-full | 19:33:39
 clang-x86-windows-msvc2015   | 15:36:50
 clang-with-lto-ubuntu| 14:57:09
 clang-with-thin-lto-ubuntu   | 14:53:10
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast | 13:54:29
 sanitizer-windows| 13:44:27
 llvm-sphinx-docs | 11:46:11
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx2a   | 10:47:21
 clang-cmake-thumbv7-full-sh  | 08:10:02
 lldb-amd64-ninja-netbsd8 | 08:06:13
 clang-cmake-aarch64-lld  | 07:52:40
 clang-cmake-armv7-full   | 06:48:56
 clang-cmake-aarch64-global-isel  | 05:57:24
 clang-cmake-armv7-selfhost   | 05:51:06
 clang-cmake-armv7-selfhost-neon  | 05:49:55
 clang-ppc64le-linux-multistage   | 05:44:48
 clang-cmake-armv7-quick  | 05:05:11
 sanitizer-ppc64le-linux  | 05:02:51
 llvm-hexagon-elf | 04:58:46
 sanitizer-x86_64-linux-fast  | 04:43:30
 sanitizer-x86_64-linux-bootstrap | 04:39:34
 reverse-iteration| 04:19:50
 clang-hexagon-elf| 03:52:58
 libcxx-libcxxabi-x86_64-linux-ubuntu-msan| 03:47:03
 sanitizer-x86_64-linux   | 03:34:47
 libcxx-libcxxabi-x86_64-linux-ubuntu-tsan| 03:33:24
 clang-cmake-x86_64-avx2-linux| 03:14:19
 clang-sphinx-docs| 03:07:27
 clang-s390x-linux-lnt| 02:56:18
 clang-cmake-armv8-quick  | 02:56:16
 clang-cmake-armv8-full   | 02:56:06
 clang-cmake-armv8-global-isel| 02:52:47
 clang-s390x-linux| 02:43:52
 llvm-clang-x86_64-expensive-checks-win   | 02:43:29
 clang-cmake-thumbv8-full-sh  | 02:38:41
 clang-cmake-armv8-selfhost-neon  | 02:38:13
 sanitizer-ppc64be-linux  | 02:35:59
 clang-ppc64le-linux  | 02:35:49
 sanitizer-x86_64-linux-bootstrap-msan| 02:32:44
 clang-cuda-build | 02:32:43
 clang-ppc64be-linux-lnt  | 02:28:34
 clang-ppc64be-linux  | 02:27:29
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast   | 02:23:52
 clang-cmake-x86_64-sde-avx512-linux  | 02:23:50
 clang-cmake-armv7-global-isel| 02:18:09
 sanitizer-x86_64-linux-bootstrap-ubsan   | 02:16:26
 clang-s390x-linux-multistage | 02:12:58
 sanitizer-x86_64-linux-android   | 02:08:51
 clang-ppc64le-linux-lnt  | 02:06:58
 clang-ppc64be-linux-multistage   | 02:06:24
 clang-with-thin-lto-windows  | 02:00:44
 clang-cmake-x86_64-avx2-linux-perf   | 01:39:52
 libcxx-libcxxabi-libunwind-armv8-linux   | 01:36:00
 clang-cmake-aarch64-quick| 01:23:20
 clang-x86_64-debian-fast | 01:17:55
 lldb-x86_64-ubuntu-14.04-buildserver | 01:15:42
 sanitizer-x86_64-linux-autoconf  | 01:13:34
 lld-perf-testsuite   | 01:03:27
 lldb-windows7-android| 01:03:17
 lldb-x86_64-darwin-13.4  | 00:54:33
 polly-arm-linux  | 00:49:27
 lldb-x86-windows-msvc2015| 00:37:23
 lldb-x86_64-ubuntu-14.04-cmake   | 00:37:07
 clang-cmake-armv8-lnt| 00:35:40
 lld-x86_64-freebsd   

Buildbot numbers for the week of 7/29/2018 - 8/04/2018

2018-08-16 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 7/29/2018 - 8/04/2018.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
  buildername  |  was_red
---+--
 clang-x64-ninja-win7  | 130:45:42
 openmp-gcc-x86_64-linux-debian| 62:46:33
 libcxx-libcxxabi-libunwind-x86_64-linux-debian| 49:53:23
 clang-cmake-aarch64-lld   | 41:54:27
 clang-ppc64le-linux-lnt   | 37:37:32
 clang-cmake-x86_64-avx2-linux | 37:34:26
 clang-cmake-x86_64-avx2-linux-perf| 37:33:08
 clang-ppc64be-linux-lnt   | 37:08:39
 clang-cmake-x86_64-sde-avx512-linux   | 36:58:53
 llvm-clang-x86_64-expensive-checks-win| 32:24:18
 lldb-amd64-ninja-netbsd8  | 26:56:20
 sanitizer-x86_64-linux-bootstrap-ubsan| 25:59:23
 libcxx-libcxxabi-x86_64-linux-debian  | 25:54:40
 sanitizer-x86_64-linux-fast   | 25:44:51
 aosp-O3-polly-before-vectorizer-unprofitable  | 24:20:09
 clang-x86-windows-msvc2015| 20:53:57
 clang-cmake-thumbv8-full-sh   | 19:20:05
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast  | 18:48:01
 clang-with-thin-lto-windows   | 17:46:01
 lldb-x86_64-ubuntu-14.04-cmake| 16:06:23
 clang-cmake-thumbv7-full-sh   | 15:28:01
 lldb-windows7-android | 15:18:52
 clang-cmake-armv7-selfhost| 15:05:11
 clang-cmake-armv7-selfhost-neon   | 14:47:38
 lldb-x86_64-darwin-13.4   | 14:27:05
 libcxx-libcxxabi-x86_64-linux-debian-noexceptions | 13:34:13
 clang-lld-x86_64-2stage   | 13:28:10
 clang-cmake-armv8-selfhost-neon   | 13:05:48
 sanitizer-x86_64-linux-bootstrap  | 10:22:07
 clang-hexagon-elf | 09:33:24
 sanitizer-ppc64le-linux   | 09:08:34
 clang-x86_64-linux-selfhost-modules   | 08:57:56
 clang-with-lto-ubuntu | 08:47:46
 clang-x86_64-debian-fast  | 08:41:31
 sanitizer-x86_64-linux-bootstrap-msan | 08:31:36
 polly-arm-linux   | 08:31:25
 clang-ppc64le-linux-multistage| 08:07:22
 clang-with-thin-lto-ubuntu| 07:46:33
 clang-cmake-aarch64-full  | 07:45:12
 sanitizer-x86_64-linux| 07:30:13
 libcxx-libcxxabi-x86_64-linux-ubuntu-asan | 07:17:23
 lld-perf-testsuite| 07:09:20
 sanitizer-ppc64be-linux   | 06:52:45
 clang-s390x-linux-multistage  | 06:43:15
 clang-cmake-armv7-global-isel | 06:42:11
 clang-cuda-build  | 06:40:51
 clang-ppc64be-linux-multistage| 06:36:33
 clang-cmake-armv8-global-isel | 06:35:43
 clang-cmake-armv8-quick   | 06:27:00
 reverse-iteration | 06:26:48
 clang-cmake-armv7-quick   | 06:26:38
 clang-cmake-armv8-full| 06:16:06
 clang-cmake-armv7-full| 06:15:23
 sanitizer-x86_64-linux-fuzzer | 06:07:19
 clang-x86_64-linux-abi-test   | 04:19:31
 clang-ppc64be-linux   | 03:44:49
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast| 03:42:53
 clang-s390x-linux | 03:41:54
 polly-amd64-linux | 03:33:37
 libcxx-libcxxabi-x86_64-linux-ubuntu-gcc49-cxx11  | 03:19:24
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03| 03:18:34
 clang-ppc64le-linux   | 03:12:27
 libcxx-libcxxabi-libunwind-aarch64-linux-noexceptions | 03:05:05
 clang-cmake-aarch64-quick | 03:01:55
 

[PATCH] D50877: [MS] Mangle a hash of the main file path into anonymous namespaces

2018-08-16 Thread Bob Haarman via Phabricator via cfe-commits
inglorion added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:389
+  if (FE) {
+llvm::MD5 Hasher;
+llvm::MD5::MD5Result Hash;

Instead of MD5, can we use xxhash (or whatever the fastest hash algorithm in 
LLVM is these days)? I don't think we need a particular hash algorithm, so we 
might as well go with the fastest one we have (as long as it does a good job 
avoiding collisions, of course).


https://reviews.llvm.org/D50877



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-16 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

This was my first time using AST matchers so it took me a while to figure out 
how exactly to get this right. clang-query helped a lot. Backspace seems to be 
a problem with clang-query though.


https://reviews.llvm.org/D50488



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-16 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 161152.
mgrang added a comment.

Changed patch to use AST Matchers.


https://reviews.llvm.org/D50488

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
  test/Analysis/ptr-sort.cpp

Index: test/Analysis/ptr-sort.cpp
===
--- /dev/null
+++ test/Analysis/ptr-sort.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.nondeterminism.PointerSorting %s -analyzer-output=text -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+namespace std {
+  template
+  void sort (RandomIt first, RandomIt last);
+
+  template
+  void sort (RandomIt first, RandomIt last, Compare comp);
+}
+using namespace std;
+
+void PointerSorting() {
+  int a = 1, b = 2;
+
+  std::vector V1 = {a, b};
+  std::sort(V1.begin(), V1.end()); // no-warning
+
+  std::vector V2 = {, };
+
+  std::sort(V2.begin(), V2.end(), true); // no-warning
+
+  std::sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+
+  sort(V2.begin(), V2.end()); // expected-warning {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+  // expected-note@-1 {{Sorting pointer-like keys can result in non-deterministic ordering}} [alpha.nondeterminism.PointerSorting]
+}
Index: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
===
--- /dev/null
+++ lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
@@ -0,0 +1,93 @@
+//===-- PointerSortingChecker.cpp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file defines PointerSortingChecker which checks for non-determinism
+// caused due to sorting container with pointer-like elements.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
+
+using namespace clang;
+using namespace ento;
+using namespace ast_matchers;
+
+namespace {
+
+// ID of a node at which the diagnostic would be emitted.
+const char *WarnAtNode = "sort";
+
+class PointerSortingChecker : public Checker {
+public:
+  void checkASTCodeBody(const Decl *D,
+AnalysisManager ,
+BugReporter ) const;
+};
+
+static void emitDiagnostics(const BoundNodes , const Decl *D,
+BugReporter , AnalysisManager ,
+const PointerSortingChecker *Checker) {
+  auto *ADC = AM.getAnalysisDeclContext(D);
+
+  const auto *MarkedStmt = Match.getNodeAs(WarnAtNode);
+  assert(MarkedStmt);
+
+  auto Range = MarkedStmt->getSourceRange();
+  auto Location = PathDiagnosticLocation::createBegin(MarkedStmt,
+  BR.getSourceManager(),
+  ADC);
+  std::string Diagnostics;
+  llvm::raw_string_ostream OS(Diagnostics);
+  OS << "Sorting pointer-like keys can result in non-deterministic ordering";
+
+  BR.EmitBasicReport(ADC->getDecl(), Checker,
+ "Sorting of pointer-like keys", "Non-determinism",
+ OS.str(), Location, Range);
+}
+
+auto callsName(const char *FunctionName) -> decltype(callee(functionDecl())) {
+  return callee(functionDecl(hasName(FunctionName)));
+}
+
+auto matchSortWithPointers() -> decltype(decl()) {
+  auto PointsToPointerM = hasType(cxxRecordDecl(has(
+fieldDecl(hasType(
+  pointsTo(pointerType())
+))
+  )));
+
+  auto SortFuncM = stmt(callExpr(allOf(
+ callsName("std::sort"),
+ argumentCountIs(2),
+ hasArgument(0, PointsToPointerM)))
+   ).bind(WarnAtNode);
+
+  return decl(forEachDescendant(SortFuncM));
+}
+
+void PointerSortingChecker::checkASTCodeBody(const Decl *D,
+ AnalysisManager ,
+ BugReporter ) const {
+  auto MatcherM = matchSortWithPointers();
+
+  auto 

[PATCH] D50862: [clang-tidy] Abseil: faster strsplit delimiter check

2018-08-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst:6
+
+This check triggers on calls to ``absl::StrSplit()`` or ``absl::MaxSplits()``
+where the delimiter is a single character string literal. The check will offer

Please make first statement same as in Release Notes. Please also avoid //this 
check//.



Comment at: docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst:21
+  for (auto piece : absl::StrSplit(str, "B")) {
+  // Suggested - the argument is a character, which causes the more efficient
+  // overload of absl::StrSplit() to be used.

Please separate before and after with empty line. Same in other places.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50862



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


[PATCH] D50119: Compiler support for P1144R0 "__is_trivially_relocatable(T)"

2018-08-16 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete added a comment.

It would be nice to be able to diagnose `X`:

  template 
  struct Foo {
struct [[trivially_relocatable]] X { // no warning
  X(X &&) = delete;
};
  };
  
  Foo f; // no warning
  static_assert(!__is_trivially_relocatable(Foo::X)); // ok

But otherwise, you might want to put the attribute in the `clang` namespace. 
LGTM then, but you'll want to wait for someone more senior than me to review 
(and possibly accept) it.


Repository:
  rC Clang

https://reviews.llvm.org/D50119



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


[PATCH] D50877: [MS] Mangle a hash of the main file path into anonymous namespaces

2018-08-16 Thread Zachary Turner via Phabricator via cfe-commits
zturner added subscribers: rnk, zturner.
zturner added a comment.

IIRC it’s `?A0xABCDABCD@` where the hex value is some kind of hash


https://reviews.llvm.org/D50877



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


Re: [PATCH] D50877: [MS] Mangle a hash of the main file path into anonymous namespaces

2018-08-16 Thread Zachary Turner via cfe-commits
IIRC it’s `?A0xABCDABCD@` where the hex value is some kind of hash
On Thu, Aug 16, 2018 at 5:27 PM David Majnemer via Phabricator <
revi...@reviews.llvm.org> wrote:

> majnemer added a comment.
>
> How does MSVC handle this case? What mangled name does it generate?
>
>
> https://reviews.llvm.org/D50877
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50877: [MS] Mangle a hash of the main file path into anonymous namespaces

2018-08-16 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

How does MSVC handle this case? What mangled name does it generate?


https://reviews.llvm.org/D50877



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


[PATCH] D50815: Establish the header

2018-08-16 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

It appears that libcxx/include/CMakeLists.txt needs to be updated to include 
`bit` file into the file set.


https://reviews.llvm.org/D50815



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


[PATCH] D50805: Don't warn on returning the address of a label from a statement expression

2018-08-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 161148.
rnk added a comment.

- return to avoid bad notes


https://reviews.llvm.org/D50805

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/statements.c


Index: clang/test/Sema/statements.c
===
--- clang/test/Sema/statements.c
+++ clang/test/Sema/statements.c
@@ -34,6 +34,15 @@
   return &  // expected-warning {{returning address of label, which is 
local}}
 }
 
+// PR38569: Don't warn when returning a label from a statement expression.
+void test10_logpc(void*);
+void test10a() {
+  test10_logpc(({
+my_pc:
+  &_pc;
+  }));
+}
+
 // PR6034
 void test11(int bit) {
   switch (bit)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6924,6 +6924,10 @@
   } else if (isa(L)) {
 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
   } else if (isa(L)) {
+// Don't warn when returning a label from a statement expression.
+// Leaving the scope doesn't end its lifetime.
+if (LK == LK_StmtExprResult)
+  return false;
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)


Index: clang/test/Sema/statements.c
===
--- clang/test/Sema/statements.c
+++ clang/test/Sema/statements.c
@@ -34,6 +34,15 @@
   return &  // expected-warning {{returning address of label, which is local}}
 }
 
+// PR38569: Don't warn when returning a label from a statement expression.
+void test10_logpc(void*);
+void test10a() {
+  test10_logpc(({
+my_pc:
+  &_pc;
+  }));
+}
+
 // PR6034
 void test11(int bit) {
   switch (bit)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6924,6 +6924,10 @@
   } else if (isa(L)) {
 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
   } else if (isa(L)) {
+// Don't warn when returning a label from a statement expression.
+// Leaving the scope doesn't end its lifetime.
+if (LK == LK_StmtExprResult)
+  return false;
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50877: [MS] Mangle a hash of the main file path into anonymous namespaces

2018-08-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk created this revision.
rnk added reviewers: majnemer, inglorion, hans.
Herald added subscribers: dexonsmith, JDevlieghere, aprantl, mehdi_amini.

This is needed to avoid conflicts in mangled names for codeview types in
anonymous namespaces. In CodeView, types refer to each other typically
through forward declarations, which contain mangled names. These names
have to be unique, otherwise the debugger will look up the mangled name
and find the wrong definition.

Furthermore, ThinLTO will deduplicate the types, and debug info
verification can fail when the types have the wrong sizes. This is
PR38608.

Fixes PR38609.


https://reviews.llvm.org/D50877

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/cfi-icall.cpp
  clang/test/CodeGenCXX/debug-info-thunk.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/mangle-ms.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp
  clang/test/CodeGenCXX/microsoft-abi-throw.cpp
  clang/test/CodeGenCXX/microsoft-abi-thunks.cpp
  clang/test/CodeGenCXX/microsoft-abi-vftables.cpp
  clang/test/CodeGenCXX/microsoft-abi-virtual-member-pointers.cpp
  clang/test/CodeGenCXX/msabi-swiftcall-cc.cpp
  clang/test/CodeGenCXX/pragma-init_seg.cpp
  clang/test/CodeGenCXX/type-metadata.cpp

Index: clang/test/CodeGenCXX/type-metadata.cpp
===
--- clang/test/CodeGenCXX/type-metadata.cpp
+++ clang/test/CodeGenCXX/type-metadata.cpp
@@ -82,8 +82,8 @@
 // MS: comdat($"??_7B@@6B0@@"), !type [[B8:![0-9]+]]
 // MS: comdat($"??_7B@@6BA@@@"), !type [[A8]]
 // MS: comdat($"??_7C@@6B@"), !type [[A8]]
-// MS: comdat($"??_7D@?A@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]]
-// MS: comdat($"??_7D@?A@@6BA@@@"), !type [[A8]]
+// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BB@@@"), !type [[B8]], !type [[D8:![0-9]+]]
+// MS: comdat($"??_7D@?A0x{{[^@]*}}@@6BA@@@"), !type [[A8]]
 // MS: comdat($"??_7FA@?1??foo@@YAXXZ@6B@"), !type [[A8]], !type [[FA8:![0-9]+]]
 
 struct A {
@@ -161,7 +161,7 @@
 }
 
 // ITANIUM: define internal void @_Z3df1PN12_GLOBAL__N_11DE
-// MS: define internal void @"?df1@@YAXPEAUD@?A@@@Z"
+// MS: define internal void @"?df1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
 void df1(D *d) {
   // TT-ITANIUM: {{%[^ ]*}} = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata ![[DTYPE:[0-9]+]])
   // TT-MS: {{%[^ ]*}} = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"?AUA@@")
@@ -171,7 +171,7 @@
 }
 
 // ITANIUM: define internal void @_Z3dg1PN12_GLOBAL__N_11DE
-// MS: define internal void @"?dg1@@YAXPEAUD@?A@@@Z"
+// MS: define internal void @"?dg1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
 void dg1(D *d) {
   // TT-ITANIUM: {{%[^ ]*}} = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTS1B")
   // TT-MS: {{%[^ ]*}} = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"?AUB@@")
@@ -181,7 +181,7 @@
 }
 
 // ITANIUM: define internal void @_Z3dh1PN12_GLOBAL__N_11DE
-// MS: define internal void @"?dh1@@YAXPEAUD@?A@@@Z"
+// MS: define internal void @"?dh1@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
 void dh1(D *d) {
   // TT-ITANIUM: {{%[^ ]*}} = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata ![[DTYPE]])
   // TT-MS: {{%[^ ]*}} = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata ![[DTYPE:[0-9]+]])
@@ -191,7 +191,7 @@
 }
 
 // ITANIUM: define internal void @_Z3df2PN12_GLOBAL__N_11DE
-// MS: define internal void @"?df2@@YAXPEAUD@?A@@@Z"
+// MS: define internal void @"?df2@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
 __attribute__((no_sanitize("cfi")))
 void df2(D *d) {
   // CFI-NVT-NOT: call i1 @llvm.type.test
@@ -201,7 +201,7 @@
 }
 
 // ITANIUM: define internal void @_Z3df3PN12_GLOBAL__N_11DE
-// MS: define internal void @"?df3@@YAXPEAUD@?A@@@Z"
+// MS: define internal void @"?df3@@YAXPEAUD@?A0x{{[^@]*}}@@@Z"
 __attribute__((no_sanitize("address"))) __attribute__((no_sanitize("cfi-vcall")))
 void df3(D *d) {
   // CFI-NVT-NOT: call i1 @llvm.type.test
Index: clang/test/CodeGenCXX/pragma-init_seg.cpp
===
--- clang/test/CodeGenCXX/pragma-init_seg.cpp
+++ clang/test/CodeGenCXX/pragma-init_seg.cpp
@@ -28,8 +28,8 @@
 namespace internal_init {
 namespace {
 int x = f();
-// CHECK: @"?x@?A@internal_init@@3HA" = internal global i32 0, align 4
-// CHECK: @__cxx_init_fn_ptr.2 = private constant void ()* @"??__Ex@?A@internal_init@@YAXXZ", section ".asdf"
+// CHECK: @"?x@?A0x{{[^@]*}}@internal_init@@3HA" = internal global i32 0, align 4
+// CHECK: @__cxx_init_fn_ptr.2 = private constant void ()* @"??__Ex@?A0x{{[^@]*}}@internal_init@@YAXXZ", section ".asdf"
 }
 }
 
Index: clang/test/CodeGenCXX/msabi-swiftcall-cc.cpp
===
--- clang/test/CodeGenCXX/msabi-swiftcall-cc.cpp
+++ clang/test/CodeGenCXX/msabi-swiftcall-cc.cpp
@@ -12,8 +12,8 @@
 namespace {
 void __attribute__((__swiftcall__)) __attribute__((__used__)) f() { }
 }
-// CHECK-DAG: @"?f@?A@@YSXXZ"
-// CHECK-64-DAG: @"?f@?A@@YSXXZ"
+// CHECK-DAG: 

[PATCH] D50815: Establish the header

2018-08-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka reopened this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

Reverted r339971 as it breaks sanitizer bots


https://reviews.llvm.org/D50815



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


[libcxx] r339971 - Revert "Establish the header. NFC yet. Reviewed as https://reviews.llvm.org/D50815"

2018-08-16 Thread Vitaly Buka via cfe-commits
Author: vitalybuka
Date: Thu Aug 16 16:57:16 2018
New Revision: 339971

URL: http://llvm.org/viewvc/llvm-project?rev=339971=rev
Log:
Revert "Establish the  header. NFC yet. Reviewed as 
https://reviews.llvm.org/D50815;

Breaks build on sanitizer bots.

This reverts commit r339943.

Removed:
libcxx/trunk/include/bit
Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/include/module.modulemap
libcxx/trunk/test/libcxx/double_include.sh.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=339971=339970=339971=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Thu Aug 16 16:57:16 2018
@@ -645,7 +645,13 @@ template 
 #include 
 #include 
-#include 
+
+#if defined(__IBMCPP__)
+#include "support/ibm/support.h"
+#endif
+#if defined(_LIBCPP_COMPILER_MSVC)
+#include 
+#endif
 
 #include <__debug>
 
@@ -782,6 +788,135 @@ struct __debug_less
 
 #endif  // _LIBCPP_DEBUG
 
+// Precondition:  __x != 0
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned __ctz(unsigned __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+return static_cast(__builtin_ctz(__x));
+#else
+  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
+  static_assert(sizeof(unsigned long) == 4, "");
+  unsigned long where;
+  // Search from LSB to MSB for first set bit.
+  // Returns zero if no set bit is found.
+  if (_BitScanForward(, __x))
+return where;
+  return 32;
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long __ctz(unsigned long __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+return static_cast(__builtin_ctzl(__x));
+#else
+static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
+return __ctz(static_cast(__x));
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long __ctz(unsigned long long __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+return static_cast(__builtin_ctzll(__x));
+#else
+unsigned long where;
+// Search from LSB to MSB for first set bit.
+// Returns zero if no set bit is found.
+#if defined(_LIBCPP_HAS_BITSCAN64)
+(defined(_M_AMD64) || defined(__x86_64__))
+  if (_BitScanForward64(, __x))
+return static_cast(where);
+#else
+  // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
+  // Scan the Low Word.
+  if (_BitScanForward(, static_cast(__x)))
+return where;
+  // Scan the High Word.
+  if (_BitScanForward(, static_cast(__x >> 32)))
+return where + 32; // Create a bit offset from the LSB.
+#endif
+  return 64;
+#endif // _LIBCPP_COMPILER_MSVC
+}
+
+// Precondition:  __x != 0
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned __clz(unsigned __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+return static_cast(__builtin_clz(__x));
+#else
+  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
+  static_assert(sizeof(unsigned long) == 4, "");
+  unsigned long where;
+  // Search from LSB to MSB for first set bit.
+  // Returns zero if no set bit is found.
+  if (_BitScanReverse(, __x))
+return 31 - where;
+  return 32; // Undefined Behavior.
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long __clz(unsigned long __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+return static_cast(__builtin_clzl (__x));
+#else
+static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
+return __clz(static_cast(__x));
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+unsigned long long __clz(unsigned long long __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+return static_cast(__builtin_clzll(__x));
+#else
+  unsigned long where;
+// BitScanReverse scans from MSB to LSB for first set bit.
+// Returns 0 if no set bit is found.
+#if defined(_LIBCPP_HAS_BITSCAN64)
+  if (_BitScanReverse64(, __x))
+return static_cast(63 - where);
+#else
+  // Scan the high 32 bits.
+  if (_BitScanReverse(, static_cast(__x >> 32)))
+return 63 - (where + 32); // Create a bit offset from the MSB.
+  // Scan the low 32 bits.
+  if (_BitScanReverse(, static_cast(__x)))
+return 63 - where;
+#endif
+  return 64; // Undefined Behavior.
+#endif // _LIBCPP_COMPILER_MSVC
+}
+
+inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+  return __builtin_popcount  (__x);
+#else
+  static_assert(sizeof(unsigned) == 4, "");
+  return __popcnt(__x);
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+  return __builtin_popcountl (__x);
+#else
+  static_assert(sizeof(unsigned long) == 4, "");
+  return __popcnt(__x);
+#endif
+}
+
+inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {
+#ifndef _LIBCPP_COMPILER_MSVC
+  return __builtin_popcountll(__x);
+#else
+  static_assert(sizeof(unsigned long long) == 8, "");
+  return __popcnt64(__x);
+#endif
+}
+
 // all_of
 
 template 

Removed: libcxx/trunk/include/bit
URL: 

[libcxx] r339969 - [libc++] Use correct rand.eng.mers all-zeroes seed sequence fallback

2018-08-16 Thread Hubert Tong via cfe-commits
Author: hubert.reinterpretcast
Date: Thu Aug 16 16:56:54 2018
New Revision: 339969

URL: http://llvm.org/viewvc/llvm-project?rev=339969=rev
Log:
[libc++] Use correct rand.eng.mers all-zeroes seed sequence fallback

Summary:
When a seed sequence would lead to having no non-zero significant bits
in the initial state of a `mersenne_twister_engine`, the fallback is to
flip the most significant bit of the first value that appears in the
textual representation of the initial state.

rand.eng.mers describes this as setting the value to be 2 to the power
of one less than w; the previous value encoded in the implementation,
namely one less than "2 to the power of w", is replaced by the correct
value in this patch.

Reviewers: mclow.lists, EricWF, jasonliu

Reviewed By: mclow.lists

Subscribers: mclow.lists, jasonliu, EricWF, christof, ldionne, cfe-commits

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

Added:

libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
Modified:
libcxx/trunk/include/random

Modified: libcxx/trunk/include/random
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=339969=339968=339969=diff
==
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Thu Aug 16 16:56:54 2018
@@ -2337,7 +2337,7 @@ mersenne_twister_engine<_UIntType, __w,
 for (size_t __i = 1; __i < __n; ++__i)
 if (__x_[__i] != 0)
 return;
-__x_[0] = _Max;
+__x_[0] = result_type(1) << (__w - 1);
 }
 }
 
@@ -2363,7 +2363,7 @@ mersenne_twister_engine<_UIntType, __w,
 for (size_t __i = 1; __i < __n; ++__i)
 if (__x_[__i] != 0)
 return;
-__x_[0] = _Max;
+__x_[0] = result_type(1) << (__w - 1);
 }
 }
 

Added: 
libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp?rev=339969=auto
==
--- 
libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
 (added)
+++ 
libcxx/trunk/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
 Thu Aug 16 16:56:54 2018
@@ -0,0 +1,81 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template 
+// class mersenne_twister_engine;
+
+// template  explicit mersenne_twister_engine(Sseq );
+//
+// [ ... ] Finally, if the most significant $w-r$ bits of $X_{-n}$ are 
zero,
+// and if each of the other resulting $X_i$ is $0$, changes $X_{-n}$ to
+// $ 2^{w-1} $.
+
+#include 
+
+#include 
+#include 
+#include 
+#if TEST_STD_VER >= 11
+#include 
+#endif
+
+struct all_zero_seed_seq {
+  typedef unsigned int result_type;
+
+  all_zero_seed_seq() {}
+
+  template 
+  all_zero_seed_seq(InputIterator, InputIterator) {}
+#if TEST_STD_VER >= 11
+  all_zero_seed_seq(std::initializer_list) {}
+#endif
+
+  template 
+  void generate(RandomAccessIterator rb, RandomAccessIterator re) {
+std::fill(rb, re, 0u);
+  }
+
+  std::size_t size() const { return 0u; }
+  template  void param(OutputIterator) const {}
+};
+
+template 
+void test(void) {
+  const std::size_t state_size = 1u;
+  const std::size_t shift_size = 1u;
+  const std::size_t tempering_l = word_size;
+
+  all_zero_seed_seq q;
+  std::mersenne_twister_engine
+  e(q);
+
+  const result_type Xneg1 = result_type(1) << (word_size - 1);
+  const result_type Y = Xneg1;
+  const result_type X0 = Xneg1 ^ (Y >> 1);
+  assert(e() == X0);
+}
+
+int main() {
+  // Test for k == 1: word_size <= 32.
+  test();
+
+  // Test for k == 2: (32 < word_size <= 64).
+  test();
+}


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


[PATCH] D50736: [libc++] Use correct rand.eng.mers all-zeroes seed sequence fallback

2018-08-16 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX339969: [libc++] Use correct rand.eng.mers all-zeroes seed 
sequence fallback (authored by hubert.reinterpretcast, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50736?vs=160923=161145#toc

Repository:
  rCXX libc++

https://reviews.llvm.org/D50736

Files:
  include/random
  test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp

Index: include/random
===
--- include/random
+++ include/random
@@ -2337,7 +2337,7 @@
 for (size_t __i = 1; __i < __n; ++__i)
 if (__x_[__i] != 0)
 return;
-__x_[0] = _Max;
+__x_[0] = result_type(1) << (__w - 1);
 }
 }
 
@@ -2363,7 +2363,7 @@
 for (size_t __i = 1; __i < __n; ++__i)
 if (__x_[__i] != 0)
 return;
-__x_[0] = _Max;
+__x_[0] = result_type(1) << (__w - 1);
 }
 }
 
Index: test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
===
--- test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
+++ test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp
@@ -0,0 +1,81 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template 
+// class mersenne_twister_engine;
+
+// template  explicit mersenne_twister_engine(Sseq );
+//
+// [ ... ] Finally, if the most significant $w-r$ bits of $X_{-n}$ are zero,
+// and if each of the other resulting $X_i$ is $0$, changes $X_{-n}$ to
+// $ 2^{w-1} $.
+
+#include 
+
+#include 
+#include 
+#include 
+#if TEST_STD_VER >= 11
+#include 
+#endif
+
+struct all_zero_seed_seq {
+  typedef unsigned int result_type;
+
+  all_zero_seed_seq() {}
+
+  template 
+  all_zero_seed_seq(InputIterator, InputIterator) {}
+#if TEST_STD_VER >= 11
+  all_zero_seed_seq(std::initializer_list) {}
+#endif
+
+  template 
+  void generate(RandomAccessIterator rb, RandomAccessIterator re) {
+std::fill(rb, re, 0u);
+  }
+
+  std::size_t size() const { return 0u; }
+  template  void param(OutputIterator) const {}
+};
+
+template 
+void test(void) {
+  const std::size_t state_size = 1u;
+  const std::size_t shift_size = 1u;
+  const std::size_t tempering_l = word_size;
+
+  all_zero_seed_seq q;
+  std::mersenne_twister_engine
+  e(q);
+
+  const result_type Xneg1 = result_type(1) << (word_size - 1);
+  const result_type Y = Xneg1;
+  const result_type X0 = Xneg1 ^ (Y >> 1);
+  assert(e() == X0);
+}
+
+int main() {
+  // Test for k == 1: word_size <= 32.
+  test();
+
+  // Test for k == 2: (32 < word_size <= 64).
+  test();
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339968 - Disable pubnames in NVPTX debug info using metadata

2018-08-16 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Thu Aug 16 16:56:32 2018
New Revision: 339968

URL: http://llvm.org/viewvc/llvm-project?rev=339968=rev
Log:
Disable pubnames in NVPTX debug info using metadata

Added:
cfe/trunk/test/CodeGen/debug-nvptx.c
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=339968=339967=339968=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Aug 16 16:56:32 2018
@@ -579,8 +579,11 @@ void CGDebugInfo::CreateCompileUnit() {
   CGOpts.DwarfDebugFlags, RuntimeVers,
   CGOpts.EnableSplitDwarf ? "" : CGOpts.SplitDwarfFile, EmissionKind,
   0 /* DWOid */, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
-  CGOpts.GnuPubnames ? llvm::DICompileUnit::DebugNameTableKind::GNU
- : llvm::DICompileUnit::DebugNameTableKind::Default);
+  CGM.getTarget().getTriple().isNVPTX()
+  ? llvm::DICompileUnit::DebugNameTableKind::None
+  : CGOpts.GnuPubnames
+? llvm::DICompileUnit::DebugNameTableKind::GNU
+: llvm::DICompileUnit::DebugNameTableKind::Default);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {

Added: cfe/trunk/test/CodeGen/debug-nvptx.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-nvptx.c?rev=339968=auto
==
--- cfe/trunk/test/CodeGen/debug-nvptx.c (added)
+++ cfe/trunk/test/CodeGen/debug-nvptx.c Thu Aug 16 16:56:32 2018
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -S -o - 
-debug-info-kind=limited %s -emit-llvm | FileCheck %s
+
+// CHECK: DICompileUnit({{.*}}, nameTableKind: None)
+
+void f1(void) {
+}


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


[clang-tools-extra] r339966 - Revert "Implement a (simple) Markdown generator"

2018-08-16 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Thu Aug 16 16:50:51 2018
New Revision: 339966

URL: http://llvm.org/viewvc/llvm-project?rev=339966=rev
Log:
Revert "Implement a (simple) Markdown generator"

This reverts commit r339948, as it's breaking a few bots in ways that I
can't reproduce right now.

Removed:
clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp
clang-tools-extra/trunk/test/clang-doc/md-module.cpp
clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/md-record.cpp
Modified:
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/Generators.cpp
clang-tools-extra/trunk/clang-doc/Generators.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
clang-tools-extra/trunk/clang-doc/gen_tests.py
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp

Modified: clang-tools-extra/trunk/clang-doc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/CMakeLists.txt?rev=339966=339965=339966=diff
==
--- clang-tools-extra/trunk/clang-doc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-doc/CMakeLists.txt Thu Aug 16 16:50:51 2018
@@ -10,7 +10,6 @@ add_clang_library(clangDoc
   ClangDoc.cpp
   Generators.cpp
   Mapper.cpp
-  MDGenerator.cpp
   Representation.cpp
   Serialize.cpp
   YAMLGenerator.cpp

Modified: clang-tools-extra/trunk/clang-doc/Generators.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.cpp?rev=339966=339965=339966=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.cpp Thu Aug 16 16:50:51 2018
@@ -29,11 +29,8 @@ findGeneratorByName(llvm::StringRef Form
 // This anchor is used to force the linker to link in the generated object file
 // and thus register the generators.
 extern volatile int YAMLGeneratorAnchorSource;
-extern volatile int MDGeneratorAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED YAMLGeneratorAnchorDest =
 YAMLGeneratorAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED MDGeneratorAnchorDest =
-MDGeneratorAnchorSource;
 
 } // namespace doc
 } // namespace clang

Modified: clang-tools-extra/trunk/clang-doc/Generators.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.h?rev=339966=339965=339966=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.h (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.h Thu Aug 16 16:50:51 2018
@@ -27,7 +27,7 @@ public:
   virtual ~Generator() = default;
 
   // Write out the decl info in the specified format.
-  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
+  virtual bool generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
 };
 
 typedef llvm::Registry GeneratorRegistry;

Removed: clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/MDGenerator.cpp?rev=339965=auto
==
--- clang-tools-extra/trunk/clang-doc/MDGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/MDGenerator.cpp (removed)
@@ -1,314 +0,0 @@
-//===-- MDGenerator.cpp - Markdown Generator *- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "Generators.h"
-#include "Representation.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
-#include 
-
-using namespace llvm;
-
-namespace clang {
-namespace doc {
-
-// Enum conversion
-
-std::string getAccess(AccessSpecifier AS) {
-  switch (AS) {
-  case AccessSpecifier::AS_public:
-return "public";
-  case AccessSpecifier::AS_protected:
-return "protected";
-  case AccessSpecifier::AS_private:
-return "private";
-  case AccessSpecifier::AS_none:
-return {};
-  }
-}
-
-std::string getTagType(TagTypeKind AS) {
-  switch (AS) {
-  case TagTypeKind::TTK_Class:
-return "class";
-  case TagTypeKind::TTK_Union:
-return "union";
-  case TagTypeKind::TTK_Interface:
-return "interface";
-  case TagTypeKind::TTK_Struct:
-return "struct";
-  case TagTypeKind::TTK_Enum:
-return "enum";
-  }
-}
-
-// Markdown generation
-
-std::string genItalic(const Twine ) { return "*" + Text.str() + "*"; }
-
-std::string genEmphasis(const Twine ) { 

[PATCH] D50876: Clean up newly created header

2018-08-16 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: include/bit:113
 inline _LIBCPP_INLINE_VISIBILITY
 unsigned __clz(unsigned __x) {
   static_assert(sizeof(unsigned) == sizeof(unsigned long), "");

Missed this one. Should be `int`


https://reviews.llvm.org/D50876



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


[PATCH] D50876: Clean up newly created header

2018-08-16 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.
mclow.lists added reviewers: ldionne, EricWF.

Still NFC here.

1. Take the 9 functions that each had an `#ifndef _LIBCPP_COMPILER_MSVC` .. 
`#else` .. `endif` block in them and make just two blocks, each with 9 
functions. Much easier to read, but makes for a terrible diff.

2. Change the return type of `__ctz` and `__clz` from the same type as the 
parameter to `int`.  I would have preferred `unsigned`, but that's not what 
P0553 gave us. I reviewed all the call sites for these functions, and for 
`__ctz` it was always immediately static_cast-ed to another type, and `__clz` 
it made no difference either.

3. Change the name `__pop_count` to `__popcount` to match the name that we're 
going to add from P0553.

4. Rename the local variable in the windows code from `where` to `__where`. 
Shame on someone ;-)


https://reviews.llvm.org/D50876

Files:
  include/__bit_reference
  include/bit

Index: include/bit
===
--- include/bit
+++ include/bit
@@ -35,135 +35,134 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#ifndef _LIBCPP_COMPILER_MSVC
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __ctz(unsigned __x)   { return __builtin_ctz(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __ctz(unsigned long __x)  { return __builtin_ctzl(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __ctz(unsigned long long __x) { return __builtin_ctzll(__x); }
+
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __clz(unsigned __x)   { return __builtin_clz(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __clz(unsigned long __x)  { return __builtin_clzl(__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __clz(unsigned long long __x) { return __builtin_clzll(__x); }
+
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __popcount(unsigned __x)   { return __builtin_popcount  (__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __popcount(unsigned long __x)  { return __builtin_popcountl (__x); }
+
+inline _LIBCPP_INLINE_VISIBILITY
+int __popcount(unsigned long long __x) { return __builtin_popcountll(__x); }
+
+#else  // _LIBCPP_COMPILER_MSVC
+
 // Precondition:  __x != 0
 inline _LIBCPP_INLINE_VISIBILITY
-unsigned __ctz(unsigned __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_ctz(__x));
-#else
+int __ctz(unsigned __x) {
   static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
   static_assert(sizeof(unsigned long) == 4, "");
-  unsigned long where;
+  unsigned long __where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanForward(, __x))
-return where;
+  if (_BitScanForward(&__where, __x))
+return static_cast(__where);
   return 32;
-#endif
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-unsigned long __ctz(unsigned long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_ctzl(__x));
-#else
+int __ctz(unsigned long __x) {
 static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
 return __ctz(static_cast(__x));
-#endif
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-unsigned long long __ctz(unsigned long long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_ctzll(__x));
-#else
-unsigned long where;
+int __ctz(unsigned long long __x) {
+unsigned long __where;
 // Search from LSB to MSB for first set bit.
 // Returns zero if no set bit is found.
 #if defined(_LIBCPP_HAS_BITSCAN64)
 (defined(_M_AMD64) || defined(__x86_64__))
-  if (_BitScanForward64(, __x))
-return static_cast(where);
+  if (_BitScanForward64(&__where, __x))
+return static_cast(__where);
 #else
   // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
   // Scan the Low Word.
-  if (_BitScanForward(, static_cast(__x)))
-return where;
+  if (_BitScanForward(&__where, static_cast(__x)))
+return __where;
   // Scan the High Word.
-  if (_BitScanForward(, static_cast(__x >> 32)))
-return where + 32; // Create a bit offset from the LSB.
+  if (_BitScanForward(&__where, static_cast(__x >> 32)))
+return __where + 32; // Create a bit offset from the LSB.
 #endif
   return 64;
-#endif // _LIBCPP_COMPILER_MSVC
 }
 
 // Precondition:  __x != 0
 inline _LIBCPP_INLINE_VISIBILITY
 unsigned __clz(unsigned __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_clz(__x));
-#else
   static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
   static_assert(sizeof(unsigned long) == 4, "");
-  unsigned long where;
+  unsigned long __where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.
-  if (_BitScanReverse(, __x))
-return 31 - where;
+  if (_BitScanReverse(&__where, __x))
+return 31 - __where;
   return 32; // Undefined Behavior.
-#endif
 }
 
 inline _LIBCPP_INLINE_VISIBILITY
-unsigned long __clz(unsigned long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_clzl (__x));
-#else
+int __clz(unsigned long __x) {
   

[PATCH] D49462: [ObjC] Error out when using forward-declared protocol in a @protocol expression

2018-08-16 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Sorry for the delay.

In https://reviews.llvm.org/D49462#1166032, @rjmccall wrote:

> Hmm.  I think this is a reasonable change to make to the language.  Have you 
> investigated to see if this causes source-compatibility problems?


Yes, I tested this change on internal code base. There's an impact, but the 
impact is fairly minimal. The biggest issue is actually in some Swift overlay: 
https://github.com/apple/swift/blob/c275826a41aca8268719061636efc12717b8dae1/stdlib/public/SDK/Dispatch/Dispatch.mm#L36




Comment at: test/CodeGenObjC/forward-declare-protocol-gnu.m:6
 
-Protocol *getProtocol(void)
-{
-   return @protocol(P);
-}
+@interface I 
+@end

rjmccall wrote:
> Does this really not require a definition of `P`?  Ugh.  I wonder if that's 
> reasonable to fix, too.
Nope, we don't emit the protocol metadata for it. It might make sense to 
require the definition with the implementation?



Comment at: test/Parser/objc-cxx-keyword-identifiers.mm:22
+@protocol P2;
+@protocol delete // expected-error {{expected identifier; 'delete' is a 
keyword in Objective-C++}}
+@end

rjmccall wrote:
> Why did this test need to change?
We need to declare `delete` because it's used in a `@protocol` expression on 
line 63.


Repository:
  rC Clang

https://reviews.llvm.org/D49462



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


[PATCH] D49462: [ObjC] Error out when using forward-declared protocol in a @protocol expression

2018-08-16 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 161142.
arphaman marked 3 inline comments as done.
arphaman added a comment.

address review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D49462

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGObjCMac.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprObjC.cpp
  test/CodeGenObjC/forward-declare-protocol-gnu.m
  test/CodeGenObjC/forward-protocol-metadata-symbols.m
  test/CodeGenObjC/hidden-visibility.m
  test/CodeGenObjC/link-errors.m
  test/CodeGenObjC/protocol-comdat.m
  test/CodeGenObjC/protocols-lazy.m
  test/CodeGenObjC/protocols.m
  test/PCH/objc_exprs.h
  test/Parser/objc-cxx-keyword-identifiers.mm
  test/SemaObjC/protocol-expr-neg-1.m

Index: test/SemaObjC/protocol-expr-neg-1.m
===
--- test/SemaObjC/protocol-expr-neg-1.m
+++ test/SemaObjC/protocol-expr-neg-1.m
@@ -12,7 +12,7 @@
 int main()
 {
 	Protocol *proto = @protocol(p1);
-Protocol *fproto = @protocol(fproto); // expected-warning {{@protocol is using a forward protocol declaration of 'fproto'}}
+Protocol *fproto = @protocol(fproto); // expected-error {{@protocol is using a forward protocol declaration of 'fproto'}}
 	Protocol *pp = @protocol(i); // expected-error {{cannot find protocol declaration for 'i'}}
 	Protocol *p1p = @protocol(cl); // expected-error {{cannot find protocol declaration for 'cl'}}
 }
@@ -26,9 +26,9 @@
 @end
 
 int doesConform(id foo) {
-  return [foo conformsToProtocol:@protocol(TestProtocol)]; // expected-warning {{@protocol is using a forward protocol declaration of 'TestProtocol'}}
+  return [foo conformsToProtocol:@protocol(TestProtocol)]; // expected-error {{@protocol is using a forward protocol declaration of 'TestProtocol'}}
 }
 
 int doesConformSuper(id foo) {
-  return [foo conformsToProtocol:@protocol(SuperProtocol)]; // expected-warning {{@protocol is using a forward protocol declaration of 'SuperProtocol'}}
+  return [foo conformsToProtocol:@protocol(SuperProtocol)]; // expected-error {{@protocol is using a forward protocol declaration of 'SuperProtocol'}}
 }
Index: test/Parser/objc-cxx-keyword-identifiers.mm
===
--- test/Parser/objc-cxx-keyword-identifiers.mm
+++ test/Parser/objc-cxx-keyword-identifiers.mm
@@ -18,7 +18,9 @@
 @protocol new // expected-error {{expected identifier; 'new' is a keyword in Objective-C++}}
 @end
 
-@protocol P2, delete; // expected-error {{expected identifier; 'delete' is a keyword in Objective-C++}}
+@protocol P2;
+@protocol delete // expected-error {{expected identifier; 'delete' is a keyword in Objective-C++}}
+@end
 
 @class Foo, try; // expected-error {{expected identifier; 'try' is a keyword in Objective-C++}}
 
Index: test/PCH/objc_exprs.h
===
--- test/PCH/objc_exprs.h
+++ test/PCH/objc_exprs.h
@@ -1,11 +1,13 @@
 
 @protocol foo;
+@protocol foo2
+@end
 @class itf;
 
 // Expressions
 typedef typeof(@"foo" "bar") objc_string;
 typedef typeof(@encode(int)) objc_encode;
-typedef typeof(@protocol(foo)) objc_protocol;
+typedef typeof(@protocol(foo2)) objc_protocol;
 typedef typeof(@selector(noArgs)) objc_selector_noArgs;
 typedef typeof(@selector(oneArg:)) objc_selector_oneArg;
 typedef typeof(@selector(foo:bar:)) objc_selector_twoArg;
Index: test/CodeGenObjC/protocols.m
===
--- test/CodeGenObjC/protocols.m
+++ test/CodeGenObjC/protocols.m
@@ -7,7 +7,8 @@
 -(int) conformsTo: (id) x;
 @end
 
-@protocol P0;
+@protocol P0
+@end
 
 @protocol P1
 +(void) classMethodReq0;
Index: test/CodeGenObjC/protocols-lazy.m
===
--- test/CodeGenObjC/protocols-lazy.m
+++ test/CodeGenObjC/protocols-lazy.m
@@ -18,7 +18,10 @@
 // RUN: grep OBJC_PROTOCOL_P3 %t | count 3
 // RUN: not grep OBJC_PROTOCOL_INSTANCE_METHODS_P3 %t
 @protocol P3;
-void f1() { id x = @protocol(P3); }
+@interface UserP3
+@end
+@implementation UserP3
+@end
 
 // Definition triggered by class reference.
 // RUN: grep OBJC_PROTOCOL_P4 %t | count 3
@@ -31,10 +34,16 @@
 // RUN: grep OBJC_PROTOCOL_P5 %t | count 3
 // RUN: grep OBJC_PROTOCOL_INSTANCE_METHODS_P5 %t | count 3
 @protocol P5;
-void f2() { id x = @protocol(P5); } // This generates a forward
-// reference, which has to be
-// updated on the next line.
-@protocol P5 -im1; @end   
+@interface UserP5 // This generates a forward
+  // reference, which has to be
+  // updated on the next line.
+@end
+@protocol P5 -im1; @end
+@implementation UserP5
+
+- im1 { }
+
+@end
 
 // Protocol reference following definition.
 // RUN: grep OBJC_PROTOCOL_P6 %t | count 4
Index: test/CodeGenObjC/protocol-comdat.m

[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-08-16 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In https://reviews.llvm.org/D50616#1202034, @ebevhan wrote:

> I think I've mentioned this before, but I would like to discuss the 
> possibility of adding a target hook(s) for some of these operations 
> (conversions, arithmetic when it comes). Precisely matching the emitted 
> saturation operation is virtually impossible for a target.


Sorry I forgot to address this also. Just to make sure I understand this 
correctly since I haven't used these before: target hooks are essentially for 
emitting target specific code for some operations right? Does this mean that 
the `EmitFixedPointConversion` function should be moved to a virtual method 
under `TargetCodeGenInfo` that can be overridden and this is what get's called 
instead during conversion?


Repository:
  rC Clang

https://reviews.llvm.org/D50616



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


[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:271-276
   llvm::GlobalVariable *global =
-elements.finishAndCreateGlobal("__block_descriptor_tmp",
-   CGM.getPointerAlign(),
-   /*constant*/ true,
-   llvm::GlobalValue::InternalLinkage,
-   AddrSpace);
+  elements.finishAndCreateGlobal(descName, CGM.getPointerAlign(),
+ /*constant*/ true, linkage, AddrSpace);
+
+  if (linkage == llvm::GlobalValue::LinkOnceODRLinkage)
+global->setVisibility(llvm::GlobalValue::HiddenVisibility);

rsmith wrote:
> Would it make sense to also mark this constant as `unnamed_addr`?
Yes. I don't think there is any harm in marking it as `unnamed_addr`. However, 
unfortunately it looks like ld64 doesn't try to merge `unnamed_addr` global 
variables.


Repository:
  rC Clang

https://reviews.llvm.org/D50783



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


r339964 - Relax a CHECK line to allow for dso_local

2018-08-16 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Aug 16 16:19:50 2018
New Revision: 339964

URL: http://llvm.org/viewvc/llvm-project?rev=339964=rev
Log:
Relax a CHECK line to allow for dso_local

Fixes a bot failure:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/11806

Modified:
cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c

Modified: cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c?rev=339964=339963=339964=diff
==
--- cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c (original)
+++ cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c Thu Aug 16 16:19:50 2018
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -emit-llvm -fprofile-instrument=clang -fsanitize=thread 
-o - | FileCheck %s
 
-// CHECK: define void @foo
+// CHECK: define {{.*}}@foo
 // CHECK-NOT: load {{.*}}foo
 // CHECK: ret void
 void foo() {}


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


[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:271-276
   llvm::GlobalVariable *global =
-elements.finishAndCreateGlobal("__block_descriptor_tmp",
-   CGM.getPointerAlign(),
-   /*constant*/ true,
-   llvm::GlobalValue::InternalLinkage,
-   AddrSpace);
+  elements.finishAndCreateGlobal(descName, CGM.getPointerAlign(),
+ /*constant*/ true, linkage, AddrSpace);
+
+  if (linkage == llvm::GlobalValue::LinkOnceODRLinkage)
+global->setVisibility(llvm::GlobalValue::HiddenVisibility);

Would it make sense to also mark this constant as `unnamed_addr`?


Repository:
  rC Clang

https://reviews.llvm.org/D50783



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


[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Okay.


Repository:
  rC Clang

https://reviews.llvm.org/D50783



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


[PATCH] D50783: [CodeGen] Merge identical block descriptor global variables

2018-08-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 161137.
ahatanak added a comment.

Try harder to shorten the names of block descriptor global variables.

The strings extracted from the names of the copy and dispose helpers are merged 
whenever it is possible to do so. The block layout string doesn't include 
information about `__strong`, `__weak`, or byref captures unless the 
copy/dispose helpers are missing.


Repository:
  rC Clang

https://reviews.llvm.org/D50783

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBlocks.h
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/CGObjCRuntime.h
  test/CodeGenCXX/blocks.cpp
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
  test/CodeGenObjC/fragile-arc.m
  test/CodeGenObjC/noescape.m

Index: test/CodeGenObjC/noescape.m
===
--- test/CodeGenObjC/noescape.m
+++ test/CodeGenObjC/noescape.m
@@ -17,7 +17,11 @@
 // helper functions.
 
 // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK: @[[BLOCK_DESCIPTOR_TMP_2:.*]] = internal constant { i64, i64, i8*, i64 } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
+
+// When the block is non-escaping, copy/dispose helpers aren't generated, so the
+// block layout string must include information about __strong captures.
+
+// CHECK: @[[BLOCK_DESCIPTOR_TMP_2:.*ls32l8"]] = linkonce_odr hidden constant { i64, i64, i8*, i64 } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
 
 // CHECK-LABEL: define void @test0(
 // CHECK: call void @noescapeFunc0({{.*}}, {{.*}} nocapture {{.*}})
Index: test/CodeGenObjC/fragile-arc.m
===
--- test/CodeGenObjC/fragile-arc.m
+++ test/CodeGenObjC/fragile-arc.m
@@ -126,13 +126,13 @@
 extern void useBlock(void (^block)(void));
 
 //  256 == 0x100 == starts with 1 strong
-// GLOBALS: @__block_descriptor_tmp{{.*}} = internal constant {{.*}}, i32 256 }
+// GLOBALS: @"__block_descriptor{{.*}} = linkonce_odr hidden {{.*}}, i32 256 }
 void testBlockLayoutStrong(id x) {
   useBlock(^{ (void) x; });
 }
 
 //  1   == 0x001 == starts with 1 weak
-// GLOBALS: @__block_descriptor_tmp{{.*}} = internal constant {{.*}}, i32 1 }
+// GLOBALS: @"__block_descriptor{{.*}} = linkonce_odr hidden {{.*}}, i32 1 }
 void testBlockLayoutWeak(__weak id x) {
   useBlock(^{ (void) x; });
 }
Index: test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
===
--- test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
+++ test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
@@ -30,7 +30,8 @@
   void (^block4)() = ^{ printf("%c %#lx", ch, fourByte); NSLog(@"%@", strong); };
 
   // Test5
-  // CHECK: Inline block variable layout: 0x0100, BL_STRONG:1, BL_OPERATOR:0
+  // Nothing gets printed here since the descriptor of this block is merged with
+  // the descriptor of Test3's block.
   void (^block5)() = ^{ NSLog(@"%@", strong); printf("%c %#llx", ch, eightByte); };
 
   // Test6
Index: test/CodeGenObjC/arc-blocks.m
===
--- test/CodeGenObjC/arc-blocks.m
+++ test/CodeGenObjC/arc-blocks.m
@@ -2,15 +2,10 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-UNOPT -check-prefix=CHECK-COMMON %s
 
 // CHECK-COMMON: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, align 8
-// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* 

[PATCH] D50805: Don't warn on returning the address of a label from a statement expression

2018-08-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:6927-6928
   } else if (isa(L)) {
-Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+if (LK == LK_Return)
+  Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
   } else {

You should `return false;` if you don't produce a diagnostic here. If you carry 
on, you'll emit notes below and they'll get attached to whatever other 
diagnostic was produced most recently.


https://reviews.llvm.org/D50805



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


[PATCH] D50740: [SourceManager] isPointWithin: avoid using isBeforeInTranslationUnit, compare buffer offsets directly for lexical correctness

2018-08-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D50740#1203126, @arphaman wrote:

> In https://reviews.llvm.org/D50740#1202248, @jkorous wrote:
>
> > Hi Alex, nice work!
> >
> > I am just wondering if it would be beneficial to assert Loc and End are in 
> > the same file. It might help to catch bugs.
>
>
> I don't see the value in that unless I'm misunderstanding something. We 
> already check if Loc and End are in the same file, and return false if 
> they're not.


I think we should assert that `Start` and `End` are in the same file. If not, 
the query doesn't make any sense; the range is malformed. And maybe we should 
also assert that `Start` is before `End` in that file.




Comment at: include/clang/Basic/SourceManager.h:1585-1586
+  /// located in the same inclusion span as the range).
   bool isPointWithin(SourceLocation Location, SourceLocation Start,
- SourceLocation End) const {
-return Location == Start || Location == End ||
-   (isBeforeInTranslationUnit(Start, Location) &&
-isBeforeInTranslationUnit(Location, End));
-  }
+ SourceLocation End) const;
 

Please rename this function to make it clearer what it's doing. The old 
implementation is the obvious one for a function with this name. Maybe 
`isSpellingLocInFileRange` or similar?



Comment at: lib/Basic/SourceManager.cpp:2038-2050
+  auto isOrderedInSameFile =
+  [&](SourceLocation RangeLoc,
+  llvm::function_ref Comparator) {
+std::pair DecomposedRangeLoc =
+getDecomposedLoc(getSpellingLoc(RangeLoc));
+// Ensure that we check for FileEntry equivalency to account for
+// multiple inclusions.

Does this do the right thing if both points are within (eg) macro expansion 
ranges in the same file? Eg, given:

```
// A
#define FOO BAR
// B
FOO
// C
```

is the macro-expanded `BAR` token between `B` and `C`? Is it between `A` and 
`B`?

I would guess that the intended semantics here are:

 * `Start` and `End` are expected to be file locations in the same inclusion of 
the same file, with `Start` occuring no later than `End`.
 * `Loc` is an arbitrary location.
 * Function returns `true` if the spelling location of `Loc` is in the same 
source file as `Start` and `End`, and occurs between them; `false` otherwise.

Is that right? If so, please write that down somewhere; the current function 
comment is too vague. (And if not, please write down what the intended rule is.)


Repository:
  rC Clang

https://reviews.llvm.org/D50740



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


[PATCH] D50640: Fix for bug 38508 - Don't do PCH processing when only generating preprocessor output

2018-08-16 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

In https://reviews.llvm.org/D50640#1203314, @thakis wrote:

> Thanks! Do you need someone to land this?


Feel free to commit it if you want.  Otherwise I'll have my colleague take care 
of it in the morning.  Thanks!


https://reviews.llvm.org/D50640



___
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

2018-08-16 Thread Galina Kistanova via cfe-commits
 Hello everyone,

LLVM buildmaster will be updated and restarted after 6PM 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: [libcxx] r339943 - Establish the header. NFC yet. Reviewed as https://reviews.llvm.org/D50815

2018-08-16 Thread Vitaly Buka via cfe-commits
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/27733
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/14670

On Thu, Aug 16, 2018 at 3:30 PM Vitaly Buka  wrote:

> This brakes some bots
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/22441
>
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_msan/include/c++/v1/algorithm:648:10:
>  fatal error: 'bit' file not found
> #include 
>  ^
> 1 error generated.
>
>
> On Thu, Aug 16, 2018 at 2:36 PM Marshall Clow via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: marshall
>> Date: Thu Aug 16 14:35:38 2018
>> New Revision: 339943
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=339943=rev
>> Log:
>> Establish the  header. NFC yet. Reviewed as
>> https://reviews.llvm.org/D50815
>>
>> Added:
>> libcxx/trunk/include/bit
>> Modified:
>> libcxx/trunk/include/algorithm
>> libcxx/trunk/include/module.modulemap
>> libcxx/trunk/test/libcxx/double_include.sh.cpp
>>
>> Modified: libcxx/trunk/include/algorithm
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=339943=339942=339943=diff
>>
>> ==
>> --- libcxx/trunk/include/algorithm (original)
>> +++ libcxx/trunk/include/algorithm Thu Aug 16 14:35:38 2018
>> @@ -645,13 +645,7 @@ template >  #include 
>>  #include 
>>  #include 
>> -
>> -#if defined(__IBMCPP__)
>> -#include "support/ibm/support.h"
>> -#endif
>> -#if defined(_LIBCPP_COMPILER_MSVC)
>> -#include 
>> -#endif
>> +#include 
>>
>>  #include <__debug>
>>
>> @@ -788,135 +782,6 @@ struct __debug_less
>>
>>  #endif  // _LIBCPP_DEBUG
>>
>> -// Precondition:  __x != 0
>> -inline _LIBCPP_INLINE_VISIBILITY
>> -unsigned __ctz(unsigned __x) {
>> -#ifndef _LIBCPP_COMPILER_MSVC
>> -return static_cast(__builtin_ctz(__x));
>> -#else
>> -  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
>> -  static_assert(sizeof(unsigned long) == 4, "");
>> -  unsigned long where;
>> -  // Search from LSB to MSB for first set bit.
>> -  // Returns zero if no set bit is found.
>> -  if (_BitScanForward(, __x))
>> -return where;
>> -  return 32;
>> -#endif
>> -}
>> -
>> -inline _LIBCPP_INLINE_VISIBILITY
>> -unsigned long __ctz(unsigned long __x) {
>> -#ifndef _LIBCPP_COMPILER_MSVC
>> -return static_cast(__builtin_ctzl(__x));
>> -#else
>> -static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
>> -return __ctz(static_cast(__x));
>> -#endif
>> -}
>> -
>> -inline _LIBCPP_INLINE_VISIBILITY
>> -unsigned long long __ctz(unsigned long long __x) {
>> -#ifndef _LIBCPP_COMPILER_MSVC
>> -return static_cast(__builtin_ctzll(__x));
>> -#else
>> -unsigned long where;
>> -// Search from LSB to MSB for first set bit.
>> -// Returns zero if no set bit is found.
>> -#if defined(_LIBCPP_HAS_BITSCAN64)
>> -(defined(_M_AMD64) || defined(__x86_64__))
>> -  if (_BitScanForward64(, __x))
>> -return static_cast(where);
>> -#else
>> -  // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit
>> calls.
>> -  // Scan the Low Word.
>> -  if (_BitScanForward(, static_cast(__x)))
>> -return where;
>> -  // Scan the High Word.
>> -  if (_BitScanForward(, static_cast(__x >> 32)))
>> -return where + 32; // Create a bit offset from the LSB.
>> -#endif
>> -  return 64;
>> -#endif // _LIBCPP_COMPILER_MSVC
>> -}
>> -
>> -// Precondition:  __x != 0
>> -inline _LIBCPP_INLINE_VISIBILITY
>> -unsigned __clz(unsigned __x) {
>> -#ifndef _LIBCPP_COMPILER_MSVC
>> -return static_cast(__builtin_clz(__x));
>> -#else
>> -  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
>> -  static_assert(sizeof(unsigned long) == 4, "");
>> -  unsigned long where;
>> -  // Search from LSB to MSB for first set bit.
>> -  // Returns zero if no set bit is found.
>> -  if (_BitScanReverse(, __x))
>> -return 31 - where;
>> -  return 32; // Undefined Behavior.
>> -#endif
>> -}
>> -
>> -inline _LIBCPP_INLINE_VISIBILITY
>> -unsigned long __clz(unsigned long __x) {
>> -#ifndef _LIBCPP_COMPILER_MSVC
>> -return static_cast(__builtin_clzl (__x));
>> -#else
>> -static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
>> -return __clz(static_cast(__x));
>> -#endif
>> -}
>> -
>> -inline _LIBCPP_INLINE_VISIBILITY
>> -unsigned long long __clz(unsigned long long __x) {
>> -#ifndef _LIBCPP_COMPILER_MSVC
>> -return static_cast(__builtin_clzll(__x));
>> -#else
>> -  unsigned long where;
>> -// BitScanReverse scans from MSB to LSB for first set bit.
>> -// Returns 0 if no set bit is found.
>> -#if defined(_LIBCPP_HAS_BITSCAN64)
>> -  if (_BitScanReverse64(, __x))
>> -return static_cast(63 - where);
>> -#else
>> -  // Scan the high 32 bits.
>> -  if (_BitScanReverse(, static_cast(__x >> 32)))
>> -return 63 - (where + 32); // Create a bit offset from the MSB.
>> -  // Scan the low 32 bits.
>> -  if (_BitScanReverse(, static_cast(__x)))
>> -return 

Re: [libcxx] r339943 - Establish the header. NFC yet. Reviewed as https://reviews.llvm.org/D50815

2018-08-16 Thread Vitaly Buka via cfe-commits
This brakes some bots
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/22441

/b/sanitizer-x86_64-linux-fast/build/libcxx_build_msan/include/c++/v1/algorithm:648:10:
fatal error: 'bit' file not found
#include 
 ^
1 error generated.


On Thu, Aug 16, 2018 at 2:36 PM Marshall Clow via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: marshall
> Date: Thu Aug 16 14:35:38 2018
> New Revision: 339943
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339943=rev
> Log:
> Establish the  header. NFC yet. Reviewed as
> https://reviews.llvm.org/D50815
>
> Added:
> libcxx/trunk/include/bit
> Modified:
> libcxx/trunk/include/algorithm
> libcxx/trunk/include/module.modulemap
> libcxx/trunk/test/libcxx/double_include.sh.cpp
>
> Modified: libcxx/trunk/include/algorithm
> URL:
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=339943=339942=339943=diff
>
> ==
> --- libcxx/trunk/include/algorithm (original)
> +++ libcxx/trunk/include/algorithm Thu Aug 16 14:35:38 2018
> @@ -645,13 +645,7 @@ template   #include 
>  #include 
>  #include 
> -
> -#if defined(__IBMCPP__)
> -#include "support/ibm/support.h"
> -#endif
> -#if defined(_LIBCPP_COMPILER_MSVC)
> -#include 
> -#endif
> +#include 
>
>  #include <__debug>
>
> @@ -788,135 +782,6 @@ struct __debug_less
>
>  #endif  // _LIBCPP_DEBUG
>
> -// Precondition:  __x != 0
> -inline _LIBCPP_INLINE_VISIBILITY
> -unsigned __ctz(unsigned __x) {
> -#ifndef _LIBCPP_COMPILER_MSVC
> -return static_cast(__builtin_ctz(__x));
> -#else
> -  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
> -  static_assert(sizeof(unsigned long) == 4, "");
> -  unsigned long where;
> -  // Search from LSB to MSB for first set bit.
> -  // Returns zero if no set bit is found.
> -  if (_BitScanForward(, __x))
> -return where;
> -  return 32;
> -#endif
> -}
> -
> -inline _LIBCPP_INLINE_VISIBILITY
> -unsigned long __ctz(unsigned long __x) {
> -#ifndef _LIBCPP_COMPILER_MSVC
> -return static_cast(__builtin_ctzl(__x));
> -#else
> -static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
> -return __ctz(static_cast(__x));
> -#endif
> -}
> -
> -inline _LIBCPP_INLINE_VISIBILITY
> -unsigned long long __ctz(unsigned long long __x) {
> -#ifndef _LIBCPP_COMPILER_MSVC
> -return static_cast(__builtin_ctzll(__x));
> -#else
> -unsigned long where;
> -// Search from LSB to MSB for first set bit.
> -// Returns zero if no set bit is found.
> -#if defined(_LIBCPP_HAS_BITSCAN64)
> -(defined(_M_AMD64) || defined(__x86_64__))
> -  if (_BitScanForward64(, __x))
> -return static_cast(where);
> -#else
> -  // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit
> calls.
> -  // Scan the Low Word.
> -  if (_BitScanForward(, static_cast(__x)))
> -return where;
> -  // Scan the High Word.
> -  if (_BitScanForward(, static_cast(__x >> 32)))
> -return where + 32; // Create a bit offset from the LSB.
> -#endif
> -  return 64;
> -#endif // _LIBCPP_COMPILER_MSVC
> -}
> -
> -// Precondition:  __x != 0
> -inline _LIBCPP_INLINE_VISIBILITY
> -unsigned __clz(unsigned __x) {
> -#ifndef _LIBCPP_COMPILER_MSVC
> -return static_cast(__builtin_clz(__x));
> -#else
> -  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
> -  static_assert(sizeof(unsigned long) == 4, "");
> -  unsigned long where;
> -  // Search from LSB to MSB for first set bit.
> -  // Returns zero if no set bit is found.
> -  if (_BitScanReverse(, __x))
> -return 31 - where;
> -  return 32; // Undefined Behavior.
> -#endif
> -}
> -
> -inline _LIBCPP_INLINE_VISIBILITY
> -unsigned long __clz(unsigned long __x) {
> -#ifndef _LIBCPP_COMPILER_MSVC
> -return static_cast(__builtin_clzl (__x));
> -#else
> -static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
> -return __clz(static_cast(__x));
> -#endif
> -}
> -
> -inline _LIBCPP_INLINE_VISIBILITY
> -unsigned long long __clz(unsigned long long __x) {
> -#ifndef _LIBCPP_COMPILER_MSVC
> -return static_cast(__builtin_clzll(__x));
> -#else
> -  unsigned long where;
> -// BitScanReverse scans from MSB to LSB for first set bit.
> -// Returns 0 if no set bit is found.
> -#if defined(_LIBCPP_HAS_BITSCAN64)
> -  if (_BitScanReverse64(, __x))
> -return static_cast(63 - where);
> -#else
> -  // Scan the high 32 bits.
> -  if (_BitScanReverse(, static_cast(__x >> 32)))
> -return 63 - (where + 32); // Create a bit offset from the MSB.
> -  // Scan the low 32 bits.
> -  if (_BitScanReverse(, static_cast(__x)))
> -return 63 - where;
> -#endif
> -  return 64; // Undefined Behavior.
> -#endif // _LIBCPP_COMPILER_MSVC
> -}
> -
> -inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {
> -#ifndef _LIBCPP_COMPILER_MSVC
> -  return __builtin_popcount  (__x);
> -#else
> -  static_assert(sizeof(unsigned) == 4, "");
> -  return __popcnt(__x);
> -#endif
> -}
> -
> -inline 

[PATCH] D50740: [SourceManager] isPointWithin: avoid using isBeforeInTranslationUnit, compare buffer offsets directly for lexical correctness

2018-08-16 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 161132.
arphaman marked an inline comment as done.
arphaman added a comment.

- Use lambda
- Work with spelling locs


Repository:
  rC Clang

https://reviews.llvm.org/D50740

Files:
  include/clang/Basic/SourceManager.h
  lib/Basic/SourceManager.cpp
  unittests/Basic/SourceManagerTest.cpp

Index: unittests/Basic/SourceManagerTest.cpp
===
--- unittests/Basic/SourceManagerTest.cpp
+++ unittests/Basic/SourceManagerTest.cpp
@@ -377,6 +377,123 @@
   EXPECT_TRUE(SourceMgr.isBeforeInTranslationUnit(Macros[10].Loc, Macros[11].Loc));
 }
 
+TEST_F(SourceManagerTest, isPointWithin) {
+  const char *header = "int x;";
+
+  const char *main = "#include \n"
+ "#include \n";
+
+  std::unique_ptr HeaderBuf =
+  llvm::MemoryBuffer::getMemBuffer(header);
+  std::unique_ptr MainBuf =
+  llvm::MemoryBuffer::getMemBuffer(main);
+  SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(MainBuf)));
+
+  const FileEntry *headerFile =
+  FileMgr.getVirtualFile("/test-header.h", HeaderBuf->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
+
+  TrivialModuleLoader ModLoader;
+  MemoryBufferCache PCMCache;
+  HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+  Diags, LangOpts, &*Target);
+  Preprocessor PP(std::make_shared(), Diags, LangOpts,
+  SourceMgr, PCMCache, HeaderInfo, ModLoader,
+  /*IILookup =*/nullptr,
+  /*OwnsHeaderSearch =*/false);
+  PP.Initialize(*Target);
+
+  PP.EnterMainSourceFile();
+
+  std::vector Tokens;
+  while (1) {
+Token tok;
+PP.Lex(tok);
+if (tok.is(tok::eof))
+  break;
+Tokens.push_back(tok);
+  }
+
+  // Make sure we got the tokens that we expected.
+  ASSERT_EQ(6U, Tokens.size());
+
+  // Make sure the FileIDs are different.
+  SourceLocation L1 = Tokens[0].getLocation();
+  SourceLocation L2 = Tokens[3].getLocation();
+  ASSERT_NE(L1, L2);
+
+  // The location of the 'int' in the first inclusion is lexically within the
+  // range of the 'int' in the second inclusion.
+  ASSERT_TRUE(SourceMgr.isPointWithin(L1, L2, L2));
+  // The location of the 'int' in the second inclusion is lexically within the
+  // range of the 'int' in the first inclusion.
+  ASSERT_TRUE(SourceMgr.isPointWithin(L2, L1, L1));
+  // The location of the 'x' in the second inclusion is lexically within the
+  // range of the 'int' in the first inclusion and ';' in the second inclusion.
+  ASSERT_TRUE(SourceMgr.isPointWithin(Tokens[4].getLocation(), L1,
+  Tokens[5].getLocation()));
+  // The location of the 'int' in the second inclusion is lexically outside of
+  // the 'x' in the first inclusion and ';' in the second inclusion.
+  ASSERT_FALSE(SourceMgr.isPointWithin(Tokens[3].getLocation(),
+   Tokens[1].getLocation(),
+   Tokens[5].getLocation()));
+}
+
+TEST_F(SourceManagerTest, isPointWithinMacroSpelling) {
+  const char *main = "#define MYMACRO int x;\n"
+ "MYMACRO\n"
+ "MYMACRO\n";
+
+  std::unique_ptr MainBuf =
+  llvm::MemoryBuffer::getMemBuffer(main);
+  SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(MainBuf)));
+
+  TrivialModuleLoader ModLoader;
+  MemoryBufferCache PCMCache;
+  HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+  Diags, LangOpts, &*Target);
+  Preprocessor PP(std::make_shared(), Diags, LangOpts,
+  SourceMgr, PCMCache, HeaderInfo, ModLoader,
+  /*IILookup =*/nullptr,
+  /*OwnsHeaderSearch =*/false);
+  PP.Initialize(*Target);
+
+  PP.EnterMainSourceFile();
+
+  std::vector Tokens;
+  while (1) {
+Token tok;
+PP.Lex(tok);
+if (tok.is(tok::eof))
+  break;
+Tokens.push_back(tok);
+  }
+
+  // Make sure we got the tokens that we expected.
+  ASSERT_EQ(6U, Tokens.size());
+
+  // Make sure the FileIDs are different.
+  SourceLocation L1 = Tokens[0].getLocation();
+  SourceLocation L2 = Tokens[3].getLocation();
+  ASSERT_NE(L1, L2);
+
+  // The location of the 'int' in the first expansion is lexically within the
+  // range of the 'int' in the second expansion.
+  ASSERT_TRUE(SourceMgr.isPointWithin(L1, L2, L2));
+  // The location of the 'int' in the second expansion is lexically within the
+  // range of the 'int' in the first expansion.
+  ASSERT_TRUE(SourceMgr.isPointWithin(L2, L1, L1));
+  // The location of the 'x' in the second expansion is lexically within the
+  // range of the 'int' in the first expansion and ';' in the second expansion.
+  ASSERT_TRUE(SourceMgr.isPointWithin(Tokens[4].getLocation(), L1,
+  Tokens[5].getLocation()));
+  // The location of the 'int' in the second expansion is lexically outside of
+  // the 'x' in the 

[PATCH] D50740: [SourceManager] isPointWithin: avoid using isBeforeInTranslationUnit, compare buffer offsets directly for lexical correctness

2018-08-16 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked 2 inline comments as done.
arphaman added inline comments.



Comment at: lib/Basic/SourceManager.cpp:2035
+ "Passed invalid source location!");
+  assert(Start.isFileID() && End.isFileID() && Loc.isFileID() &&
+ "Passed non-file source location!");

ioeric wrote:
> Why do we disallow locations from macro expansions?
I changed the patch to allow them by working with spelling locs.


Repository:
  rC Clang

https://reviews.llvm.org/D50740



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


[PATCH] D50542: [clang-tidy] Add abseil-no-internal-deps check

2018-08-16 Thread Hugo Gonzalez via Phabricator via cfe-commits
hugoeg updated this revision to Diff 161130.
hugoeg added a comment.

added IsInAbseilFile Matcher


https://reviews.llvm.org/D50542

Files:
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/abseil/CMakeLists.txt
  clang-tidy/abseil/NoInternalDepsCheck.cpp
  clang-tidy/abseil/NoInternalDepsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-no-internal-deps.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/absl/strings/str_cat.h
  test/clang-tidy/abseil-no-internal-deps.cpp

Index: test/clang-tidy/abseil-no-internal-deps.cpp
===
--- test/clang-tidy/abseil-no-internal-deps.cpp
+++ test/clang-tidy/abseil-no-internal-deps.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s abseil-no-internal-deps %t
+
+#include "Inputs/absl/strings/str_cat.h"
+
+void DirectAcess() {
+  absl::strings_internal::InternalFunction();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+
+  absl::strings_internal::InternalTemplateFunction ("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+}
+
+class FriendUsage {
+  friend struct absl::container_internal::InternalStruct;
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+};
+i hate this
+namespace absl {
+  void OpeningNamespace() {
+strings_internal::InternalFunction();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+  }
+} // namespace absl
+
+void CorrectUsage() {
+  std::string Str = absl::StringsFunction("a");
+  absl::SomeContainer b;
+}
+
+namespace absl {
+  SomeContainer b;
+  std::string Str = absl::StringsFunction("a");
+} // namespace absl
Index: test/clang-tidy/Inputs/absl/strings/str_cat.h
===
--- test/clang-tidy/Inputs/absl/strings/str_cat.h
+++ test/clang-tidy/Inputs/absl/strings/str_cat.h
@@ -0,0 +1,33 @@
+namespace std {
+struct string {
+  string(const char *);
+  ~string();
+};
+} // namespace std
+
+namespace absl {
+std::string StringsFunction(std::string s1) { return s1; }
+class SomeContainer {};
+namespace strings_internal {
+void InternalFunction() {}
+template  P InternalTemplateFunction(P a) {}
+} // namespace strings_internal
+
+namespace container_internal {
+struct InternalStruct {};
+} // namespace container_internal
+} // namespace absl
+
+// should not trigger warnings because inside Abseil files
+void DirectAcessInternal() {
+  absl::strings_internal::InternalFunction();
+  absl::strings_internal::InternalTemplateFunction("a");
+}
+
+class FriendUsageInternal {
+  friend struct absl::container_internal::InternalStruct;
+};
+
+namespace absl {
+void OpeningNamespaceInternally() { strings_internal::InternalFunction(); }
+} // namespace absl
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -4,6 +4,7 @@
 =
 
 .. toctree::
+   abseil-no-internal-deps
abseil-string-find-startswith
android-cloexec-accept
android-cloexec-accept4
Index: docs/clang-tidy/checks/abseil-no-internal-deps.rst
===
--- docs/clang-tidy/checks/abseil-no-internal-deps.rst
+++ docs/clang-tidy/checks/abseil-no-internal-deps.rst
@@ -0,0 +1,21 @@
+subl.. title:: clang-tidy - abseil-no-internal-deps
+
+abseil-no-internal-deps
+===
+
+Gives a warning if code using Abseil depends on internal details. If something
+is in a namespace that includes the word “internal”, code is not allowed to 
+depend upon it beaucse it’s an implementation detail. They cannot friend it, 
+include it, you mention it or refer to it in any way. Doing so violates 
+Abseil's compatibility guidelines and may result in breakage. See 
+https://abseil.io/about/compatibility for more information.
+
+The following cases will result in warnings:
+
+.. code-block:: c++
+
+  absl::strings_internal::foo();
+  class foo{
+friend struct absl::container_internal::faa;
+  };
+  absl::memory_internal::MakeUniqueResult();
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,7 +57,10 @@
 Improvements to clang-tidy
 --
 
-The improvements are...
+- New :doc:`abseil-no-internal-deps
+  ` check.
+  
+  Gives a warning if code using Abseil depends on internal details.
 
 Improvements to include-fixer
 -
Index: clang-tidy/abseil/NoInternalDepsCheck.h

r339955 - [InstrProf] Use atomic profile counter updates for TSan

2018-08-16 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Aug 16 15:24:47 2018
New Revision: 339955

URL: http://llvm.org/viewvc/llvm-project?rev=339955=rev
Log:
[InstrProf] Use atomic profile counter updates for TSan

Thread sanitizer instrumentation fails to skip all loads and stores to
profile counters. This can happen if profile counter updates are merged:

  %.sink = phi i64* ...
  %pgocount5 = load i64, i64* %.sink
  %27 = add i64 %pgocount5, 1
  %28 = bitcast i64* %.sink to i8*
  call void @__tsan_write8(i8* %28)
  store i64 %27, i64* %.sink

To suppress TSan diagnostics about racy counter updates, make the
counter updates atomic when TSan is enabled. If there's general interest
in this mode it can be surfaced as a clang/swift driver option.

Testing: check-{llvm,clang,profile}

rdar://40477803

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

Added:
cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c
Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=339955=339954=339955=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Aug 16 15:24:47 2018
@@ -653,6 +653,11 @@ void EmitAssemblyHelper::CreatePasses(le
 InstrProfOptions Options;
 Options.NoRedZone = CodeGenOpts.DisableRedZone;
 Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
+
+// TODO: Surface the option to emit atomic profile counter increments at
+// the driver level.
+Options.Atomic = LangOpts.Sanitize.has(SanitizerKind::Thread);
+
 MPM.add(createInstrProfilingLegacyPass(Options));
   }
   if (CodeGenOpts.hasProfileIRInstr()) {

Added: cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c?rev=339955=auto
==
--- cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c (added)
+++ cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c Thu Aug 16 15:24:47 2018
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -emit-llvm -fprofile-instrument=clang -fsanitize=thread 
-o - | FileCheck %s
+
+// CHECK: define void @foo
+// CHECK-NOT: load {{.*}}foo
+// CHECK: ret void
+void foo() {}


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


[PATCH] D50640: Fix for bug 38508 - Don't do PCH processing when only generating preprocessor output

2018-08-16 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.

Thanks! Do you need someone to land this?


https://reviews.llvm.org/D50640



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


[PATCH] D50870: Close FileEntries of cached files in ModuleManager::addModule().

2018-08-16 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

@bruno: When we last discussed this my plan was to avoid the stat() in 
lookupModuleFile() for files that were just added to the PCMCache by WriteAST() 
entirely, but ModuleManager::Modules is a DenseMap and 
lookupModuleFile() is the easiest way to create a new FileEntry. It would be 
nice to find a way to avoid the stat() for a file that we just wrote, but it 
wasn't immediately obvious to me how to do that.


Repository:
  rL LLVM

https://reviews.llvm.org/D50870



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


[libcxxabi] r339952 - Factor Node creation out of the demangler. No functionality change intended.

2018-08-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 16 15:04:36 2018
New Revision: 339952

URL: http://llvm.org/viewvc/llvm-project?rev=339952=rev
Log:
Factor Node creation out of the demangler. No functionality change intended.

(This is a port of llvm r339944 to libcxxabi.)

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=339952=339951=339952=diff
==
--- libcxxabi/trunk/src/cxa_demangle.cpp (original)
+++ libcxxabi/trunk/src/cxa_demangle.cpp Thu Aug 16 15:04:36 2018
@@ -1953,6 +1953,23 @@ public:
   }
 };
 
+class DefaultAllocator {
+  BumpPointerAllocator Alloc;
+
+public:
+  void reset() { Alloc.reset(); }
+
+  template T *makeNode(Args &&...args) {
+return new (Alloc.allocate(sizeof(T)))
+T(std::forward(args)...);
+  }
+
+  void *allocateNodeArray(size_t sz) {
+return Alloc.allocate(sizeof(Node *) * sz);
+  }
+};
+
+template
 struct Db {
   const char *First;
   const char *Last;
@@ -1983,7 +2000,7 @@ struct Db {
   bool PermitForwardTemplateReferences = false;
   bool ParsingLambdaParams = false;
 
-  BumpPointerAllocator ASTAllocator;
+  Alloc ASTAllocator;
 
   Db(const char *First_, const char *Last_) : First(First_), Last(Last_) {}
 
@@ -2000,13 +2017,12 @@ struct Db {
   }
 
   template  T *make(Args &&... args) {
-return new (ASTAllocator.allocate(sizeof(T)))
-T(std::forward(args)...);
+return ASTAllocator.template makeNode(std::forward(args)...);
   }
 
   template  NodeArray makeNodeArray(It begin, It end) {
 size_t sz = static_cast(end - begin);
-void *mem = ASTAllocator.allocate(sizeof(Node *) * sz);
+void *mem = ASTAllocator.allocateNodeArray(sz);
 Node **data = new (mem) Node *[sz];
 std::copy(begin, end, data);
 return NodeArray(data, sz);
@@ -2143,7 +2159,7 @@ const char* parse_discriminator(const ch
 //
 //  ::= 
 //  ::= 
-Node *Db::parseName(NameState *State) {
+template Node *Db::parseName(NameState *State) {
   consumeIf('L'); // extension
 
   if (look() == 'N')
@@ -2184,7 +2200,7 @@ Node *Db::parseName(NameState *State) {
 //  := Z  E  []
 //  := Z  E s []
 //  := Z  Ed [  ] _ 
-Node *Db::parseLocalName(NameState *State) {
+template Node *Db::parseLocalName(NameState *State) {
   if (!consumeIf('Z'))
 return nullptr;
   Node *Encoding = parseEncoding();
@@ -2216,7 +2232,7 @@ Node *Db::parseLocalName(NameState *Stat
 //  ::= 
 // ::= St# ::std::
 // extension   ::= StL
-Node *Db::parseUnscopedName(NameState *State) {
+template Node *Db::parseUnscopedName(NameState *State) {
  if (consumeIf("StL") || consumeIf("St")) {
Node *R = parseUnqualifiedName(State);
if (R == nullptr)
@@ -2231,27 +2247,28 @@ Node *Db::parseUnscopedName(NameState *S
 //::= 
 //::= 
 //::= DC + E  # structured binding 
declaration
-Node *Db::parseUnqualifiedName(NameState *State) {
- // s are special-cased in parseNestedName().
- Node *Result;
- if (look() == 'U')
-   Result = parseUnnamedTypeName(State);
- else if (look() >= '1' && look() <= '9')
-   Result = parseSourceName(State);
- else if (consumeIf("DC")) {
-   size_t BindingsBegin = Names.size();
-   do {
- Node *Binding = parseSourceName(State);
- if (Binding == nullptr)
-   return nullptr;
- Names.push_back(Binding);
-   } while (!consumeIf('E'));
-   Result = make(popTrailingNodeArray(BindingsBegin));
- } else
-   Result = parseOperatorName(State);
- if (Result != nullptr)
-   Result = parseAbiTags(Result);
- return Result;
+template
+Node *Db::parseUnqualifiedName(NameState *State) {
+  // s are special-cased in parseNestedName().
+  Node *Result;
+  if (look() == 'U')
+Result = parseUnnamedTypeName(State);
+  else if (look() >= '1' && look() <= '9')
+Result = parseSourceName(State);
+  else if (consumeIf("DC")) {
+size_t BindingsBegin = Names.size();
+do {
+  Node *Binding = parseSourceName(State);
+  if (Binding == nullptr)
+return nullptr;
+  Names.push_back(Binding);
+} while (!consumeIf('E'));
+Result = make(popTrailingNodeArray(BindingsBegin));
+  } else
+Result = parseOperatorName(State);
+  if (Result != nullptr)
+Result = parseAbiTags(Result);
+  return Result;
 }
 
 //  ::= Ut [] _
@@ -2260,7 +2277,7 @@ Node *Db::parseUnqualifiedName(NameState
 //  ::= Ul  E [  ] _
 //
 //  ::= +  # Parameter types or "v" if the lambda 
has no parameters
-Node *Db::parseUnnamedTypeName(NameState *) {
+template Node *Db::parseUnnamedTypeName(NameState *) {
   if (consumeIf("Ut")) {
 StringView Count = parseNumber();
 if (!consumeIf('_'))
@@ -2289,7 +2306,7 @@ Node *Db::parseUnnamedTypeName(NameState
 }
 
 //  ::=  
-Node *Db::parseSourceName(NameState *) {
+template Node 

[PATCH] D50870: Close FileEntries of cached files in ModuleManager::addModule().

2018-08-16 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl created this revision.
aprantl added reviewers: bruno, rsmith, teemperor.
Herald added a subscriber: llvm-commits.

Close FileEntries of cached files in ModuleManager::addModule().

While investigating why LLDB (which can build hundreds of clang
modules during one debug session) was getting "too many open files"
errors, I found that most of them are .pcm files that are kept open by
ModuleManager. Pretty much all of the open file dscriptors are
FileEntries that are refering to `.pcm` files for which a buffer
already exists in a CompilerInstance's PCMCache.

Before PCMCache was added it was necessary to hold on to open file
descriptors to ensure that all ModuleManagers using the same
FileManager read the a consistent version of a given `.pcm` file on
disk, even when a concurrent clang process overwrites the file halfway
through. The PCMCache makes this practice unnecessary, since it caches
the entire contents of a `.pcm` file, while the FileManager caches all
the stat() information.

This patch adds a call to FileEntry::closeFile() to the path where a
Buffer has already been created. This is necessary because even for a
freshly written `.pcm` file the file is stat()ed once immediately
after writing to generate a FileEntry in the FileManager. Because a
freshly-generated file's contents is stored in the PCMCache, it is
fine to close the file immediately thereafter.  The second change this
patch makes is to set the `ShouldClose` flag to true when reading a
`.pcm` file into the PCMCache for the first time.

[For reference, in 1 Clang instance there is

- 1 FileManager and
- n ModuleManagers with
- n PCMCaches.]

rdar://problem/40906753


Repository:
  rL LLVM

https://reviews.llvm.org/D50870

Files:
  lib/Serialization/ModuleManager.cpp


Index: lib/Serialization/ModuleManager.cpp
===
--- lib/Serialization/ModuleManager.cpp
+++ lib/Serialization/ModuleManager.cpp
@@ -161,21 +161,24 @@
   if (std::unique_ptr Buffer = lookupBuffer(FileName)) {
 // The buffer was already provided for us.
 NewModule->Buffer = >addBuffer(FileName, std::move(Buffer));
+// Since the cached buffer is reused, it is safe to close the file
+// descriptor that was opened while stat()ing the PCM in
+// lookupModuleFile() above, it won't be needed any longer.
+Entry->closeFile();
   } else if (llvm::MemoryBuffer *Buffer = PCMCache->lookupBuffer(FileName)) {
 NewModule->Buffer = Buffer;
+// As above, the file descriptor is no longer needed.
+Entry->closeFile();
   } else {
 // Open the AST file.
 llvm::ErrorOr> 
Buf((std::error_code()));
 if (FileName == "-") {
   Buf = llvm::MemoryBuffer::getSTDIN();
 } else {
-  // Leave the FileEntry open so if it gets read again by another
-  // ModuleManager it must be the same underlying file.
-  // FIXME: Because FileManager::getFile() doesn't guarantee that it will
-  // give us an open file, this may not be 100% reliable.
+  // Get a buffer of the file and close the file descriptor when done.
   Buf = FileMgr.getBufferForFile(NewModule->File,
  /*IsVolatile=*/false,
- /*ShouldClose=*/false);
+ /*ShouldClose=*/true);
 }
 
 if (!Buf) {


Index: lib/Serialization/ModuleManager.cpp
===
--- lib/Serialization/ModuleManager.cpp
+++ lib/Serialization/ModuleManager.cpp
@@ -161,21 +161,24 @@
   if (std::unique_ptr Buffer = lookupBuffer(FileName)) {
 // The buffer was already provided for us.
 NewModule->Buffer = >addBuffer(FileName, std::move(Buffer));
+// Since the cached buffer is reused, it is safe to close the file
+// descriptor that was opened while stat()ing the PCM in
+// lookupModuleFile() above, it won't be needed any longer.
+Entry->closeFile();
   } else if (llvm::MemoryBuffer *Buffer = PCMCache->lookupBuffer(FileName)) {
 NewModule->Buffer = Buffer;
+// As above, the file descriptor is no longer needed.
+Entry->closeFile();
   } else {
 // Open the AST file.
 llvm::ErrorOr> Buf((std::error_code()));
 if (FileName == "-") {
   Buf = llvm::MemoryBuffer::getSTDIN();
 } else {
-  // Leave the FileEntry open so if it gets read again by another
-  // ModuleManager it must be the same underlying file.
-  // FIXME: Because FileManager::getFile() doesn't guarantee that it will
-  // give us an open file, this may not be 100% reliable.
+  // Get a buffer of the file and close the file descriptor when done.
   Buf = FileMgr.getBufferForFile(NewModule->File,
  /*IsVolatile=*/false,
- /*ShouldClose=*/false);
+ /*ShouldClose=*/true);
 }
 
 if (!Buf) {

[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-08-16 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
juliehockett marked an inline comment as done.
Closed by commit rCTE339948: Implement a (simple) Markdown generator (authored 
by juliehockett, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43424?vs=159091=161123#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43424

Files:
  clang-doc/CMakeLists.txt
  clang-doc/Generators.cpp
  clang-doc/Generators.h
  clang-doc/MDGenerator.cpp
  clang-doc/Representation.h
  clang-doc/YAMLGenerator.cpp
  clang-doc/gen_tests.py
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/md-comment.cpp
  test/clang-doc/md-linkage.cpp
  test/clang-doc/md-module.cpp
  test/clang-doc/md-namespace.cpp
  test/clang-doc/md-record.cpp

Index: clang-doc/gen_tests.py
===
--- clang-doc/gen_tests.py
+++ clang-doc/gen_tests.py
@@ -18,16 +18,19 @@
 
 To generate all current tests:
 - Generate mapper tests:
-python gen_tests.py -flag='--dump-mapper' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix mapper
+python gen_tests.py -flag='--dump-mapper' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix mapper -use-check-next
 
 - Generate reducer tests:
-python gen_tests.py -flag='--dump-intermediate' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix bc
+python gen_tests.py -flag='--dump-intermediate' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix bc -use-check-next
 
 - Generate yaml tests:
-python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix yaml
+python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix yaml -use-check-next
 
 - Generate public decl tests:
-python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--public' -flag='--extra-arg=-fmodules-ts' -prefix public
+python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--public' -flag='--extra-arg=-fmodules-ts' -prefix public -use-check-next
+
+- Generate Markdown tests:
+python gen_tests.py -flag='--format=md' -flag='--doxygen' -flag='--public' -flag='--extra-arg=-fmodules-ts' -prefix md
 
 This script was written on/for Linux, and has not been tested on any other
 platform and so it may not work.
@@ -95,7 +98,8 @@
 return code
 
 
-def get_output(root, out_file, case_out_path, flags, checkname, bcanalyzer):
+def get_output(root, out_file, case_out_path, flags, checkname, bcanalyzer,
+check_next=True):
 output = ''
 run_cmd = ''
 if '--dump-mapper' in flags or '--dump-intermediate' in flags:
@@ -119,8 +123,14 @@
 output = re.sub(YAML_USR_REGEX, YAML_USR, output)
 output = re.sub(BITCODE_USR_REGEX, BITCODE_USR, output)
 output = CHECK.format(checkname) + output.rstrip()
-output = run_cmd + output.replace('\n',
-  '\n' + CHECK_NEXT.format(checkname))
+
+if check_next:
+  check_comment = CHECK_NEXT.format(checkname)
+else:
+  check_comment = CHECK.format(checkname)
+
+output = output.replace('\n', '\n' + check_comment)
+output = run_cmd + output.replace('%s\n' % check_comment, "")
 
 return output + '\n'
 
@@ -151,6 +161,12 @@
 metavar="PATH",
 default='llvm-bcanalyzer',
 help='path to llvm-bcanalyzer binary')
+parser.add_argument(
+'-use-check-next',
+dest='check_next',
+default=False,
+action='store_true',
+help='Whether or not to use CHECK-NEXT in the resulting tests.')
 args = parser.parse_args()
 
 flags = ' '.join(args.flags)
@@ -188,7 +204,8 @@
 if len(usr) < 2:
 continue
 all_output += get_output(root, out_file, out_dir, args.flags,
- num_outputs, args.bcanalyzer)
+ num_outputs, args.bcanalyzer, 
+ args.check_next)
 num_outputs += 1
 
 # Add test case code to test
Index: clang-doc/CMakeLists.txt
===
--- clang-doc/CMakeLists.txt
+++ clang-doc/CMakeLists.txt
@@ -10,6 +10,7 @@
   ClangDoc.cpp
   Generators.cpp
   Mapper.cpp
+  MDGenerator.cpp
   Representation.cpp
   Serialize.cpp
   YAMLGenerator.cpp
Index: clang-doc/tool/ClangDocMain.cpp
===
--- clang-doc/tool/ClangDocMain.cpp
+++ clang-doc/tool/ClangDocMain.cpp
@@ -34,6 +34,7 @@
 #include "clang/Tooling/StandaloneExecution.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -69,13 +70,18 @@
llvm::cl::init(false), 

[clang-tools-extra] r339948 - Implement a (simple) Markdown generator

2018-08-16 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Thu Aug 16 14:54:34 2018
New Revision: 339948

URL: http://llvm.org/viewvc/llvm-project?rev=339948=rev
Log:
Implement a (simple) Markdown generator

Implementing a simple Markdown generator from the emitted bitcode
summary of declarations. Very primitive at this point, but will be
expanded. Currently emits an .md file for each class and namespace,
listing its contents.

For a more detailed overview of the tool, see the design document
on the mailing list:
http://lists.llvm.org/pipermail/cfe-dev/2017-December/056203.html

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

Added:
clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp
clang-tools-extra/trunk/test/clang-doc/md-module.cpp
clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/md-record.cpp
Modified:
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/Generators.cpp
clang-tools-extra/trunk/clang-doc/Generators.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
clang-tools-extra/trunk/clang-doc/gen_tests.py
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp

Modified: clang-tools-extra/trunk/clang-doc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/CMakeLists.txt?rev=339948=339947=339948=diff
==
--- clang-tools-extra/trunk/clang-doc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-doc/CMakeLists.txt Thu Aug 16 14:54:34 2018
@@ -10,6 +10,7 @@ add_clang_library(clangDoc
   ClangDoc.cpp
   Generators.cpp
   Mapper.cpp
+  MDGenerator.cpp
   Representation.cpp
   Serialize.cpp
   YAMLGenerator.cpp

Modified: clang-tools-extra/trunk/clang-doc/Generators.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.cpp?rev=339948=339947=339948=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.cpp Thu Aug 16 14:54:34 2018
@@ -29,8 +29,11 @@ findGeneratorByName(llvm::StringRef Form
 // This anchor is used to force the linker to link in the generated object file
 // and thus register the generators.
 extern volatile int YAMLGeneratorAnchorSource;
+extern volatile int MDGeneratorAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED YAMLGeneratorAnchorDest =
 YAMLGeneratorAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MDGeneratorAnchorDest =
+MDGeneratorAnchorSource;
 
 } // namespace doc
 } // namespace clang

Modified: clang-tools-extra/trunk/clang-doc/Generators.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.h?rev=339948=339947=339948=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.h (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.h Thu Aug 16 14:54:34 2018
@@ -27,7 +27,7 @@ public:
   virtual ~Generator() = default;
 
   // Write out the decl info in the specified format.
-  virtual bool generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
+  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
 };
 
 typedef llvm::Registry GeneratorRegistry;

Added: clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/MDGenerator.cpp?rev=339948=auto
==
--- clang-tools-extra/trunk/clang-doc/MDGenerator.cpp (added)
+++ clang-tools-extra/trunk/clang-doc/MDGenerator.cpp Thu Aug 16 14:54:34 2018
@@ -0,0 +1,314 @@
+//===-- MDGenerator.cpp - Markdown Generator *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Generators.h"
+#include "Representation.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include 
+
+using namespace llvm;
+
+namespace clang {
+namespace doc {
+
+// Enum conversion
+
+std::string getAccess(AccessSpecifier AS) {
+  switch (AS) {
+  case AccessSpecifier::AS_public:
+return "public";
+  case AccessSpecifier::AS_protected:
+return "protected";
+  case AccessSpecifier::AS_private:
+return "private";
+  case AccessSpecifier::AS_none:
+return {};
+  }
+}
+
+std::string getTagType(TagTypeKind AS) {
+  switch (AS) {
+  case TagTypeKind::TTK_Class:
+return "class";
+  case TagTypeKind::TTK_Union:
+

[PATCH] D32902: [Analyzer] Iterator Checker - Part 7: Support for push and pop operations

2018-08-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.
Herald added subscribers: Szelethus, mikhail.ramalho.



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:1477-1530
+bool isPushBackCall(const FunctionDecl *Func) {
+  const auto *IdInfo = Func->getIdentifier();
+  if (!IdInfo)
+return false;
+  if (Func->getNumParams() != 1)
+return false;
+  return IdInfo->getName() == "push_back";

I guess we should think if we want to use `CallDescription` for these when 
D48027 lands.


https://reviews.llvm.org/D32902



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


[PATCH] D50640: Fix for bug 38508 - Don't do PCH processing when only generating preprocessor output

2018-08-16 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

In https://reviews.llvm.org/D50640#1201216, @thakis wrote:

> How does the gcc driver codepath handle this?


Interestingly I'd say.  So the gcc PCH model uses -include pch.h to use a PCH.  
In the driver, -include pch.h is handled by locating a matching pch file (say 
pch.h.gch) and if found adds -include_pch pch.h.gch instead of -include pch.h.  
This occurs even when only preprocessing (-E).  When preprocessing the compiler 
then handles the -include_pch option by opening pch.h.gch, finding the original 
file that created it (pch.h) and doing what -include pch.h does.   Seems like 
it would be better handled by the driver but maybe there is a reason for it.

When we only allowed PCH with a single /FI the model was the same as gcc and it 
worked similarly.  Since the through header/MS model allows creation of a PCH 
from any tokens not just a single #include, we can't handle it this way anymore.


https://reviews.llvm.org/D50640



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


[PATCH] D50640: Fix for bug 38508 - Don't do PCH processing when only generating preprocessor output

2018-08-16 Thread Mike Rice via Phabricator via cfe-commits
mikerice updated this revision to Diff 161116.
mikerice marked an inline comment as done.
mikerice added a comment.

Added a -verify test to ensure no warnings on successful PCH use.


https://reviews.llvm.org/D50640

Files:
  lib/Driver/Driver.cpp
  test/Driver/cl-pch.cpp
  test/PCH/Inputs/pch-through-use3c.cpp
  test/PCH/Inputs/pch-through3c.h
  test/PCH/pch-through3c.cpp


Index: test/PCH/pch-through3c.cpp
===
--- /dev/null
+++ test/PCH/pch-through3c.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h -o %t.3c %s
+
+// RUN: %clang_cc1 -verify -I %S -include-pch %t.3c \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h \
+// RUN:   %S/Inputs/pch-through-use3c.cpp 2>&1
Index: test/PCH/Inputs/pch-through3c.h
===
--- /dev/null
+++ test/PCH/Inputs/pch-through3c.h
@@ -0,0 +1 @@
+#define A 1
Index: test/PCH/Inputs/pch-through-use3c.cpp
===
--- /dev/null
+++ test/PCH/Inputs/pch-through-use3c.cpp
@@ -0,0 +1,2 @@
+int a = A;
+// expected-no-diagnostics
Index: test/Driver/cl-pch.cpp
===
--- test/Driver/cl-pch.cpp
+++ test/Driver/cl-pch.cpp
@@ -345,3 +345,24 @@
 // CHECK-NoSourceTP: pchfile.pch
 // CHECK-NoSourceTP: -x
 // CHECK-NoSourceTP: "c++"
+
+// If only preprocessing, PCH options are ignored.
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-P %s
+// CHECK-YC-P-NOT: -emit-pch
+// CHECK-YC-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-E %s
+// CHECK-YC-E-NOT: -emit-pch
+// CHECK-YC-E-NOT: -include-pch
+
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YU-P %s
+// CHECK-YU-P-NOT: -emit-pch
+// CHECK-YU-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YU-E %s
+// CHECK-YU-E-NOT: -emit-pch
+// CHECK-YU-E-NOT: -include-pch
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2998,9 +2998,10 @@
 Args.eraseArg(options::OPT__SLASH_Yc);
 YcArg = nullptr;
   }
-  if (Args.hasArg(options::OPT__SLASH_Y_)) {
-// /Y- disables all pch handling.  Rather than check for it everywhere,
-// just remove clang-cl pch-related flags here.
+  if (FinalPhase == phases::Preprocess || Args.hasArg(options::OPT__SLASH_Y_)) 
{
+// If only preprocessing or /Y- is used, all pch handling is disabled.
+// Rather than check for it everywhere, just remove clang-cl pch-related
+// flags here.
 Args.eraseArg(options::OPT__SLASH_Fp);
 Args.eraseArg(options::OPT__SLASH_Yc);
 Args.eraseArg(options::OPT__SLASH_Yu);


Index: test/PCH/pch-through3c.cpp
===
--- /dev/null
+++ test/PCH/pch-through3c.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h -o %t.3c %s
+
+// RUN: %clang_cc1 -verify -I %S -include-pch %t.3c \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h \
+// RUN:   %S/Inputs/pch-through-use3c.cpp 2>&1
Index: test/PCH/Inputs/pch-through3c.h
===
--- /dev/null
+++ test/PCH/Inputs/pch-through3c.h
@@ -0,0 +1 @@
+#define A 1
Index: test/PCH/Inputs/pch-through-use3c.cpp
===
--- /dev/null
+++ test/PCH/Inputs/pch-through-use3c.cpp
@@ -0,0 +1,2 @@
+int a = A;
+// expected-no-diagnostics
Index: test/Driver/cl-pch.cpp
===
--- test/Driver/cl-pch.cpp
+++ test/Driver/cl-pch.cpp
@@ -345,3 +345,24 @@
 // CHECK-NoSourceTP: pchfile.pch
 // CHECK-NoSourceTP: -x
 // CHECK-NoSourceTP: "c++"
+
+// If only preprocessing, PCH options are ignored.
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-P %s
+// CHECK-YC-P-NOT: -emit-pch
+// CHECK-YC-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-E %s
+// CHECK-YC-E-NOT: -emit-pch
+// CHECK-YC-E-NOT: -include-pch
+
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YU-P %s
+// CHECK-YU-P-NOT: -emit-pch
+// CHECK-YU-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h 

[PATCH] D50866: [analyzer] CFRetainReleaseChecker: Avoid checking C++ methods with the same name.

2018-08-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, george.karpenkov.
Herald added subscribers: cfe-commits, Szelethus, mikhail.ramalho, a.sidorin, 
szepet, baloghadamsoftware, xazax.hun.

CFRetainReleaseChecker is a tiny checker that verifies that arguments of 
CoreFoundation retain/release functions are non-null. The checker accidentally 
checks all functions with the respective name, not just the actual `CFRetain` 
etc, which has caused a crash.

Fix it and modernize the checker to use CallEvent/CallDescription APIs to avoid 
further mistakes.

rdar://problem/42433152


Repository:
  rC Clang

https://reviews.llvm.org/D50866

Files:
  lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  test/Analysis/retain-release.mm

Index: test/Analysis/retain-release.mm
===
--- test/Analysis/retain-release.mm
+++ test/Analysis/retain-release.mm
@@ -470,3 +470,18 @@
 void rdar33832412() {
   void* x = IOBSDNameMatching(); // no-warning
 }
+
+
+namespace member_CFRetains {
+class Foo {
+public:
+  void CFRetain(const Foo &) {}
+  void CFRetain(int) {}
+};
+
+void bar() {
+  Foo foo;
+  foo.CFRetain(foo); // no-warning
+  foo.CFRetain(0); // no-warning
+}
+}
Index: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
===
--- lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -36,6 +36,7 @@
 
 using namespace clang;
 using namespace ento;
+using namespace llvm;
 
 namespace {
 class APIMisuse : public BugType {
@@ -531,93 +532,59 @@
 //===--===//
 
 namespace {
-class CFRetainReleaseChecker : public Checker< check::PreStmt > {
-  mutable std::unique_ptr BT;
-  mutable IdentifierInfo *Retain, *Release, *MakeCollectable, *Autorelease;
+class CFRetainReleaseChecker : public Checker {
+  mutable APIMisuse BT{this, "null passed to CF memory management function"};
+  CallDescription CFRetain{"CFRetain", 1},
+  CFRelease{"CFRelease", 1},
+  CFMakeCollectable{"CFMakeCollectable", 1},
+  CFAutorelease{"CFAutorelease", 1};
 
 public:
-  CFRetainReleaseChecker()
-  : Retain(nullptr), Release(nullptr), MakeCollectable(nullptr),
-Autorelease(nullptr) {}
-  void checkPreStmt(const CallExpr *CE, CheckerContext ) const;
+  void checkPreCall(const CallEvent , CheckerContext ) const;
 };
 } // end anonymous namespace
 
-void CFRetainReleaseChecker::checkPreStmt(const CallExpr *CE,
+void CFRetainReleaseChecker::checkPreCall(const CallEvent ,
   CheckerContext ) const {
-  // If the CallExpr doesn't have exactly 1 argument just give up checking.
-  if (CE->getNumArgs() != 1)
+  // TODO: Make this check part of CallDescription.
+  if (!Call.isGlobalCFunction())
 return;
 
-  ProgramStateRef state = C.getState();
-  const FunctionDecl *FD = C.getCalleeDecl(CE);
-  if (!FD)
-return;
-
-  if (!BT) {
-ASTContext  = C.getASTContext();
-Retain = ("CFRetain");
-Release = ("CFRelease");
-MakeCollectable = ("CFMakeCollectable");
-Autorelease = ("CFAutorelease");
-BT.reset(new APIMisuse(
-this, "null passed to CF memory management function"));
-  }
-
   // Check if we called CFRetain/CFRelease/CFMakeCollectable/CFAutorelease.
-  const IdentifierInfo *FuncII = FD->getIdentifier();
-  if (!(FuncII == Retain || FuncII == Release || FuncII == MakeCollectable ||
-FuncII == Autorelease))
+  if (!(Call.isCalled(CFRetain) || Call.isCalled(CFRelease) ||
+Call.isCalled(CFMakeCollectable) || Call.isCalled(CFAutorelease)))
 return;
 
-  // FIXME: The rest of this just checks that the argument is non-null.
-  // It should probably be refactored and combined with NonNullParamChecker.
-
   // Get the argument's value.
-  const Expr *Arg = CE->getArg(0);
-  SVal ArgVal = C.getSVal(Arg);
+  SVal ArgVal = Call.getArgSVal(0);
   Optional DefArgVal = ArgVal.getAs();
   if (!DefArgVal)
 return;
 
-  // Get a NULL value.
-  SValBuilder  = C.getSValBuilder();
-  DefinedSVal zero =
-  svalBuilder.makeZeroVal(Arg->getType()).castAs();
-
-  // Make an expression asserting that they're equal.
-  DefinedOrUnknownSVal ArgIsNull = svalBuilder.evalEQ(state, zero, *DefArgVal);
-
-  // Are they equal?
-  ProgramStateRef stateTrue, stateFalse;
-  std::tie(stateTrue, stateFalse) = state->assume(ArgIsNull);
+  // Is it null?
+  ProgramStateRef state = C.getState();
+  ProgramStateRef stateNonNull, stateNull;
+  std::tie(stateNonNull, stateNull) = state->assume(*DefArgVal);
 
-  if (stateTrue && !stateFalse) {
-ExplodedNode *N = C.generateErrorNode(stateTrue);
+  if (!stateNonNull) {
+ExplodedNode *N = C.generateErrorNode(stateNull);
 if (!N)
   return;
 
-const char *description;
-if (FuncII == Retain)
-  

[PATCH] D50815: Establish the header

2018-08-16 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists closed this revision.
mclow.lists added a comment.

landed as revision 339943


https://reviews.llvm.org/D50815



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


[libcxx] r339943 - Establish the header. NFC yet. Reviewed as https://reviews.llvm.org/D50815

2018-08-16 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Aug 16 14:35:38 2018
New Revision: 339943

URL: http://llvm.org/viewvc/llvm-project?rev=339943=rev
Log:
Establish the  header. NFC yet. Reviewed as https://reviews.llvm.org/D50815

Added:
libcxx/trunk/include/bit
Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/include/module.modulemap
libcxx/trunk/test/libcxx/double_include.sh.cpp

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=339943=339942=339943=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Thu Aug 16 14:35:38 2018
@@ -645,13 +645,7 @@ template 
 #include 
 #include 
-
-#if defined(__IBMCPP__)
-#include "support/ibm/support.h"
-#endif
-#if defined(_LIBCPP_COMPILER_MSVC)
-#include 
-#endif
+#include 
 
 #include <__debug>
 
@@ -788,135 +782,6 @@ struct __debug_less
 
 #endif  // _LIBCPP_DEBUG
 
-// Precondition:  __x != 0
-inline _LIBCPP_INLINE_VISIBILITY
-unsigned __ctz(unsigned __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_ctz(__x));
-#else
-  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
-  static_assert(sizeof(unsigned long) == 4, "");
-  unsigned long where;
-  // Search from LSB to MSB for first set bit.
-  // Returns zero if no set bit is found.
-  if (_BitScanForward(, __x))
-return where;
-  return 32;
-#endif
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-unsigned long __ctz(unsigned long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_ctzl(__x));
-#else
-static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
-return __ctz(static_cast(__x));
-#endif
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-unsigned long long __ctz(unsigned long long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_ctzll(__x));
-#else
-unsigned long where;
-// Search from LSB to MSB for first set bit.
-// Returns zero if no set bit is found.
-#if defined(_LIBCPP_HAS_BITSCAN64)
-(defined(_M_AMD64) || defined(__x86_64__))
-  if (_BitScanForward64(, __x))
-return static_cast(where);
-#else
-  // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
-  // Scan the Low Word.
-  if (_BitScanForward(, static_cast(__x)))
-return where;
-  // Scan the High Word.
-  if (_BitScanForward(, static_cast(__x >> 32)))
-return where + 32; // Create a bit offset from the LSB.
-#endif
-  return 64;
-#endif // _LIBCPP_COMPILER_MSVC
-}
-
-// Precondition:  __x != 0
-inline _LIBCPP_INLINE_VISIBILITY
-unsigned __clz(unsigned __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_clz(__x));
-#else
-  static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
-  static_assert(sizeof(unsigned long) == 4, "");
-  unsigned long where;
-  // Search from LSB to MSB for first set bit.
-  // Returns zero if no set bit is found.
-  if (_BitScanReverse(, __x))
-return 31 - where;
-  return 32; // Undefined Behavior.
-#endif
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-unsigned long __clz(unsigned long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_clzl (__x));
-#else
-static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
-return __clz(static_cast(__x));
-#endif
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-unsigned long long __clz(unsigned long long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-return static_cast(__builtin_clzll(__x));
-#else
-  unsigned long where;
-// BitScanReverse scans from MSB to LSB for first set bit.
-// Returns 0 if no set bit is found.
-#if defined(_LIBCPP_HAS_BITSCAN64)
-  if (_BitScanReverse64(, __x))
-return static_cast(63 - where);
-#else
-  // Scan the high 32 bits.
-  if (_BitScanReverse(, static_cast(__x >> 32)))
-return 63 - (where + 32); // Create a bit offset from the MSB.
-  // Scan the low 32 bits.
-  if (_BitScanReverse(, static_cast(__x)))
-return 63 - where;
-#endif
-  return 64; // Undefined Behavior.
-#endif // _LIBCPP_COMPILER_MSVC
-}
-
-inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-  return __builtin_popcount  (__x);
-#else
-  static_assert(sizeof(unsigned) == 4, "");
-  return __popcnt(__x);
-#endif
-}
-
-inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-  return __builtin_popcountl (__x);
-#else
-  static_assert(sizeof(unsigned long) == 4, "");
-  return __popcnt(__x);
-#endif
-}
-
-inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {
-#ifndef _LIBCPP_COMPILER_MSVC
-  return __builtin_popcountll(__x);
-#else
-  static_assert(sizeof(unsigned long long) == 8, "");
-  return __popcnt64(__x);
-#endif
-}
-
 // all_of
 
 template 

Added: libcxx/trunk/include/bit
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/bit?rev=339943=auto

[PATCH] D50619: [clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer

2018-08-16 Thread Shuai Wang via Phabricator via cfe-commits
shuaiwang added a comment.

In https://reviews.llvm.org/D50619#1202135, @JonasToth wrote:

> @shuaiwang i tried to apply this and check the clang-tidy part again, but it 
> does not compile (log attached).
>  I update clang to master, did you add a matcher or something like this?
>
> F6950472: error.log 


Oops, my bad, this depends on https://reviews.llvm.org/D50617


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50619



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


r339941 - Update for LLVM API change

2018-08-16 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Thu Aug 16 14:30:24 2018
New Revision: 339941

URL: http://llvm.org/viewvc/llvm-project?rev=339941=rev
Log:
Update for LLVM API change

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=339941=339940=339941=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Aug 16 14:30:24 2018
@@ -579,7 +579,8 @@ void CGDebugInfo::CreateCompileUnit() {
   CGOpts.DwarfDebugFlags, RuntimeVers,
   CGOpts.EnableSplitDwarf ? "" : CGOpts.SplitDwarfFile, EmissionKind,
   0 /* DWOid */, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
-  CGOpts.GnuPubnames);
+  CGOpts.GnuPubnames ? llvm::DICompileUnit::DebugNameTableKind::GNU
+ : llvm::DICompileUnit::DebugNameTableKind::Default);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {


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


[PATCH] D50862: [clang-tidy] Abseil: faster strsplit delimiter check

2018-08-16 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:24
+
+ast_matchers::internal::Matcher
+constructExprWithArg(llvm::StringRef ClassName,

you dont need the `ast_matchers` namespace as there is a `using namespace 
ast_matchers` at the top, same at other places.



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:49
+  // in the character literal.
+  if (Result == R"("'")") {
+return std::string(R"('\'')");

The comment suggest, that all single quotes need to be escaped and then further 
processing happens, but you check on identity to `'` and return the escaped 
version of it. 
That confuses me.



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:54
+  // Now replace the " with '.
+  auto Pos = Result.find_first_of('"');
+  if (Pos == Result.npos)

This expects at max 2 `"` characters. couldnt there be more?



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:71
+
+  // One character string literal.
+  const auto SingleChar =

Please make the comments full sentences



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:75
+
+  // string_view passed by value and contructed from string literal.
+  auto StringViewArg =

What about the `std::string_view`?



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:108
+
+  auto Replacement = makeCharacterLiteral(Literal);
+  if (!Replacement)

Please dont use auto here



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:118
+  diag(Literal->getBeginLoc(),
+   "absl::StrSplit()/ByAnyChar()/MaxSplits() called with a string literal "
+   "consisting of a single character; consider using the more efficient "

You can configure this diagnostic with `%select{option1|option2}`.

See 
https://clang.llvm.org/docs/InternalsManual.html#formatting-a-diagnostic-argument
or `bugprone/ForwardingReferenceOverloadCheck.cpp` line 133 as an example 
(there are of course other places that technique is used)



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp:119
+   "absl::StrSplit()/ByAnyChar()/MaxSplits() called with a string literal "
+   "consisting of a single character; consider using the more efficient "
+   "overload accepting a character")

This diagnostic is really long, maybe you can shorten it a bit?

E.g. `consider using character overload` for the second part
and `.. called with single character string literal;`

My diagnostics are usually not so good, maybe you come up with something better 
:)



Comment at: clang-tidy/abseil/FasterStrsplitDelimiterCheck.h:20
+/// Finds instances of absl::StrSplit() or absl::MaxSplits() where the 
delimiter
+/// is a single character string literal and replaces with a character.
+///

s/replaces with/replaces it with/



Comment at: docs/ReleaseNotes.rst:63
+
+  Finds instances of absl::StrSplit() or absl::MaxSplits() where the delimiter
+  is a single character string literal and replaces with a character.

Please highlight code with two `



Comment at: docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst:8
+where the delimiter is a single character string literal. The check will offer
+a suggestion to change the string literal into a character. It will also catch
+when code uses ``absl::ByAnyChar()`` for just a single character and will

I think:
It will also catch code using ...

sounds a little better



Comment at: test/clang-tidy/abseil-faster-strsplit-delimiter.cpp:42
+void SplitDelimiters() {
+  absl::StrSplit("ABC", "A");
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: 
absl::StrSplit()/ByAnyChar()/MaxSplits() called with a string literal 
consisting of a single character; consider using the more efficient overload 
accepting a character [abseil-faster-strsplit-delimiter]

Please add a test, where `"A"` is used as an arbitray function argument 
(similar to the template case, but without templates involved)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50862



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


[PATCH] D50740: [SourceManager] isPointWithin: avoid using isBeforeInTranslationUnit, compare buffer offsets directly for lexical correctness

2018-08-16 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

In https://reviews.llvm.org/D50740#1202248, @jkorous wrote:

> Hi Alex, nice work!
>
> I am just wondering if it would be beneficial to assert Loc and End are in 
> the same file. It might help to catch bugs.


I don't see the value in that unless I'm misunderstanding something. We already 
check if Loc and End are in the same file, and return false if they're not.

> I also stumbled upon this function but not sure it makes things significantly 
> cleaner here:
>  https://clang.llvm.org/doxygen/SourceLocation_8h_source.html#l00175
> 
> LGTM otherwise.


Repository:
  rC Clang

https://reviews.llvm.org/D50740



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D50845#1203031, @gtbercea wrote:

> In https://reviews.llvm.org/D50845#1202991, @hfinkel wrote:
>
> > In https://reviews.llvm.org/D50845#1202965, @Hahnfeld wrote:
> >
> > > In https://reviews.llvm.org/D50845#1202963, @hfinkel wrote:
> > >
> > > > As a result, we should really have a separate header that has those 
> > > > actually-available functions. When targeting NVPTX, why don't we have 
> > > > the included math.h be CUDA's math.h? In the end, those are the 
> > > > functions we need to call when we generate code. Right?
> > >
> > >
> > > That's what https://reviews.llvm.org/D47849 deals with.
> >
> >
> > Yes, but it doesn't get CUDA's math.h. Maybe I misunderstand how this works 
> > (and I very well might, because it's not clear that CUDA has a math.h by 
> > that name), but that patch tries to avoid problems with the host's math.h 
> > and then also injects __clang_cuda_device_functions.h into the device 
> > compilation. How does this compare to when you include math.h in Clang's 
> > CUDA mode? It seems to be that we want to somehow map standard includes, 
> > where applicable, to include files in CUDA's include/crt directory (e.g., 
> > crt/math_functions.h and crt/common_functions.h for stdio.h for printf), 
> > and nothing else ends up being available (because it is, in fact, not 
> > available).
>
>
> There's no CUDA specific math.h unless you want to regard 
> clang_cuda_device_functions.h as a math header.


True. We rely on CUDA SDK which defines a subset of standard libc/libm 
functions with `__device__` attribute.

__clang_cuda_device_functions.h just provides a set of substitutes that became 
nvcc's builtins and are no longer implemented in CUDA headers.
It's not supposed to replace math.h and may change with next version of CUDA 
which may need to cope with some other quirk of CUDA's headers.

> The patch is using the same approach as CUDA and redirecting the function 
> calls to device specific function calls. The parts of that patch which deal 
> with host header compatibility would more naturally belong in a patch like 
> this one so ultimately they won't be part of that patch. I'm currently 
> working on improving the patch though by eliminating the 
> clang_cuda_device_functions.h injection and eliminating the need to disable 
> the built-ins.

This sounds great. When you do have device-side implementation of math library, 
it would probably worth considering to make CUDA use it, instead of the current 
hacks to adapt to CUDA headers. This would simplify things a bit and would give 
us much better control over the implementation.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50852: [clang-tidy] abseil-auto-make-unique

2018-08-16 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:21
+void AutoMakeUniqueCheck::registerMatchers(MatchFinder* finder) {
+  if (!getLangOpts().CPlusPlus) return;
+

Please clang-format, `return` on next line.



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:23
+
+  using clang::ast_matchers::isTemplateInstantiation;
+  auto is_instantiation = decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),

`clang::ast_matchers` is used already at line 14. No need to add this line.



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:27
+ functionDecl(isTemplateInstantiation(;
+  // There should be no additional expressions inbetween.
+  // E.g. this statement contains implicitCastExpr which makes it not eligible:

This sentence misses something. inbetween what?



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:34
+  has(ignoringParenImpCasts(callExpr(callee(functionDecl(
+  hasAnyName("absl::MakeUnique", "absl::make_unique",
+ "gtl::MakeUnique", "std::make_unique"),

The same rules apply for `make_shared`.

`make_pair` would be interesting as well, are there are standard `make_` 
templates?



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:51
+  var->getType()->getAsCXXRecordDecl());
+  if (!unique) return nullptr;
+  QualType type = unique->getTemplateArgs().get(0).getAsType();

Formatting and Naming conventions.

I think the following is more readable:

```
if (const auto* Unique = dyn_cast(var...)) {
  // stuff with var
}

return nullptr;
```



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:57
+const Type* GetMakeUniqueType(const FunctionDecl* make_unique_decl) {
+  const auto& template_arg =
+  
make_unique_decl->getTemplateSpecializationInfo()->TemplateArguments->get(

Naming conventions.



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:64
+void AutoMakeUniqueCheck::check(
+const ast_matchers::MatchFinder::MatchResult& result) {
+  const auto* var_decl = result.Nodes.getNodeAs("var_decl");

You don't need the `ast_matchers` namespace here.

Please follow the naming convention inside the function.



Comment at: clang-tidy/abseil/AutoMakeUniqueCheck.cpp:69
+  if (var_decl->isOutOfLine()) {
+// "auto Struct::field = make_unique<...>();" doesn't work in GCC.
+return;

What exactly is the issue here in GCC? Please make this comment more 
explanatory and maybe add a `FIXME` to work around the issue (depending on the 
nature of the issue)



Comment at: docs/ReleaseNotes.rst:63
+
+  FIXME: add release notes.
+

Please add release notes.



Comment at: docs/clang-tidy/checks/abseil-auto-make-unique.rst:11
+  std::unique_ptr x = MakeUnique(...);
+
+with

Please add documentation that the 'Abstract Factory' use case is resolved 
correctly.



Comment at: test/clang-tidy/abseil-auto-make-unique.cpp:34
+void Primitive() {
+  std::unique_ptr x = absl::make_unique();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'auto' to avoid repeating 
the type name

How does the code look with multiple variable declarations?

Please add a test for
```
std::unique_ptr x = absl::make_unique(), y = 
absl::make_unique(), z;
```



Comment at: test/clang-tidy/abseil-auto-make-unique.cpp:73
+  // Different type. No change.
+  std::unique_ptr z = make_unique();
+  std::unique_ptr z2(make_unique());

lets consider a 3 level class hierarchy.

```
struct A { virtual void Something(); };
struct B : A { void Something() override; };
struct C : B { void Something() override; };

std::unique_ptr b_ptr = make_unique(), c_ptr = make_unique();
std::unique_ptr c_ptr2 = make_unique(), b_ptr2 = make_unique();
```

What is the behaviour? I expect that these places break when transformed. To 
avoid you can check the `VarDecl` `isSingleDecl()` (or similar, i forgot the 
exact name) and only emit a fixit if it is.
Doing type transformations for the multi-definitions is tricky.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50852



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


[PATCH] D50852: [clang-tidy] abseil-auto-make-unique

2018-08-16 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In https://reviews.llvm.org/D50852#1202774, @lebedev.ri wrote:

> 1. Please always upload all patches with full context.
> 2. There already is `modernize-use-auto`. Does it handle this case? Then this 
> should be just an alias to that check. Else, i think it would be best to 
> extend that one, and still alias.


I checked fast and `modernize-use-auto` does not catch this case.

> Just checking, was there some memo i missed that abseil-related checks are 
> exempt from all the usual guidelines?

Because this check is really not abseil-library-specific.

I agree that this check is general for `make_...` templates. It should be 
either an addition to `modernize-use-auto` or `readability-` or so. What we do 
for such cases, where the check is generally useful and specific to a guideline 
at the same time is aliasing.

You can take a look at `hicpp-` module where most checks are actually aliases.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50852



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


[PATCH] D50862: [clang-tidy] Abseil: faster strsplit delimiter check

2018-08-16 Thread Deanna Garcia via Phabricator via cfe-commits
deannagarcia created this revision.
deannagarcia added reviewers: hokein, alexfh.
deannagarcia added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

This check is an abseil specific check that checks for code using single 
character string literals as delimiters and transforms the code into characters.


https://reviews.llvm.org/D50862

Files:
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/abseil/CMakeLists.txt
  clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
  clang-tidy/abseil/FasterStrsplitDelimiterCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/abseil-faster-strsplit-delimiter.cpp

Index: test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
===
--- test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
+++ test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
@@ -0,0 +1,95 @@
+// RUN: %check_clang_tidy %s abseil-faster-strsplit-delimiter %t
+
+namespace absl {
+
+class string_view {
+  public:
+string_view();
+string_view(const char *);
+};
+
+namespace strings_internal {
+struct Splitter {};
+struct MaxSplitsImpl {
+  MaxSplitsImpl();
+  ~MaxSplitsImpl();
+};
+} //namespace strings_internal
+
+template 
+strings_internal::Splitter StrSplit(absl::string_view, Delim) {
+  return {};
+}
+template 
+strings_internal::Splitter StrSplit(absl::string_view, Delim, Pred) {
+  return {};
+}
+
+class ByAnyChar {
+  public:
+explicit ByAnyChar(absl::string_view);
+~ByAnyChar();
+};
+
+template 
+strings_internal::MaxSplitsImpl MaxSplits(Delim, int) {
+  return {};
+}
+
+} //namespace absl
+
+void SplitDelimiters() {
+  absl::StrSplit("ABC", "A");
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()/ByAnyChar()/MaxSplits() called with a string literal consisting of a single character; consider using the more efficient overload accepting a character [abseil-faster-strsplit-delimiter]
+  // CHECK-FIXES: absl::StrSplit("ABC", 'A');
+
+  absl::StrSplit("ABC", absl::ByAnyChar("\n"));
+  // CHECK-MESSAGES: [[@LINE-1]]:41: warning: absl::StrSplit()/ByAnyChar()
+  // CHECK-FIXES: absl::StrSplit("ABC", '\n');
+
+  // Works with predicate
+  absl::StrSplit("ABC", "A", [](absl::string_view) { return true; });
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()/ByAnyChar()
+  // CHECK-FIXES: absl::StrSplit("ABC", 'A', [](absl::string_view) { return true; });
+
+  // Doesn't do anything with other strings lenghts.
+  absl::StrSplit("ABC", "AB");
+  absl::StrSplit("ABC", absl::ByAnyChar(""));
+  absl::StrSplit("ABC", absl::ByAnyChar(" \t"));
+
+  // Escapes a single quote in the resulting character literal.
+  absl::StrSplit("ABC", "'");
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()/ByAnyChar()
+  // CHECK-FIXES: absl::StrSplit("ABC", '\'');
+
+  absl::StrSplit("ABC", absl::MaxSplits("\t", 1));
+  // CHECK-MESSAGES: [[@LINE-1]]:41: warning: absl::StrSplit()/ByAnyChar()
+  // CHECK-FIXES: absl::StrSplit("ABC", absl::MaxSplits('\t', 1));
+
+  auto delim = absl::MaxSplits(absl::ByAnyChar(" "), 1);
+  // CHECK-MESSAGES: [[@LINE-1]]:48: warning: absl::StrSplit()/ByAnyChar()
+  // CHECK-FIXES: auto delim = absl::MaxSplits(' ', 1);
+}
+
+#define MACRO(str) absl::StrSplit("ABC", str)
+
+void Macro() {
+  MACRO("A");
+}
+
+template 
+void FunctionTemplate() {
+  // This one should not warn because ByAnyChar is a dependent type.
+  absl::StrSplit("TTT", T("A"));
+
+  // This one will warn, but we are checking that we get a correct warning only
+  // once.
+  absl::StrSplit("TTT", "A");
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()/ByAnyChar()
+  // CHECK-FIXES: absl::StrSplit("TTT", 'A');
+}
+
+void FunctionTemplateCaller() {
+  FunctionTemplate();
+  FunctionTemplate();
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -4,6 +4,7 @@
 =
 
 .. toctree::
+   abseil-faster-strsplit-delimiter
abseil-string-find-startswith
android-cloexec-accept
android-cloexec-accept4
Index: docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst
===
--- docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst
+++ docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - abseil-faster-strsplit-delimiter
+
+abseil-faster-strsplit-delimiter
+
+
+This check triggers on calls to ``absl::StrSplit()`` or ``absl::MaxSplits()``
+where the delimiter is a single character string literal. The check will offer
+a suggestion to change the string literal into a character. It will also catch
+when code uses ``absl::ByAnyChar()`` for just a single character and will
+transform that into a single 

r339934 - AMDGPU: Correct errors in device table

2018-08-16 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Thu Aug 16 13:19:47 2018
New Revision: 339934

URL: http://llvm.org/viewvc/llvm-project?rev=339934=rev
Log:
AMDGPU: Correct errors in device table

Modified:
cfe/trunk/lib/Basic/Targets/AMDGPU.h

Modified: cfe/trunk/lib/Basic/Targets/AMDGPU.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AMDGPU.h?rev=339934=339933=339934=diff
==
--- cfe/trunk/lib/Basic/Targets/AMDGPU.h (original)
+++ cfe/trunk/lib/Basic/Targets/AMDGPU.h Thu Aug 16 13:19:47 2018
@@ -125,7 +125,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTarg
 {{"sumo"},{"sumo"},GK_SUMO,false, false, false, false, false, 
false},
 {{"sumo2"},   {"sumo"},GK_SUMO,false, false, false, false, false, 
false},
 {{"barts"},   {"barts"},   GK_BARTS,   false, false, false, false, false, 
false},
-{{"caicos"},  {"caicos"},  GK_BARTS,   false, false, false, false, false, 
false},
+{{"caicos"},  {"caicos"},  GK_CAICOS,  false, false, false, false, false, 
false},
 {{"aruba"},   {"cayman"},  GK_CAYMAN,  true,  false, false, false, false, 
false},
 {{"cayman"},  {"cayman"},  GK_CAYMAN,  true,  false, false, false, false, 
false},
 {{"turks"},   {"turks"},   GK_TURKS,   false, false, false, false, false, 
false},
@@ -163,7 +163,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTarg
 {{"gfx810"},{"gfx810"},  GK_GFX810,  true, false, true,  true, true, 
true},
 {{"stoney"},{"gfx810"},  GK_GFX810,  true, false, true,  true, true, 
true},
 {{"gfx900"},{"gfx900"},  GK_GFX900,  true, true,  true,  true, true, 
true},
-{{"gfx902"},{"gfx902"},  GK_GFX900,  true, true,  true,  true, true, 
true},
+{{"gfx902"},{"gfx902"},  GK_GFX902,  true, true,  true,  true, true, 
true},
 {{"gfx904"},{"gfx904"},  GK_GFX904,  true, true,  true,  true, true, 
true},
 {{"gfx906"},{"gfx906"},  GK_GFX906,  true, true,  true,  true, true, 
true},
   };


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


[PATCH] D50843: AMDGPU: Correct errors in device table

2018-08-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

r339934


https://reviews.llvm.org/D50843



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


[PATCH] D50805: Don't warn on returning the address of a label from a statement expression

2018-08-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 161098.
rnk added a comment.

- fix it right


https://reviews.llvm.org/D50805

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/statements.c


Index: clang/test/Sema/statements.c
===
--- clang/test/Sema/statements.c
+++ clang/test/Sema/statements.c
@@ -34,6 +34,15 @@
   return &  // expected-warning {{returning address of label, which is 
local}}
 }
 
+// PR38569: Don't warn when returning a label from a statement expression.
+void test10_logpc(void*);
+void test10a() {
+  test10_logpc(({
+my_pc:
+  &_pc;
+  }));
+}
+
 // PR6034
 void test11(int bit) {
   switch (bit)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6924,7 +6924,8 @@
   } else if (isa(L)) {
 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
   } else if (isa(L)) {
-Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+if (LK == LK_Return)
+  Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
  << Entity.getType()->isReferenceType() << DiagRange;


Index: clang/test/Sema/statements.c
===
--- clang/test/Sema/statements.c
+++ clang/test/Sema/statements.c
@@ -34,6 +34,15 @@
   return &  // expected-warning {{returning address of label, which is local}}
 }
 
+// PR38569: Don't warn when returning a label from a statement expression.
+void test10_logpc(void*);
+void test10a() {
+  test10_logpc(({
+my_pc:
+  &_pc;
+  }));
+}
+
 // PR6034
 void test11(int bit) {
   switch (bit)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6924,7 +6924,8 @@
   } else if (isa(L)) {
 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
   } else if (isa(L)) {
-Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+if (LK == LK_Return)
+  Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
  << Entity.getType()->isReferenceType() << DiagRange;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48714: [clang-tidy] fix PR37913, templated exception factory diagnosed correctly

2018-08-16 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/hicpp-exception-baseclass.cpp:191
+void templated_thrower() { throw T{}(); }
+// CHECK-MESSAGES: [[@LINE-1]]:34: warning: throwing an exception whose type 
'int' is not derived from 'std::exception'
+

hokein wrote:
> JonasToth wrote:
> > JonasToth wrote:
> > > JonasToth wrote:
> > > > alexfh wrote:
> > > > > hokein wrote:
> > > > > > I think giving message on the template function here is confusing 
> > > > > > to users even it gets instantiated somewhere in this TU -- because 
> > > > > > users have to find the location that triggers the template 
> > > > > > instantiation.
> > > > > > 
> > > > > > Maybe 
> > > > > > 1) Add a note which gives the instantiation location to the 
> > > > > > message, or
> > > > > > 2) ignore template case (some clang-tidy checks do this)
> > > > > In this particular case it seems to be useful to get warnings from 
> > > > > template instantiations. But the message will indeed be confusing.
> > > > > 
> > > > > Ideally, the message should have "in instantiation of xxx requested 
> > > > > here" notes attached, as clang warnings do. But this is not working 
> > > > > automatically, and it's implemented in Sema 
> > > > > (`Sema::PrintInstantiationStack()` in 
> > > > > lib/Sema/SemaTemplateInstantiate.cpp).
> > > > > 
> > > > > I wonder whether it's feasible to produce similar notes after Sema is 
> > > > > dead? Maybe not the whole instantiation stack, but at least it should 
> > > > > be possible to figure out that the enclosing function is a template 
> > > > > instantiation or is a member function of an type that is an 
> > > > > instantiation of a template. That would be useful for other checks as 
> > > > > well.
> > > > It should be possible to figure out, that the type comes from template 
> > > > instantiation and that information could be added to the warning.
> > > > 
> > > > I will take a look at Sema and think about something like this. 
> > > > Unfortunatly i dont have a lot of time :/
> > > I did look further into the issue, i think it is non-trivial.
> > > 
> > > The newly added case is not a templated exception perse, but there is a 
> > > exception-factory, which is templated, that creates a normal exception.
> > > 
> > > I did add another note for template instantiations, but i could not 
> > > figure out a way to give better diagnostics for the new use-case.
> > @hokein and @alexfh Do you still have your concerns (the exception is not a 
> > template value, but the factory creating them) or is this fix acceptable?
> I agree this is non-trivial. If we can't find a good solution at the moment, 
> I'd prefer to ignore this case instead of adding some workarounds in the 
> check, what do you think? 
Honestly I would let it as is. This test case is not well readable, but if we 
have something similar to

```
template 
void SomeComplextFunction() {
T ExceptionFactory;

   if (SomeCondition) 
 throw ExceptionFactory();
}
```
It is not that bad. And the check is still correct, just the code triggering 
this condition just hides whats happening.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48714



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


[PATCH] D50805: [Sema] Don't warn on returning the address of a label

2018-08-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 161096.
rnk added a comment.

- keep the warning, suppress stmt expr case


https://reviews.llvm.org/D50805

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/statements.c


Index: clang/test/Sema/statements.c
===
--- clang/test/Sema/statements.c
+++ clang/test/Sema/statements.c
@@ -34,6 +34,15 @@
   return &  // expected-warning {{returning address of label, which is 
local}}
 }
 
+// PR38569: Don't warn when returning a label from a statement expression.
+void test10_logpc(void*);
+void test10a() {
+  test10_logpc(({
+my_pc:
+  &_pc;
+  }));
+}
+
 // PR6034
 void test11(int bit) {
   switch (bit)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6923,7 +6923,7 @@
 << isa(DRE->getDecl()) << DiagRange;
   } else if (isa(L)) {
 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
-  } else if (isa(L)) {
+  } else if (isa(L) && LK == LK_Return) {
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)


Index: clang/test/Sema/statements.c
===
--- clang/test/Sema/statements.c
+++ clang/test/Sema/statements.c
@@ -34,6 +34,15 @@
   return &  // expected-warning {{returning address of label, which is local}}
 }
 
+// PR38569: Don't warn when returning a label from a statement expression.
+void test10_logpc(void*);
+void test10a() {
+  test10_logpc(({
+my_pc:
+  &_pc;
+  }));
+}
+
 // PR6034
 void test11(int bit) {
   switch (bit)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6923,7 +6923,7 @@
 << isa(DRE->getDecl()) << DiagRange;
   } else if (isa(L)) {
 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
-  } else if (isa(L)) {
+  } else if (isa(L) && LK == LK_Return) {
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339933 - Update README and Dockerfile to include llvm-proto-fuzzer

2018-08-16 Thread Emmett Neyman via cfe-commits
Author: emmettneyman
Date: Thu Aug 16 13:13:40 2018
New Revision: 339933

URL: http://llvm.org/viewvc/llvm-project?rev=339933=rev
Log:
Update README and Dockerfile to include llvm-proto-fuzzer

Summary: Added commands to Dockerfile to build llvm-proto-fuzzer and the other 
related tools. Also added a section to the bottom of the README describing what 
llvm-proto-fuzzer does and how to run it.

Reviewers: morehouse, kcc

Reviewed By: morehouse

Subscribers: cfe-commits, llvm-commits

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

Modified:
cfe/trunk/tools/clang-fuzzer/Dockerfile
cfe/trunk/tools/clang-fuzzer/README.txt

Modified: cfe/trunk/tools/clang-fuzzer/Dockerfile
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/Dockerfile?rev=339933=339932=339933=diff
==
--- cfe/trunk/tools/clang-fuzzer/Dockerfile (original)
+++ cfe/trunk/tools/clang-fuzzer/Dockerfile Thu Aug 16 13:13:40 2018
@@ -35,3 +35,7 @@ RUN mkdir build1 && cd build1 && cmake -
 RUN cd build1 && ninja clang-fuzzer
 RUN cd build1 && ninja clang-proto-fuzzer
 RUN cd build1 && ninja clang-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-llvm
+RUN cd build1 && ninja clang-loop-proto-fuzzer
+RUN cd build1 && ninja clang-llvm-proto-fuzzer

Modified: cfe/trunk/tools/clang-fuzzer/README.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/README.txt?rev=339933=339932=339933=diff
==
--- cfe/trunk/tools/clang-fuzzer/README.txt (original)
+++ cfe/trunk/tools/clang-fuzzer/README.txt Thu Aug 16 13:13:40 2018
@@ -80,3 +80,37 @@ custom optimization level and target tri
 
 To translate a clang-proto-fuzzer corpus output to C++:
   bin/clang-proto-to-cxx CORPUS_OUTPUT_FILE
+
+===
+ llvm-proto-fuzzer
+===
+Like, clang-proto-fuzzer, llvm-proto-fuzzer is also a protobuf-mutator based
+fuzzer. It receives as input a cxx_loop_proto which it then converts into a
+string of valid LLVM IR: a function with either a single loop or two nested
+loops. It then creates a new string of IR by running optimization passes over
+the original IR. Currently, it only runs a loop-vectorize pass but more passes
+can easily be added to the fuzzer. Once there are two versions of the input
+function (optimized and not), llvm-proto-fuzzer uses LLVM's JIT Engine to
+compile both functions. Lastly, it runs both functions on a suite of inputs and
+checks that both functions behave the same on all inputs. In this way,
+llvm-proto-fuzzer can find not only compiler crashes, but also miscompiles
+originating from LLVM's optimization passes.
+
+llvm-proto-fuzzer is built very similarly to clang-proto-fuzzer. You can run 
the
+fuzzer with the following command:
+  bin/clang-llvm-proto-fuzzer CORPUS_DIR
+
+To translate a cxx_loop_proto file into LLVM IR do:
+  bin/clang-loop-proto-to-llvm CORPUS_OUTPUT_FILE
+To translate a cxx_loop_proto file into C++ do:
+  bin/clang-loop-proto-to-cxx CORPUS_OUTPUT_FILE
+
+Note: To get a higher number of executions per second with llvm-proto-fuzzer it
+helps to build it without ASan instrumentation and with the -O2 flag. Because
+the fuzzer is not only compiling code, but also running it, as the inputs get
+large, the time necessary to fuzz one input can get very high.
+Example:
+  cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
+-DCLANG_ENABLE_PROTO_FUZZER=ON -DLLVM_USE_SANITIZE_COVERAGE=YES \
+-DCMAKE_CXX_FLAGS="-O2"
+  ninja clang-llvm-proto-fuzzer clang-loop-proto-to-llvm


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


[PATCH] D50462: Try building complete AST after a fatal error was emitted if further diagnostics are expected

2018-08-16 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Have you checked that produced AST is of sufficient quality to be used? 
Because, for example, for invalid code error recovery tries to keep going but 
the end result isn't always good.

In the test you verify that you can ignore bogus includes. Is this the 
real-world use case you want to address? Or something like "stddef.h not found"?


Repository:
  rC Clang

https://reviews.llvm.org/D50462



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


[PATCH] D50829: Update README and Dockerfile to include llvm-proto-fuzzer

2018-08-16 Thread Emmett Neyman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339933: Update README and Dockerfile to include 
llvm-proto-fuzzer (authored by emmettneyman, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50829?vs=161093=161095#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50829

Files:
  cfe/trunk/tools/clang-fuzzer/Dockerfile
  cfe/trunk/tools/clang-fuzzer/README.txt


Index: cfe/trunk/tools/clang-fuzzer/README.txt
===
--- cfe/trunk/tools/clang-fuzzer/README.txt
+++ cfe/trunk/tools/clang-fuzzer/README.txt
@@ -80,3 +80,37 @@
 
 To translate a clang-proto-fuzzer corpus output to C++:
   bin/clang-proto-to-cxx CORPUS_OUTPUT_FILE
+
+===
+ llvm-proto-fuzzer
+===
+Like, clang-proto-fuzzer, llvm-proto-fuzzer is also a protobuf-mutator based
+fuzzer. It receives as input a cxx_loop_proto which it then converts into a
+string of valid LLVM IR: a function with either a single loop or two nested
+loops. It then creates a new string of IR by running optimization passes over
+the original IR. Currently, it only runs a loop-vectorize pass but more passes
+can easily be added to the fuzzer. Once there are two versions of the input
+function (optimized and not), llvm-proto-fuzzer uses LLVM's JIT Engine to
+compile both functions. Lastly, it runs both functions on a suite of inputs and
+checks that both functions behave the same on all inputs. In this way,
+llvm-proto-fuzzer can find not only compiler crashes, but also miscompiles
+originating from LLVM's optimization passes.
+
+llvm-proto-fuzzer is built very similarly to clang-proto-fuzzer. You can run 
the
+fuzzer with the following command:
+  bin/clang-llvm-proto-fuzzer CORPUS_DIR
+
+To translate a cxx_loop_proto file into LLVM IR do:
+  bin/clang-loop-proto-to-llvm CORPUS_OUTPUT_FILE
+To translate a cxx_loop_proto file into C++ do:
+  bin/clang-loop-proto-to-cxx CORPUS_OUTPUT_FILE
+
+Note: To get a higher number of executions per second with llvm-proto-fuzzer it
+helps to build it without ASan instrumentation and with the -O2 flag. Because
+the fuzzer is not only compiling code, but also running it, as the inputs get
+large, the time necessary to fuzz one input can get very high.
+Example:
+  cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
+-DCLANG_ENABLE_PROTO_FUZZER=ON -DLLVM_USE_SANITIZE_COVERAGE=YES \
+-DCMAKE_CXX_FLAGS="-O2"
+  ninja clang-llvm-proto-fuzzer clang-loop-proto-to-llvm
Index: cfe/trunk/tools/clang-fuzzer/Dockerfile
===
--- cfe/trunk/tools/clang-fuzzer/Dockerfile
+++ cfe/trunk/tools/clang-fuzzer/Dockerfile
@@ -35,3 +35,7 @@
 RUN cd build1 && ninja clang-fuzzer
 RUN cd build1 && ninja clang-proto-fuzzer
 RUN cd build1 && ninja clang-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-llvm
+RUN cd build1 && ninja clang-loop-proto-fuzzer
+RUN cd build1 && ninja clang-llvm-proto-fuzzer


Index: cfe/trunk/tools/clang-fuzzer/README.txt
===
--- cfe/trunk/tools/clang-fuzzer/README.txt
+++ cfe/trunk/tools/clang-fuzzer/README.txt
@@ -80,3 +80,37 @@
 
 To translate a clang-proto-fuzzer corpus output to C++:
   bin/clang-proto-to-cxx CORPUS_OUTPUT_FILE
+
+===
+ llvm-proto-fuzzer
+===
+Like, clang-proto-fuzzer, llvm-proto-fuzzer is also a protobuf-mutator based
+fuzzer. It receives as input a cxx_loop_proto which it then converts into a
+string of valid LLVM IR: a function with either a single loop or two nested
+loops. It then creates a new string of IR by running optimization passes over
+the original IR. Currently, it only runs a loop-vectorize pass but more passes
+can easily be added to the fuzzer. Once there are two versions of the input
+function (optimized and not), llvm-proto-fuzzer uses LLVM's JIT Engine to
+compile both functions. Lastly, it runs both functions on a suite of inputs and
+checks that both functions behave the same on all inputs. In this way,
+llvm-proto-fuzzer can find not only compiler crashes, but also miscompiles
+originating from LLVM's optimization passes.
+
+llvm-proto-fuzzer is built very similarly to clang-proto-fuzzer. You can run the
+fuzzer with the following command:
+  bin/clang-llvm-proto-fuzzer CORPUS_DIR
+
+To translate a cxx_loop_proto file into LLVM IR do:
+  bin/clang-loop-proto-to-llvm CORPUS_OUTPUT_FILE
+To translate a cxx_loop_proto file into C++ do:
+  bin/clang-loop-proto-to-cxx CORPUS_OUTPUT_FILE
+
+Note: To get a higher number of executions per second with llvm-proto-fuzzer it
+helps to build it without ASan instrumentation and with the -O2 flag. Because
+the fuzzer is not only compiling code, but also running it, as the inputs get
+large, the time necessary to fuzz one input can get very high.
+Example:
+  cmake 

[PATCH] D50829: Update README and Dockerfile to include llvm-proto-fuzzer

2018-08-16 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 161093.
emmettneyman added a comment.

Rebased and ready to land


Repository:
  rC Clang

https://reviews.llvm.org/D50829

Files:
  clang/tools/clang-fuzzer/Dockerfile
  clang/tools/clang-fuzzer/README.txt


Index: clang/tools/clang-fuzzer/README.txt
===
--- clang/tools/clang-fuzzer/README.txt
+++ clang/tools/clang-fuzzer/README.txt
@@ -80,3 +80,37 @@
 
 To translate a clang-proto-fuzzer corpus output to C++:
   bin/clang-proto-to-cxx CORPUS_OUTPUT_FILE
+
+===
+ llvm-proto-fuzzer
+===
+Like, clang-proto-fuzzer, llvm-proto-fuzzer is also a protobuf-mutator based
+fuzzer. It receives as input a cxx_loop_proto which it then converts into a
+string of valid LLVM IR: a function with either a single loop or two nested
+loops. It then creates a new string of IR by running optimization passes over
+the original IR. Currently, it only runs a loop-vectorize pass but more passes
+can easily be added to the fuzzer. Once there are two versions of the input
+function (optimized and not), llvm-proto-fuzzer uses LLVM's JIT Engine to
+compile both functions. Lastly, it runs both functions on a suite of inputs and
+checks that both functions behave the same on all inputs. In this way,
+llvm-proto-fuzzer can find not only compiler crashes, but also miscompiles
+originating from LLVM's optimization passes.
+
+llvm-proto-fuzzer is built very similarly to clang-proto-fuzzer. You can run 
the
+fuzzer with the following command:
+  bin/clang-llvm-proto-fuzzer CORPUS_DIR
+
+To translate a cxx_loop_proto file into LLVM IR do:
+  bin/clang-loop-proto-to-llvm CORPUS_OUTPUT_FILE
+To translate a cxx_loop_proto file into C++ do:
+  bin/clang-loop-proto-to-cxx CORPUS_OUTPUT_FILE
+
+Note: To get a higher number of executions per second with llvm-proto-fuzzer it
+helps to build it without ASan instrumentation and with the -O2 flag. Because
+the fuzzer is not only compiling code, but also running it, as the inputs get
+large, the time necessary to fuzz one input can get very high.
+Example:
+  cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
+-DCLANG_ENABLE_PROTO_FUZZER=ON -DLLVM_USE_SANITIZE_COVERAGE=YES \
+-DCMAKE_CXX_FLAGS="-O2"
+  ninja clang-llvm-proto-fuzzer clang-loop-proto-to-llvm
Index: clang/tools/clang-fuzzer/Dockerfile
===
--- clang/tools/clang-fuzzer/Dockerfile
+++ clang/tools/clang-fuzzer/Dockerfile
@@ -35,3 +35,7 @@
 RUN cd build1 && ninja clang-fuzzer
 RUN cd build1 && ninja clang-proto-fuzzer
 RUN cd build1 && ninja clang-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-llvm
+RUN cd build1 && ninja clang-loop-proto-fuzzer
+RUN cd build1 && ninja clang-llvm-proto-fuzzer


Index: clang/tools/clang-fuzzer/README.txt
===
--- clang/tools/clang-fuzzer/README.txt
+++ clang/tools/clang-fuzzer/README.txt
@@ -80,3 +80,37 @@
 
 To translate a clang-proto-fuzzer corpus output to C++:
   bin/clang-proto-to-cxx CORPUS_OUTPUT_FILE
+
+===
+ llvm-proto-fuzzer
+===
+Like, clang-proto-fuzzer, llvm-proto-fuzzer is also a protobuf-mutator based
+fuzzer. It receives as input a cxx_loop_proto which it then converts into a
+string of valid LLVM IR: a function with either a single loop or two nested
+loops. It then creates a new string of IR by running optimization passes over
+the original IR. Currently, it only runs a loop-vectorize pass but more passes
+can easily be added to the fuzzer. Once there are two versions of the input
+function (optimized and not), llvm-proto-fuzzer uses LLVM's JIT Engine to
+compile both functions. Lastly, it runs both functions on a suite of inputs and
+checks that both functions behave the same on all inputs. In this way,
+llvm-proto-fuzzer can find not only compiler crashes, but also miscompiles
+originating from LLVM's optimization passes.
+
+llvm-proto-fuzzer is built very similarly to clang-proto-fuzzer. You can run the
+fuzzer with the following command:
+  bin/clang-llvm-proto-fuzzer CORPUS_DIR
+
+To translate a cxx_loop_proto file into LLVM IR do:
+  bin/clang-loop-proto-to-llvm CORPUS_OUTPUT_FILE
+To translate a cxx_loop_proto file into C++ do:
+  bin/clang-loop-proto-to-cxx CORPUS_OUTPUT_FILE
+
+Note: To get a higher number of executions per second with llvm-proto-fuzzer it
+helps to build it without ASan instrumentation and with the -O2 flag. Because
+the fuzzer is not only compiling code, but also running it, as the inputs get
+large, the time necessary to fuzz one input can get very high.
+Example:
+  cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
+-DCLANG_ENABLE_PROTO_FUZZER=ON -DLLVM_USE_SANITIZE_COVERAGE=YES \
+-DCMAKE_CXX_FLAGS="-O2"
+  ninja clang-llvm-proto-fuzzer 

[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

In https://reviews.llvm.org/D50845#1202991, @hfinkel wrote:

> In https://reviews.llvm.org/D50845#1202965, @Hahnfeld wrote:
>
> > In https://reviews.llvm.org/D50845#1202963, @hfinkel wrote:
> >
> > > As a result, we should really have a separate header that has those 
> > > actually-available functions. When targeting NVPTX, why don't we have the 
> > > included math.h be CUDA's math.h? In the end, those are the functions we 
> > > need to call when we generate code. Right?
> >
> >
> > That's what https://reviews.llvm.org/D47849 deals with.
>
>
> Yes, but it doesn't get CUDA's math.h. Maybe I misunderstand how this works 
> (and I very well might, because it's not clear that CUDA has a math.h by that 
> name), but that patch tries to avoid problems with the host's math.h and then 
> also injects __clang_cuda_device_functions.h into the device compilation. How 
> does this compare to when you include math.h in Clang's CUDA mode? It seems 
> to be that we want to somehow map standard includes, where applicable, to 
> include files in CUDA's include/crt directory (e.g., crt/math_functions.h and 
> crt/common_functions.h for stdio.h for printf), and nothing else ends up 
> being available (because it is, in fact, not available).


There's no CUDA specific math.h unless you want to regard 
clang_cuda_device_functions.h as a math header. The patch is using the same 
approach as CUDA and redirecting the function calls to device specific function 
calls. The parts of that patch which deal with host header compatibility would 
more naturally belong in a patch like this one so ultimately they won't be part 
of that patch. I'm currently working on improving the patch though by 
eliminating the clang_cuda_device_functions.h injection and elimintating the 
need to disable the built-ins.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50805: [Sema] Don't warn on returning the address of a label

2018-08-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Sounds good. I think, in the meantime, we all agree we can stop emitting this 
warning in the statement expression case. I'll upload a patch for that.


Repository:
  rC Clang

https://reviews.llvm.org/D50805



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


[PATCH] D50843: AMDGPU: Correct errors in device table

2018-08-16 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl accepted this revision.
kzhuravl added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D50843



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


[PATCH] D50852: abseil-auto-make-unique

2018-08-16 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added reviewers: aaron.ballman, zinovy.nis.
lebedev.ri added a comment.

In https://reviews.llvm.org/D50852#1203009, @hugoeg wrote:

> In https://reviews.llvm.org/D50852#1202774, @lebedev.ri wrote:
>
> > 1. Please always upload all patches with full context.
> > 2. There already is `modernize-use-auto`. Does it handle this case? Then 
> > this should be just an alias to that check. Else, i think it would be best 
> > to extend that one, and still alias.
>
>
> since this check checks for absl::make_unique primarily 
>  if we move it to the general check, it'd be weird to check for 
> absl::make_unique


Why do you think it would be weird?
That list should/would be a user-configurable config option anyway.

> right now our main goal is to release checks tailored specifically to abseil 
> users, so if we can we would like to release this check separately in the 
> abseil directory

Just checking, was there some memo i missed that abseil-related checks are 
exempt from all the usual guidelines?
Because this check is really not abseil-library-specific.


https://reviews.llvm.org/D50852



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


[PATCH] D50852: abseil-auto-make-unique

2018-08-16 Thread Hugo Gonzalez via Phabricator via cfe-commits
hugoeg added a comment.

In https://reviews.llvm.org/D50852#1202774, @lebedev.ri wrote:

> 1. Please always upload all patches with full context.
> 2. There already is `modernize-use-auto`. Does it handle this case? Then this 
> should be just an alias to that check. Else, i think it would be best to 
> extend that one, and still alias.


since this check checks for absl::make_unique primarily 
if we move it to the general check, it'd be weird to check for absl::make_unique
right now our main goal is to release checks tailored specifically to abseil 
users, so if we can we would like to release this check separately in the 
abseil directory


https://reviews.llvm.org/D50852



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


[PATCH] D50805: [Sema] Don't warn on returning the address of a label

2018-08-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D50805#1201910, @rnk wrote:

> I think the state machine use case is real, though, something like:
>
>   void *f(void *startlabel) {
> common_work();
> goto *startlabel;
>   state1:
> return &
>   state2:
> return &
>   ...
>   }
>


Per GCC's documentation, this code is wrong, and `__attribute__((noinline, 
noclone))` must be used. However, GCC's behavior on that case is extremely 
interesting: https://godbolt.org/g/xesYK1

Note that it produces a warning about returning the address of a label, just 
like we do. But it also says that `f` cannot be inlined because it contains a 
computed goto. So perhaps the GCC documentation / spec for the feature is wrong.

> Suppressing it under noinline doesn't solve the original statement expression 
> issue

True, but it's straightforward to fix the regression for the statement 
expression case. I don't think that affects whether we go further than that and 
remove the warning for the `return` case.

> Are we really worried about users doing this?
> 
>   void *f() {
> return &
>   next:
> ...
>   }
>   void g() {
> void *pc = f();
> goto *pc; // cross-functional frame re-entry! =D
>   }

A little, yes. But I think this cross-function case alone would not justify an 
enabled-by-default warning with false-positives on the state machine case. So I 
think the question is, do we think the warnings on the state machine case are 
false positives or not? Some options I think are reasonable:

1. We explicitly document that our extension provides an additional guarantee 
on top of GCC's -- that the address of a label always denotes the same label 
for multiple invocations of the same function -- and remove this warning (or 
downgrade to `-Wgcc-compat`).
2. We keep merely inheriting the specification (such as it is) for the feature 
from GCC's documentation, and the warning is arguably valid because any code 
that triggers it is (almost certainly) wrong, even though we won't currently 
exploit the wrongness.

Or secret option 1b: we get the GCC folks to update their documentation to 
explicitly state that the presence of a computed goto in a function prevents 
inlining and cloning in all circumstances, and remove the warning.

I've filed gcc.gnu.org/PR86983 ; hopefully we'll 
get more clarification on what the semantics of this extension are supposed to 
be there.


Repository:
  rC Clang

https://reviews.llvm.org/D50805



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

In https://reviews.llvm.org/D50845#1202973, @ABataev wrote:

> >> If I understand it correctly, the root cause of this exercise is that we 
> >> want to compile for GPU using plain C. CUDA avoids this issue by 
> >> separating device and host code via target attributes and clang has few 
> >> special cases to ignore inline assembly errors in the host code if we're 
> >> compiling for device. For OpenMP there's no such separation, not in the 
> >> system headers, at least.
> > 
> > Yes, that's one of the nice properties of CUDA (for the compiler). There 
> > used to be the same restriction for OpenMP where all functions used in 
> > `target` regions needed to be put in `declare target`. However that was 
> > relaxed in favor of implicitly marking all **called** functions in that TU 
> > to be `declare target`.
> >  So ideally I think Clang should determine which functions are really 
> > `declare target` (either explicit or implicit) and only run semantical 
> > analysis on them. If a function is then found to be "broken" it's perfectly 
> > desirable to error back to the user.
>
> It is not possible for OpenMP because we support implicit declare target 
> functions. Clang cannot identify whether the function is going to be used on 
> the device or not during sema analysis.


Sounds like that is a recipe for just disabling sema analysis for all implicit 
declare target functions.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D50845#1202965, @Hahnfeld wrote:

> In https://reviews.llvm.org/D50845#1202963, @hfinkel wrote:
>
> > As a result, we should really have a separate header that has those 
> > actually-available functions. When targeting NVPTX, why don't we have the 
> > included math.h be CUDA's math.h? In the end, those are the functions we 
> > need to call when we generate code. Right?
>
>
> That's what https://reviews.llvm.org/D47849 deals with.


Yes, but it doesn't get CUDA's math.h. Maybe I misunderstand how this works 
(and I very well might, because it's not clear that CUDA has a math.h by that 
name), but that patch tries to avoid problems with the host's math.h and then 
also injects __clang_cuda_device_functions.h into the device compilation. How 
does this compare to when you include math.h in Clang's CUDA mode? It seems to 
be that we want to somehow map standard includes, where applicable, to include 
files in CUDA's include/crt directory (e.g., crt/math_functions.h and 
crt/common_functions.h for stdio.h for printf), and nothing else ends up being 
available (because it is, in fact, not available).


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50855: [analyzer] pr37578: Fix lvalue/rvalue problem in field-of-temporary adjustments.

2018-08-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

...and adding the aforementioned assertion for prvalues increases the  number 
of crashes on tests to 196. It seems that the analyzer assigns values of 
improper loc-less very often, but then immediately overwrites them :/ I wonder 
how much performance could be gained by fixing these bugs.


https://reviews.llvm.org/D50855



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

>> If I understand it correctly, the root cause of this exercise is that we 
>> want to compile for GPU using plain C. CUDA avoids this issue by separating 
>> device and host code via target attributes and clang has few special cases 
>> to ignore inline assembly errors in the host code if we're compiling for 
>> device. For OpenMP there's no such separation, not in the system headers, at 
>> least.
> 
> Yes, that's one of the nice properties of CUDA (for the compiler). There used 
> to be the same restriction for OpenMP where all functions used in `target` 
> regions needed to be put in `declare target`. However that was relaxed in 
> favor of implicitly marking all **called** functions in that TU to be 
> `declare target`.
>  So ideally I think Clang should determine which functions are really 
> `declare target` (either explicit or implicit) and only run semantical 
> analysis on them. If a function is then found to be "broken" it's perfectly 
> desirable to error back to the user.

It is not possible for OpenMP because we support implicit declare target 
functions. Clang cannot identify whether the function is going to be used on 
the device or not during sema analysis.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D50845#1202963, @hfinkel wrote:

> As a result, we should really have a separate header that has those 
> actually-available functions. When targeting NVPTX, why don't we have the 
> included math.h be CUDA's math.h? In the end, those are the functions we need 
> to call when we generate code. Right?


That's what https://reviews.llvm.org/D47849 deals with.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

> Another option would be to implement some sort of attribute-based 
> overloading. Then OpenMP can provide its own version of the device-side 
> library function without clashing with system headers.

I'm thinking about what the desired behavior is here. So, if we have a 
situation where the target is the host, then we really only have one set of 
headers and we want everything to work as it does today. math.h should be 
math.h, with the same relevant preprocessor context. When the host and target 
differ, then we have a restricted set of external/system device functions 
available on the device (which may or may not have anything to do with the set 
of system functions provided by the host's system headers). As a result, we 
should really have a separate header that has those actually-available 
functions. When targeting NVPTX, why don't we have the included math.h be 
CUDA's math.h? In the end, those are the functions we need to call when we 
generate code. Right?


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-08-16 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:331
+  SourceLocation Loc);
+
   /// Emit a conversion from the specified complex type to the specified

ebevhan wrote:
> What's the plan for the other conversions (int<->fix, float<->fix)? Functions 
> for those as well?
> 
> What about `EmitScalarConversion`? If it cannot handle conversions of 
> fixed-point values it should probably be made to assert, since it will likely 
> mess up.
Ideally, my plan was to have separate functions for each cast since it seems 
the logic for each of them is unique, other than saturation which may be 
abstracted to its own function and be used by the others.

I wasn't sure if I should also place the logic for these casts in 
`EmitScalarConversion` since `EmitScalarConversion` seemed pretty large enough 
and thought it was easier if we instead had separate, self contained functions 
for each fixed point conversion. But I'm open for hearing ideas on different 
ways on implementing them.

Will add the assertion.



Comment at: lib/CodeGen/CGExprScalar.cpp:1052
+} else if (IsSigned && !DstFPSema.isSigned()) {
+  Value *Zero =
+  ConstantInt::get(CGF.getLLVMContext(), APInt(ResultWidth, 0));

ebevhan wrote:
> `ConstantInt::getNullValue`?
I did not know about this method. Thanks!



Comment at: lib/Sema/Sema.cpp:537
+  case Type::STK_FixedPoint:
+llvm_unreachable("Unknown cast from FixedPoint to boolean");
   }

ebevhan wrote:
> Will we want to support this?
I imagine we would want `_Bool` conversions since logical negation works on 
fixed point types and more people would probably assume by default for it to 
also implicitly be converted to a boolean as opposed to not.

I also don't think implementing in a later patch this will be too hard.


Repository:
  rC Clang

https://reviews.llvm.org/D50616



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-16 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D50845#1202838, @tra wrote:

> In https://reviews.llvm.org/D50845#1202551, @ABataev wrote:
>
> > In https://reviews.llvm.org/D50845#1202550, @Hahnfeld wrote:
> >
> > > In https://reviews.llvm.org/D50845#1202540, @ABataev wrote:
> > >
> > > > Maybe for device compilation we also should define `__NO_MATH_INLINES` 
> > > > and `__NO_STRING_INLINES` macros to disable inline assembly in glibc?
> > >
> > >
> > > The problem is that `__NO_MATH_INLINES` doesn't even avoid all inline 
> > > assembly from `bits/mathinline.h` :-( incidentally Clang already defines 
> > > `__NO_MATH_INLINES` for x86 (due to an old bug which has been fixed long 
> > > ago) - and on CentOS we still have problems as described in PR38464.
> > >
> > > As a second thought: This might be valid for NVPTX, but I don't think 
> > > it's a good idea for x86-like offloading targets - they might well profit 
> > > from inline assembly code.
> >
> >
> > I'm not saying that we should define those macros for all targets, only for 
> > NVPTX. But still, it may disable some inline assembly for other 
> > architectures.
>
>
> IMO, trying to avoid inline assembly by defining(or not) some macros and 
> hoping for the best is rather fragile as we'll have to chase *all* patches 
> that host's math.h may have on any given system.


Completely agree here: This patch tries to pick the low-hanging fruits that 
happen to fix `include ` on most systems (and addressing a 
long-standing `FIXME` in the code). I know there are more headers that define 
inline assembly unconditionally and need more advanced fixes (see below).

> If I understand it correctly, the root cause of this exercise is that we want 
> to compile for GPU using plain C. CUDA avoids this issue by separating device 
> and host code via target attributes and clang has few special cases to ignore 
> inline assembly errors in the host code if we're compiling for device. For 
> OpenMP there's no such separation, not in the system headers, at least.

Yes, that's one of the nice properties of CUDA (for the compiler). There used 
to be the same restriction for OpenMP where all functions used in `target` 
regions needed to be put in `declare target`. However that was relaxed in favor 
of implicitly marking all **called** functions in that TU to be `declare 
target`.
So ideally I think Clang should determine which functions are really `declare 
target` (either explicit or implicit) and only run semantical analysis on them. 
If a function is then found to be "broken" it's perfectly desirable to error 
back to the user.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50855: [analyzer] pr37578: Fix lvalue/rvalue problem in field-of-temporary adjustments.

2018-08-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> which is of course a bad thing to do because we should not bind `Loc`s to 
> `prvalue` expressions

... of non-pointer type. On the other hand, binding `NonLoc`s to glvalue 
expressions is always a bad thing to do; but, for the reference, adding this as 
an assertion currently crashes 92 tests.


https://reviews.llvm.org/D50855



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


[PATCH] D50860: [libc++][test] Remove non-portable assumption that thread's constructor allocates with ::new

2018-08-16 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.
CaseyCarter added reviewers: mclow.lists, EricWF.

Drive-by:

- Fix potential race between check and update of `throw_one` in operator new
- Fix latent bug in operator delete, which shouldn't decrement 
`outstanding_new` when passed a null pointer
- Specifically catch the expected `bad_alloc` in `main` instead of `...`


https://reviews.llvm.org/D50860

Files:
  
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp


Index: 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -31,17 +31,19 @@
 
 void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
 {
-if (throw_one == 0)
-TEST_THROW(std::bad_alloc());
---throw_one;
+unsigned expected = throw_one;
+do {
+if (expected == 0) TEST_THROW(std::bad_alloc());
+} while (!throw_one.compare_exchange_weak(expected, expected - 1));
 ++outstanding_new;
 void* ret = std::malloc(s);
 if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
 return ret;
 }
 
 void  operator delete(void* p) TEST_NOEXCEPT
 {
+if (!p) return;
 --outstanding_new;
 std::free(p);
 }
@@ -116,14 +118,16 @@
 //2.3 Check that no memory allocated by the creation of the thread is 
leaked.
 //  3 Finally check that a thread runs successfully if we throw after 'N+1'
 //allocations.
+int numAllocs;
+
 void test_throwing_new_during_thread_creation() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 throw_one = 0xFFF;
 {
 std::thread t(f);
 t.join();
 }
-const int numAllocs = 0xFFF - throw_one;
+numAllocs = 0xFFF - throw_one;
 // i <= numAllocs means the last iteration is expected not to throw.
 for (int i=0; i <= numAllocs; ++i) {
 throw_one = i;
@@ -164,16 +168,16 @@
 }
 G::op_run = false;
 #ifndef TEST_HAS_NO_EXCEPTIONS
-{
+if (numAllocs > 0) {
 try
 {
 throw_one = 0;
 assert(G::n_alive == 0);
 assert(!G::op_run);
 std::thread t((G()));
 assert(false);
 }
-catch (...)
+catch (std::bad_alloc const&)
 {
 throw_one = 0x;
 assert(G::n_alive == 0);


Index: test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -31,17 +31,19 @@
 
 void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
 {
-if (throw_one == 0)
-TEST_THROW(std::bad_alloc());
---throw_one;
+unsigned expected = throw_one;
+do {
+if (expected == 0) TEST_THROW(std::bad_alloc());
+} while (!throw_one.compare_exchange_weak(expected, expected - 1));
 ++outstanding_new;
 void* ret = std::malloc(s);
 if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
 return ret;
 }
 
 void  operator delete(void* p) TEST_NOEXCEPT
 {
+if (!p) return;
 --outstanding_new;
 std::free(p);
 }
@@ -116,14 +118,16 @@
 //2.3 Check that no memory allocated by the creation of the thread is leaked.
 //  3 Finally check that a thread runs successfully if we throw after 'N+1'
 //allocations.
+int numAllocs;
+
 void test_throwing_new_during_thread_creation() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 throw_one = 0xFFF;
 {
 std::thread t(f);
 t.join();
 }
-const int numAllocs = 0xFFF - throw_one;
+numAllocs = 0xFFF - throw_one;
 // i <= numAllocs means the last iteration is expected not to throw.
 for (int i=0; i <= numAllocs; ++i) {
 throw_one = i;
@@ -164,16 +168,16 @@
 }
 G::op_run = false;
 #ifndef TEST_HAS_NO_EXCEPTIONS
-{
+if (numAllocs > 0) {
 try
 {
 throw_one = 0;
 assert(G::n_alive == 0);
 assert(!G::op_run);
 std::thread t((G()));
 assert(false);
 }
-catch (...)
+catch (std::bad_alloc const&)
 {
 throw_one = 0x;
 assert(G::n_alive == 0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50829: Update README and Dockerfile to include llvm-proto-fuzzer

2018-08-16 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 161080.
emmettneyman added a comment.

Added to README


Repository:
  rC Clang

https://reviews.llvm.org/D50829

Files:
  clang/tools/clang-fuzzer/Dockerfile
  clang/tools/clang-fuzzer/README.txt


Index: clang/tools/clang-fuzzer/README.txt
===
--- clang/tools/clang-fuzzer/README.txt
+++ clang/tools/clang-fuzzer/README.txt
@@ -80,3 +80,37 @@
 
 To translate a clang-proto-fuzzer corpus output to C++:
   bin/clang-proto-to-cxx CORPUS_OUTPUT_FILE
+
+===
+ llvm-proto-fuzzer
+===
+Like, clang-proto-fuzzer, llvm-proto-fuzzer is also a protobuf-mutator based
+fuzzer. It receives as input a cxx_loop_proto which it then converts into a
+string of valid LLVM IR: a function with either a single loop or two nested
+loops. It then creates a new string of IR by running optimization passes over
+the original IR. Currently, it only runs a loop-vectorize pass but more passes
+can easily be added to the fuzzer. Once there are two versions of the input
+function (optimized and not), llvm-proto-fuzzer uses LLVM's JIT Engine to
+compile both functions. Lastly, it runs both functions on a suite of inputs and
+checks that both functions behave the same on all inputs. In this way,
+llvm-proto-fuzzer can find not only compiler crashes, but also miscompiles
+originating from LLVM's optimization passes.
+
+llvm-proto-fuzzer is built very similarly to clang-proto-fuzzer. You can run 
the
+fuzzer with the following command:
+  bin/clang-llvm-proto-fuzzer CORPUS_DIR
+
+To translate a cxx_loop_proto file into LLVM IR do:
+  bin/clang-loop-proto-to-llvm CORPUS_OUTPUT_FILE
+To translate a cxx_loop_proto file into C++ do:
+  bin/clang-loop-proto-to-cxx CORPUS_OUTPUT_FILE
+
+Note: To get a higher number of executions per second with llvm-proto-fuzzer it
+helps to build it without ASan instrumentation and with the -O2 flag. Because
+the fuzzer is not only compiling code, but also running it, as the inputs get
+large, the time necessary to fuzz one input can get very high.
+Example:
+  cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
+-DCLANG_ENABLE_PROTO_FUZZER=ON -DLLVM_USE_SANITIZE_COVERAGE=YES \
+-DCMAKE_CXX_FLAGS="-O2"
+  ninja clang-llvm-proto-fuzzer clang-loop-proto-to-llvm
Index: clang/tools/clang-fuzzer/Dockerfile
===
--- clang/tools/clang-fuzzer/Dockerfile
+++ clang/tools/clang-fuzzer/Dockerfile
@@ -35,3 +35,7 @@
 RUN cd build1 && ninja clang-fuzzer
 RUN cd build1 && ninja clang-proto-fuzzer
 RUN cd build1 && ninja clang-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-cxx
+RUN cd build1 && ninja clang-loop-proto-to-llvm
+RUN cd build1 && ninja clang-loop-proto-fuzzer
+RUN cd build1 && ninja clang-llvm-proto-fuzzer


Index: clang/tools/clang-fuzzer/README.txt
===
--- clang/tools/clang-fuzzer/README.txt
+++ clang/tools/clang-fuzzer/README.txt
@@ -80,3 +80,37 @@
 
 To translate a clang-proto-fuzzer corpus output to C++:
   bin/clang-proto-to-cxx CORPUS_OUTPUT_FILE
+
+===
+ llvm-proto-fuzzer
+===
+Like, clang-proto-fuzzer, llvm-proto-fuzzer is also a protobuf-mutator based
+fuzzer. It receives as input a cxx_loop_proto which it then converts into a
+string of valid LLVM IR: a function with either a single loop or two nested
+loops. It then creates a new string of IR by running optimization passes over
+the original IR. Currently, it only runs a loop-vectorize pass but more passes
+can easily be added to the fuzzer. Once there are two versions of the input
+function (optimized and not), llvm-proto-fuzzer uses LLVM's JIT Engine to
+compile both functions. Lastly, it runs both functions on a suite of inputs and
+checks that both functions behave the same on all inputs. In this way,
+llvm-proto-fuzzer can find not only compiler crashes, but also miscompiles
+originating from LLVM's optimization passes.
+
+llvm-proto-fuzzer is built very similarly to clang-proto-fuzzer. You can run the
+fuzzer with the following command:
+  bin/clang-llvm-proto-fuzzer CORPUS_DIR
+
+To translate a cxx_loop_proto file into LLVM IR do:
+  bin/clang-loop-proto-to-llvm CORPUS_OUTPUT_FILE
+To translate a cxx_loop_proto file into C++ do:
+  bin/clang-loop-proto-to-cxx CORPUS_OUTPUT_FILE
+
+Note: To get a higher number of executions per second with llvm-proto-fuzzer it
+helps to build it without ASan instrumentation and with the -O2 flag. Because
+the fuzzer is not only compiling code, but also running it, as the inputs get
+large, the time necessary to fuzz one input can get very high.
+Example:
+  cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
+-DCLANG_ENABLE_PROTO_FUZZER=ON -DLLVM_USE_SANITIZE_COVERAGE=YES \
+-DCMAKE_CXX_FLAGS="-O2"
+  ninja clang-llvm-proto-fuzzer clang-loop-proto-to-llvm

[PATCH] D50792: [ASTImporter] Add test for member pointer types.

2018-08-16 Thread Raphael Isemann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339919: [ASTImporter] Add test for member pointer types. 
(authored by teemperor, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50792?vs=160860=161078#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50792

Files:
  cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
  cfe/trunk/test/Import/cxx-member-pointers/test.cpp


Index: cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
===
--- cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
+++ cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
@@ -0,0 +1,7 @@
+struct S {
+  int i;
+};
+
+int S::*iptr() {
+  return ::i;
+}
Index: cfe/trunk/test/Import/cxx-member-pointers/test.cpp
===
--- cfe/trunk/test/Import/cxx-member-pointers/test.cpp
+++ cfe/trunk/test/Import/cxx-member-pointers/test.cpp
@@ -0,0 +1,16 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | 
FileCheck %s
+
+// CHECK: VarDecl
+// CHECK-SAME: int S::*
+// CHECK-NEXT: CallExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: int S::*(*)()
+// CHECK-NEXT: DeclRefExpr
+// CHECK-SAME: int S::*()
+
+void expr() {
+  int S::*p = iptr();
+  S s;
+  s.i = 3;
+  int i = s.*p;
+}


Index: cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
===
--- cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
+++ cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
@@ -0,0 +1,7 @@
+struct S {
+  int i;
+};
+
+int S::*iptr() {
+  return ::i;
+}
Index: cfe/trunk/test/Import/cxx-member-pointers/test.cpp
===
--- cfe/trunk/test/Import/cxx-member-pointers/test.cpp
+++ cfe/trunk/test/Import/cxx-member-pointers/test.cpp
@@ -0,0 +1,16 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | FileCheck %s
+
+// CHECK: VarDecl
+// CHECK-SAME: int S::*
+// CHECK-NEXT: CallExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: int S::*(*)()
+// CHECK-NEXT: DeclRefExpr
+// CHECK-SAME: int S::*()
+
+void expr() {
+  int S::*p = iptr();
+  S s;
+  s.i = 3;
+  int i = s.*p;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339919 - [ASTImporter] Add test for member pointer types.

2018-08-16 Thread Raphael Isemann via cfe-commits
Author: teemperor
Date: Thu Aug 16 11:22:21 2018
New Revision: 339919

URL: http://llvm.org/viewvc/llvm-project?rev=339919=rev
Log:
[ASTImporter] Add test for member pointer types.

Reviewers: a.sidorin, martong

Reviewed By: martong

Subscribers: rnkovacs, martong, cfe-commits

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

Added:
cfe/trunk/test/Import/cxx-member-pointers/
cfe/trunk/test/Import/cxx-member-pointers/Inputs/
cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
cfe/trunk/test/Import/cxx-member-pointers/test.cpp

Added: cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp?rev=339919=auto
==
--- cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp (added)
+++ cfe/trunk/test/Import/cxx-member-pointers/Inputs/S.cpp Thu Aug 16 11:22:21 
2018
@@ -0,0 +1,7 @@
+struct S {
+  int i;
+};
+
+int S::*iptr() {
+  return ::i;
+}

Added: cfe/trunk/test/Import/cxx-member-pointers/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/cxx-member-pointers/test.cpp?rev=339919=auto
==
--- cfe/trunk/test/Import/cxx-member-pointers/test.cpp (added)
+++ cfe/trunk/test/Import/cxx-member-pointers/test.cpp Thu Aug 16 11:22:21 2018
@@ -0,0 +1,16 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | 
FileCheck %s
+
+// CHECK: VarDecl
+// CHECK-SAME: int S::*
+// CHECK-NEXT: CallExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: int S::*(*)()
+// CHECK-NEXT: DeclRefExpr
+// CHECK-SAME: int S::*()
+
+void expr() {
+  int S::*p = iptr();
+  S s;
+  s.i = 3;
+  int i = s.*p;
+}


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


[PATCH] D50793: [ASTImporter] Add test for importing CompoundAssignOperators

2018-08-16 Thread Raphael Isemann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339918: [ASTImporter] Add test for importing 
CompoundAssignOperators (authored by teemperor, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50793?vs=160862=161076#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50793

Files:
  cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
  cfe/trunk/test/Import/compound-assign-op/test.cpp


Index: cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
===
--- cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
+++ cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
@@ -0,0 +1,18 @@
+void f() {
+  unsigned iadd_eq = 0U;
+  iadd_eq += 1U;
+  unsigned isub_eq = 0U;
+  isub_eq -= 1U;
+  unsigned imul_eq = 0U;
+  imul_eq *= 1U;
+  unsigned idiv_eq = 0U;
+  idiv_eq /= 1U;
+  unsigned iand_eq = 0U;
+  iand_eq &= 1U;
+  unsigned ixor_eq = 0U;
+  ixor_eq ^= 1U;
+  unsigned ilsh_eq = 0U;
+  ilsh_eq <<= 1U;
+  unsigned irsh_eq = 0U;
+  irsh_eq >>= 1U;
+}
Index: cfe/trunk/test/Import/compound-assign-op/test.cpp
===
--- cfe/trunk/test/Import/compound-assign-op/test.cpp
+++ cfe/trunk/test/Import/compound-assign-op/test.cpp
@@ -0,0 +1,45 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | 
FileCheck %s
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '+='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '-='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '*='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '/='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '&='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '^='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '<<='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '>>='
+
+void expr() {
+  f();
+}


Index: cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
===
--- cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
+++ cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
@@ -0,0 +1,18 @@
+void f() {
+  unsigned iadd_eq = 0U;
+  iadd_eq += 1U;
+  unsigned isub_eq = 0U;
+  isub_eq -= 1U;
+  unsigned imul_eq = 0U;
+  imul_eq *= 1U;
+  unsigned idiv_eq = 0U;
+  idiv_eq /= 1U;
+  unsigned iand_eq = 0U;
+  iand_eq &= 1U;
+  unsigned ixor_eq = 0U;
+  ixor_eq ^= 1U;
+  unsigned ilsh_eq = 0U;
+  ilsh_eq <<= 1U;
+  unsigned irsh_eq = 0U;
+  irsh_eq >>= 1U;
+}
Index: cfe/trunk/test/Import/compound-assign-op/test.cpp
===
--- cfe/trunk/test/Import/compound-assign-op/test.cpp
+++ cfe/trunk/test/Import/compound-assign-op/test.cpp
@@ -0,0 +1,45 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '+='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '-='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '*='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '/='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '&='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '^='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '<<='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '>>='
+
+void expr() {
+  f();
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50810: [ASTImporter] Add test for DoStmt

2018-08-16 Thread Raphael Isemann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339917: [ASTImporter] Add test for DoStmt (authored by 
teemperor, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50810?vs=160918=161075#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50810

Files:
  cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
  cfe/trunk/test/Import/do-stmt/test.cpp


Index: cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
===
--- cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
+++ cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
@@ -0,0 +1,7 @@
+void f() {
+  do
+;
+  while (true);
+  do {
+  } while (false);
+}
Index: cfe/trunk/test/Import/do-stmt/test.cpp
===
--- cfe/trunk/test/Import/do-stmt/test.cpp
+++ cfe/trunk/test/Import/do-stmt/test.cpp
@@ -0,0 +1,15 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | 
FileCheck %s
+
+// CHECK: DoStmt
+// CHECK-NEXT: NullStmt
+// CHECK-NEXT: CXXBoolLiteralExpr
+// CHECK-SAME: true
+
+// CHECK: DoStmt
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: CXXBoolLiteralExpr
+// CHECK-SAME: false
+
+void expr() {
+  f();
+}


Index: cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
===
--- cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
+++ cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
@@ -0,0 +1,7 @@
+void f() {
+  do
+;
+  while (true);
+  do {
+  } while (false);
+}
Index: cfe/trunk/test/Import/do-stmt/test.cpp
===
--- cfe/trunk/test/Import/do-stmt/test.cpp
+++ cfe/trunk/test/Import/do-stmt/test.cpp
@@ -0,0 +1,15 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s
+
+// CHECK: DoStmt
+// CHECK-NEXT: NullStmt
+// CHECK-NEXT: CXXBoolLiteralExpr
+// CHECK-SAME: true
+
+// CHECK: DoStmt
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: CXXBoolLiteralExpr
+// CHECK-SAME: false
+
+void expr() {
+  f();
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339918 - [ASTImporter] Add test for importing CompoundAssignOperators

2018-08-16 Thread Raphael Isemann via cfe-commits
Author: teemperor
Date: Thu Aug 16 11:21:33 2018
New Revision: 339918

URL: http://llvm.org/viewvc/llvm-project?rev=339918=rev
Log:
[ASTImporter] Add test for importing CompoundAssignOperators

Reviewers: a.sidorin, martong

Reviewed By: martong

Subscribers: rnkovacs, cfe-commits, martong

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

Added:
cfe/trunk/test/Import/compound-assign-op/
cfe/trunk/test/Import/compound-assign-op/Inputs/
cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
cfe/trunk/test/Import/compound-assign-op/test.cpp

Added: cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp?rev=339918=auto
==
--- cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp (added)
+++ cfe/trunk/test/Import/compound-assign-op/Inputs/F.cpp Thu Aug 16 11:21:33 
2018
@@ -0,0 +1,18 @@
+void f() {
+  unsigned iadd_eq = 0U;
+  iadd_eq += 1U;
+  unsigned isub_eq = 0U;
+  isub_eq -= 1U;
+  unsigned imul_eq = 0U;
+  imul_eq *= 1U;
+  unsigned idiv_eq = 0U;
+  idiv_eq /= 1U;
+  unsigned iand_eq = 0U;
+  iand_eq &= 1U;
+  unsigned ixor_eq = 0U;
+  ixor_eq ^= 1U;
+  unsigned ilsh_eq = 0U;
+  ilsh_eq <<= 1U;
+  unsigned irsh_eq = 0U;
+  irsh_eq >>= 1U;
+}

Added: cfe/trunk/test/Import/compound-assign-op/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/compound-assign-op/test.cpp?rev=339918=auto
==
--- cfe/trunk/test/Import/compound-assign-op/test.cpp (added)
+++ cfe/trunk/test/Import/compound-assign-op/test.cpp Thu Aug 16 11:21:33 2018
@@ -0,0 +1,45 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | 
FileCheck %s
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '+='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '-='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '*='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '/='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '&='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '^='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '<<='
+
+// CHECK: VarDecl
+// CHECK-NEXT: Integer
+// CHECK-NEXT: CompoundAssignOperator
+// CHECK-SAME: '>>='
+
+void expr() {
+  f();
+}


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


[PATCH] D50855: [analyzer] pr37578: Fix lvalue/rvalue problem in field-of-temporary adjustments.

2018-08-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 161073.
NoQ added a comment.

Add comments for optional arguments.

The reason why i chose an out-parameter rather than returning a std::pair is 
because most callers //presumably// don't need this feature.


https://reviews.llvm.org/D50855

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1152,3 +1152,23 @@
 // and the non-definition decl should be found by direct lookup.
 void T::foo(C) {}
 } // namespace argument_virtual_decl_lookup
+
+namespace union_indirect_field_crash {
+union U {
+  struct {
+int x;
+  };
+};
+
+template  class C {
+public:
+  void foo() const {
+(void)(true ? U().x : 0);
+  }
+};
+
+void test() {
+  C c;
+  c.foo();
+}
+} // namespace union_indirect_field_crash
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -283,11 +283,10 @@
   return state;
 }
 
-ProgramStateRef
-ExprEngine::createTemporaryRegionIfNeeded(ProgramStateRef State,
-  const LocationContext *LC,
-  const Expr *InitWithAdjustments,
-  const Expr *Result) {
+ProgramStateRef ExprEngine::createTemporaryRegionIfNeeded(
+ProgramStateRef State, const LocationContext *LC,
+const Expr *InitWithAdjustments, const Expr *Result,
+const SubRegion **OutRegionWithAdjustments) {
   // FIXME: This function is a hack that works around the quirky AST
   // we're often having with respect to C++ temporaries. If only we modelled
   // the actual execution order of statements properly in the CFG,
@@ -297,8 +296,11 @@
   if (!Result) {
 // If we don't have an explicit result expression, we're in "if needed"
 // mode. Only create a region if the current value is a NonLoc.
-if (!InitValWithAdjustments.getAs())
+if (!InitValWithAdjustments.getAs()) {
+  if (OutRegionWithAdjustments)
+*OutRegionWithAdjustments = nullptr;
   return State;
+}
 Result = InitWithAdjustments;
   } else {
 // We need to create a region no matter what. For sanity, make sure we don't
@@ -418,11 +420,16 @@
   // The result expression would now point to the correct sub-region of the
   // newly created temporary region. Do this last in order to getSVal of Init
   // correctly in case (Result == Init).
-  State = State->BindExpr(Result, LC, Reg);
+  if (Result->isGLValue())
+State = State->BindExpr(Result, LC, Reg);
+  else
+State = State->BindExpr(Result, LC, InitValWithAdjustments);
 
   // Notify checkers once for two bindLoc()s.
   State = processRegionChange(State, TR, LC);
 
+  if (OutRegionWithAdjustments)
+*OutRegionWithAdjustments = cast(Reg.getAsRegion());
   return State;
 }
 
@@ -2533,8 +2540,12 @@
   }
 
   // Handle regular struct fields / member variables.
-  state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
-  SVal baseExprVal = state->getSVal(BaseExpr, LCtx);
+  const SubRegion *MR;
+  state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr,
+/*Result=*/nullptr,
+/*OutRegionWithAdjustments=*/);
+  SVal baseExprVal =
+  MR ? loc::MemRegionVal(MR) : state->getSVal(BaseExpr, LCtx);
 
   const auto *field = cast(Member);
   SVal L = state->getLValue(field, baseExprVal);
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -734,10 +734,14 @@
   ///
   /// If \p Result is provided, the new region will be bound to this expression
   /// instead of \p InitWithAdjustments.
-  ProgramStateRef createTemporaryRegionIfNeeded(ProgramStateRef State,
-const LocationContext *LC,
-const Expr *InitWithAdjustments,
-const Expr *Result = nullptr);
+  ///
+  /// Returns the temporary region with adjustments into the optional
+  /// OutRegionWithAdjustments out-parameter if a new region was indeed needed,
+  /// otherwise sets it to nullptr.
+  ProgramStateRef createTemporaryRegionIfNeeded(
+  ProgramStateRef State, const LocationContext *LC,
+  const Expr *InitWithAdjustments, const Expr *Result = nullptr,
+  const SubRegion **OutRegionWithAdjustments = nullptr);
 
   /// Returns a region representing the first element 

r339917 - [ASTImporter] Add test for DoStmt

2018-08-16 Thread Raphael Isemann via cfe-commits
Author: teemperor
Date: Thu Aug 16 11:20:52 2018
New Revision: 339917

URL: http://llvm.org/viewvc/llvm-project?rev=339917=rev
Log:
[ASTImporter] Add test for DoStmt

Reviewers: a.sidorin, martong

Reviewed By: martong

Subscribers: rnkovacs, martong, cfe-commits

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

Added:
cfe/trunk/test/Import/do-stmt/
cfe/trunk/test/Import/do-stmt/Inputs/
cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
cfe/trunk/test/Import/do-stmt/test.cpp

Added: cfe/trunk/test/Import/do-stmt/Inputs/F.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/do-stmt/Inputs/F.cpp?rev=339917=auto
==
--- cfe/trunk/test/Import/do-stmt/Inputs/F.cpp (added)
+++ cfe/trunk/test/Import/do-stmt/Inputs/F.cpp Thu Aug 16 11:20:52 2018
@@ -0,0 +1,7 @@
+void f() {
+  do
+;
+  while (true);
+  do {
+  } while (false);
+}

Added: cfe/trunk/test/Import/do-stmt/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/do-stmt/test.cpp?rev=339917=auto
==
--- cfe/trunk/test/Import/do-stmt/test.cpp (added)
+++ cfe/trunk/test/Import/do-stmt/test.cpp Thu Aug 16 11:20:52 2018
@@ -0,0 +1,15 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | 
FileCheck %s
+
+// CHECK: DoStmt
+// CHECK-NEXT: NullStmt
+// CHECK-NEXT: CXXBoolLiteralExpr
+// CHECK-SAME: true
+
+// CHECK: DoStmt
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: CXXBoolLiteralExpr
+// CHECK-SAME: false
+
+void expr() {
+  f();
+}


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


  1   2   3   >