[PATCH] D32341: Fix a bug that warnings generated with -M or -MM flags

2017-04-24 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

Do you think it is not a good idea to change condition if -MD or -MMD exists?
for example,
if ( !A->getOption().matches(options::OPT_MD) && 
!A->getOption().matches(options::OPT_MQ)) CmdArgs.push_back("-w");


https://reviews.llvm.org/D32341



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


[PATCH] D32401: [Devirtualization] insert placement new barrier with -O0

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

In https://reviews.llvm.org/D32401#734921, @rjmccall wrote:

> I continue to be really uncomfortable with the entire design of this 
> optimization, which appears to miscompile code by default, but as long as 
> nobody's suggesting that we actually turn it on by default, I guess it can be 
> your little research-compiler playground.  It might be better to downgrade it 
> to a -cc1 option, though.
>
> This specific change is fine by me.


Can you tell me a little more about what part of the design you dislike? Is it 
about missing optimizations by introducing the barriers, cost of inserting the 
barriers or the fact that we have to be cautious to not break anything?


https://reviews.llvm.org/D32401



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


[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-04-24 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin added a comment.

BTW, the list of include files which are located in [PROGRAM_FILES]\Microsoft 
Visual Studio 14.0\VC\include directory is

- stdbool.h
- limits.h
- stdint.h
- setjmp.h

The rest is in [PROGRAM_FILES]\Windows Kits\10\Include\10.0.whatever.0\ucrt 
directory. Which directory @_LIBCPP_INCLUDE_NEXT@ is supposed to point to?


https://reviews.llvm.org/D32411



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


[clang-tools-extra] r301167 - [clang-tidy] New check: modernize-replace-random-shuffle.

2017-04-24 Thread Mads Ravn via cfe-commits
Author: madsravn
Date: Mon Apr 24 04:27:20 2017
New Revision: 301167

URL: http://llvm.org/viewvc/llvm-project?rev=301167&view=rev
Log:
[clang-tidy] New check: modernize-replace-random-shuffle.

This check will find occurrences of ``std::random_shuffle`` and replace it with 
``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available 
and thus we need to replace it.

Example of case that it fixes

```
  std::vector v;

  // First example
  std::random_shuffle(vec.begin(), vec.end());

```

Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons, mclow.lists

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-replace-random-shuffle.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=301167&r1=301166&r2=301167&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Mon Apr 24 
04:27:20 2017
@@ -13,6 +13,7 @@ add_clang_library(clangTidyModernizeModu
   RawStringLiteralCheck.cpp
   RedundantVoidArgCheck.cpp
   ReplaceAutoPtrCheck.cpp
+  ReplaceRandomShuffleCheck.cpp
   ReturnBracedInitListCheck.cpp
   ShrinkToFitCheck.cpp
   UseAutoCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp?rev=301167&r1=301166&r2=301167&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp Mon 
Apr 24 04:27:20 2017
@@ -19,6 +19,7 @@
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
 #include "ReplaceAutoPtrCheck.h"
+#include "ReplaceRandomShuffleCheck.h"
 #include "ReturnBracedInitListCheck.h"
 #include "ShrinkToFitCheck.h"
 #include "UseAutoCheck.h"
@@ -54,6 +55,8 @@ public:
 "modernize-redundant-void-arg");
 CheckFactories.registerCheck(
 "modernize-replace-auto-ptr");
+CheckFactories.registerCheck(
+"modernize-replace-random-shuffle");
 CheckFactories.registerCheck(
 "modernize-return-braced-init-list");
 CheckFactories.registerCheck("modernize-shrink-to-fit");

Added: 
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp?rev=301167&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp 
Mon Apr 24 04:27:20 2017
@@ -0,0 +1,109 @@
+//===--- ReplaceRandomShuffleCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ReplaceRandomShuffleCheck.h"
+#include "../utils/FixItHintUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+ReplaceRandomShuffleCheck::ReplaceRandomShuffleCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.get("IncludeStyle", "llvm"))) {}
+
+void ReplaceRandomShuffleCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus11)
+return;
+
+  const auto Begin = hasArgument(0, expr());
+  const auto End = hasArgument(1, expr());
+  const auto RandomFunc = hasArgument(2, expr().bind("randomFunc"));
+  Finder->addMatcher(
+  callExpr(anyOf(allOf(Begin, End, argumentC

[PATCH] D30158: [clang-tidy] modernize: Find usage of random_shuffle and replace it with shuffle.

2017-04-24 Thread Mads Ravn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301167: [clang-tidy] New check: 
modernize-replace-random-shuffle. (authored by madsravn).

Changed prior to commit:
  https://reviews.llvm.org/D30158?vs=96303&id=96362#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30158

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-replace-random-shuffle.rst
  clang-tools-extra/trunk/test/clang-tidy/modernize-replace-random-shuffle.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -19,6 +19,7 @@
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
 #include "ReplaceAutoPtrCheck.h"
+#include "ReplaceRandomShuffleCheck.h"
 #include "ReturnBracedInitListCheck.h"
 #include "ShrinkToFitCheck.h"
 #include "UseAutoCheck.h"
@@ -54,6 +55,8 @@
 "modernize-redundant-void-arg");
 CheckFactories.registerCheck(
 "modernize-replace-auto-ptr");
+CheckFactories.registerCheck(
+"modernize-replace-random-shuffle");
 CheckFactories.registerCheck(
 "modernize-return-braced-init-list");
 CheckFactories.registerCheck("modernize-shrink-to-fit");
Index: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
@@ -13,6 +13,7 @@
   RawStringLiteralCheck.cpp
   RedundantVoidArgCheck.cpp
   ReplaceAutoPtrCheck.cpp
+  ReplaceRandomShuffleCheck.cpp
   ReturnBracedInitListCheck.cpp
   ShrinkToFitCheck.cpp
   UseAutoCheck.cpp
Index: clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
+++ clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.h
@@ -0,0 +1,42 @@
+//===--- ReplaceRandomShuffleCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_RANDOM_SHUFFLE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_RANDOM_SHUFFLE_H
+
+#include "../ClangTidy.h"
+#include "../utils/IncludeInserter.h"
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// std::random_shuffle will be removed as of C++17. This check will find and
+/// replace all occurrences of std::random_shuffle with std::shuffle.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-replace-random-shuffle.html
+class ReplaceRandomShuffleCheck : public ClangTidyCheck {
+public:
+  ReplaceRandomShuffleCheck(StringRef Name, ClangTidyContext *Context);
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  std::unique_ptr IncludeInserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_RANDOM_SHUFFLE_H
Index: clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
@@ -0,0 +1,109 @@
+//===--- ReplaceRandomShuffleCheck.cpp - clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ReplaceRandomShuffleCheck.h"
+#include "../utils/FixItHintUtils.h"
+#include "clang/AST/ASTContext.h"
+#i

[PATCH] D32424: Add a fix-it for -Wunguarded-availability

2017-04-24 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch adds a fix-it for the -Wunguarded-availability warning. This fix-it 
is similar to the Swift one: it suggests that you wrap the statement in an `if 
(@available)` check. The produced fixits are indented (just like the Swift 
ones) to make them look nice in Xcode's fix-it preview.


Repository:
  rL LLVM

https://reviews.llvm.org/D32424

Files:
  include/clang/Lex/Lexer.h
  lib/Lex/Lexer.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/FixIt/fixit-availability.c
  test/FixIt/fixit-availability.mm

Index: test/FixIt/fixit-availability.mm
===
--- /dev/null
+++ test/FixIt/fixit-availability.mm
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunguarded-availability -fdiagnostics-parseable-fixits -triple x86_64-apple-darwin9 %s 2>&1 | FileCheck %s
+
+__attribute__((availability(macos, introduced=10.12)))
+int function(void);
+
+void anotherFunction(int function);
+
+int use() {
+  function();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:14-[[@LINE-2]]:14}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  int x = function();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:22-[[@LINE-2]]:22}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  x += function();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:19-[[@LINE-2]]:19}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  if (1) {
+x = function();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:20-[[@LINE-2]]:20}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  }
+  anotherFunction(function());
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:31-[[@LINE-2]]:31}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  if (function()) {
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE+1]]:4-[[@LINE+1]]:4}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  }
+  while (function())
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE+1]]:6-[[@LINE+1]]:6}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+;
+  do
+function();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n"
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n} else {\n// Fallback on earlier versions\n}"
+  while (1);
+  for (int i = 0; i < 10; ++i)
+function();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:5-[[@LINE-1]]:5}:"if (@available(macos 10.12, *)) {\n"
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n} else {\n// Fallback on earlier versions\n}"
+  return function();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:21-[[@LINE-2]]:21}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+}
+
+#define MYFUNCTION function
+
+#define MACRO_ARGUMENT(X) X
+#define MACRO_ARGUMENT_SEMI(X) X;
+#define MACRO_ARGUMENT_2(X) if (1) X;
+
+#define INNER_MACRO if (1) MACRO_ARGUMENT(function()); else ;
+
+void useInMacros() {
+  MYFUNCTION();
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+
+  MACRO_ARGUMENT_SEMI(function())
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:34-[[@LINE-2]]:34}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  MACRO_ARGUMENT(function());
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:30-[[@LINE-2]]:30}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+  MACRO_ARGUMENT_2(function());
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:32-[[@LINE-2]]:32}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+
+  INNER_MACRO
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (@available(macos 10.12, *)) {\n  "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:14-[[@LINE-2]]:14}:"\n  } else {\n  // Fallback on earlier versions\n  }"
+}
Index: test/FixIt/fixit-availabilit

[PATCH] D32378: Insert invariant.group.barrier for pointers comparisons

2017-04-24 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 96371.
Prazek added a comment.

Don't add barrier if compared with nullptr. With this it reduces added 
barriers to compares by half. Note that we will transform barrier(null) -> 
barrier
in llvm


https://reviews.llvm.org/D32378

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGenCXX/strict-vtable-pointers.cpp

Index: test/CodeGenCXX/strict-vtable-pointers.cpp
===
--- test/CodeGenCXX/strict-vtable-pointers.cpp
+++ test/CodeGenCXX/strict-vtable-pointers.cpp
@@ -257,6 +257,72 @@
   take(u.h);
 }
 
+// CHECK-NEW-LABEL: define void @_Z7comparev()
+void compare() {
+  A *a = new A;
+  a->foo();
+  // CHECK-NEW: call i8* @llvm.invariant.group.barrier(i8*
+  A *b = new (a) B;
+
+  // CHECK-NEW: %[[a:.*]] = call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: %[[a2:.*]] = bitcast i8* %[[a]] to %struct.A*
+  // CHECK-NEW: %[[b:.*]] = call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: %[[b2:.*]] = bitcast i8* %[[b]] to %struct.A*
+  // CHECK-NEW: %cmp = icmp eq %struct.A* %[[a2]], %[[b2]]
+  if (a == b)
+b->foo();
+}
+
+// CHECK-NEW-LABEL: compare2
+bool compare2(A *a, A *a2) {
+  // CHECK-NEW: %[[a:.*]] = call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: %[[a2:.*]] = bitcast i8* %[[a]] to %struct.A*
+  // CHECK-NEW: %[[b:.*]] = call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: %[[b2:.*]] = bitcast i8* %[[b]] to %struct.A*
+  // CHECK-NEW: %cmp = icmp ult %struct.A* %[[a2]], %[[b2]]
+  return a < a2;
+}
+// CHECK-NEW-LABEL: compareIntPointers
+bool compareIntPointers(int *a, int *b) {
+  // CHECK-NEW-NOT: call i8* @llvm.invariant.group.barrier
+  return a == b;
+}
+
+struct HoldingOtherVirtuals {
+  B b;
+};
+
+// There is no need to add barriers for comparision of pointer to classes
+// that are not dynamic.
+// CHECK-NEW-LABEL: compare5
+bool compare5(HoldingOtherVirtuals *a, HoldingOtherVirtuals *b) {
+  // CHECK-NEW-NOT: call i8* @llvm.invariant.group.barrier
+  return a == b;
+}
+// CHECK-NEW-LABEL: compareNull
+bool compareNull(A *a) {
+  // CHECK-NEW-NOT: call i8* @llvm.invariant.group.barrier
+
+  if (a != nullptr)
+return false;
+  if (!a)
+return false;
+  return a == nullptr;
+}
+
+struct X;
+// We have to also introduce the barriers if comparing pointers to incomplete
+// objects
+// CHECK-NEW-LABEL: define zeroext i1 @_Z8compare4P1XS0_
+bool compare4(X *x, X *x2) {
+  // CHECK-NEW: %[[x:.*]] = call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: %[[xp:.*]] = bitcast i8* %[[x]] to %struct.X*
+  // CHECK-NEW: %[[x2:.*]] = call i8* @llvm.invariant.group.barrier(i8*
+  // CHECK-NEW: %[[x2p:.*]] = bitcast i8* %[[x2]] to %struct.X*
+  // CHECK-NEW: %cmp = icmp eq %struct.X* %[[xp]], %[[x2p]]
+  return x == x2;
+}
+
 /** DTORS **/
 // CHECK-DTORS-LABEL: define linkonce_odr void @_ZN10StaticBaseD2Ev(
 // CHECK-DTORS-NOT: call i8* @llvm.invariant.group.barrier(
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1698,7 +1698,7 @@
   }
 
   case CK_IntToOCLSampler:
-return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF);
+return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF);
 
   } // end of switch
 
@@ -3062,8 +3062,22 @@
   Result = Builder.CreateFCmp(FCmpOpc, LHS, RHS, "cmp");
 } else if (LHSTy->hasSignedIntegerRepresentation()) {
   Result = Builder.CreateICmp(SICmpOpc, LHS, RHS, "cmp");
-} else {
-  // Unsigned integers and pointers.
+} else { // Unsigned integers and pointers.
+  if (CGF.CGM.getCodeGenOpts().StrictVTablePointers &&
+  !isa(LHS) &&
+  !isa(RHS)) {
+// Based on comparisons of pointers to dynamic objects, the optimizer
+// can replace one pointer with another. This might result in
+// replacing pointer after barrier to pointer before barrier,
+// resulting in invalid devirtualization. Compare with null is safe.
+
+if (auto *RD = LHSTy->getPointeeCXXRecordDecl())
+  if (!RD->isCompleteDefinition() || RD->isDynamicClass())
+LHS = Builder.CreateInvariantGroupBarrier(LHS);
+if (auto *RD = RHSTy->getPointeeCXXRecordDecl())
+  if (!RD->isCompleteDefinition() || RD->isDynamicClass())
+RHS = Builder.CreateInvariantGroupBarrier(RHS);
+  }
   Result = Builder.CreateICmp(UICmpOpc, LHS, RHS, "cmp");
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-04-24 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar added inline comments.



Comment at: test/clang-tidy/modernize-use-emplace.cpp:284
+  // CHECK-FIXES: v.emplace_back(42LL, 13);
+
+  v.push_back(std::make_pair(0, 3));

kuhar wrote:
> Prazek wrote:
> > I would add here test like:
> > 
> >   class X {
> > X(std:;pair a) {}
> >   };
> >   
> >   std::vector v;
> >   v.push_back(make_pair(42, 42));
> >   
> > I guess as long as X ctor is not explicit this can happen, and we can't 
> > transform it to
> > emplace.back(42, 42)
> Nice idea for a test case, added.
A better test case would be to make X's ctor take a pair by const reference or 
rvalue reference. This way it wouldn't produce an extra CxxConstructExpr and 
will be currently (incorrectly) matched. This needs to be fixed.


https://reviews.llvm.org/D32395



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


[PATCH] D30691: [analyzer] Support for naive cross translational unit analysis

2017-04-24 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 96377.
xazax.hun marked an inline comment as done.
xazax.hun added a comment.

- Removed more unused code.
- Remove the usages of posix API.
- Changes according to some review comments.
- Add a test to the clang-func-mapping tool.


https://reviews.llvm.org/D30691

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Mangle.h
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/ItaniumMangle.cpp
  lib/Basic/SourceManager.cpp
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CMakeLists.txt
  lib/StaticAnalyzer/Core/CallEvent.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  test/Analysis/Inputs/ctu-chain.cpp
  test/Analysis/Inputs/ctu-other.cpp
  test/Analysis/Inputs/externalFnMap.txt
  test/Analysis/ctu-main.cpp
  test/Analysis/func-mapping-test.cpp
  test/CMakeLists.txt
  test/lit.cfg
  tools/CMakeLists.txt
  tools/clang-func-mapping/CMakeLists.txt
  tools/clang-func-mapping/ClangFnMapGen.cpp
  tools/ctu-analysis/ctu-analyze.py
  tools/ctu-analysis/ctu-build.py
  tools/scan-build-py/libscanbuild/runner.py

Index: tools/scan-build-py/libscanbuild/runner.py
===
--- tools/scan-build-py/libscanbuild/runner.py
+++ tools/scan-build-py/libscanbuild/runner.py
@@ -162,7 +162,8 @@
 
 def target():
 """ Creates output file name for reports. """
-if opts['output_format'] in {'plist', 'plist-html'}:
+if opts['output_format'] in {'plist', 'plist-html',
+ 'plist-multi-file'}:
 (handle, name) = tempfile.mkstemp(prefix='report-',
   suffix='.plist',
   dir=opts['output_dir'])
Index: tools/ctu-analysis/ctu-build.py
===
--- /dev/null
+++ tools/ctu-analysis/ctu-build.py
@@ -0,0 +1,214 @@
+#!/usr/bin/env python
+
+import argparse
+import json
+import logging
+import multiprocessing
+import os
+import re
+import signal
+import subprocess
+import shlex
+
+SOURCE_PATTERN = re.compile('.*\.(C|c|cc|cpp|cxx|ii|m|mm)$', re.IGNORECASE)
+TIMEOUT = 86400
+DEFINED_FUNCTIONS_FILENAME = 'definedFns.txt'
+EXTERNAL_FUNCTIONS_FILENAME = 'externalFns.txt'
+EXTERNAL_FUNCTION_MAP_FILENAME = 'externalFnMap.txt'
+
+
+def get_args():
+parser = argparse.ArgumentParser(
+description='Executes 1st pass of CTU analysis where we preprocess '
+'all files in the compilation database and generate '
+'AST dumps and other necessary information from those '
+'to be used later by the 2nd pass of '
+'Cross Translation Unit analysis',
+formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+parser.add_argument('-b', required=True, dest='buildlog',
+metavar='build.json',
+help='JSON Compilation Database to be used')
+parser.add_argument('-p', metavar='preanalyze-dir', dest='ctuindir',
+help='Target directory for preanalyzation data',
+default='.ctu')
+parser.add_argument('-j', metavar='threads', dest='threads', type=int,
+help='Number of threads to be used',
+default=int(multiprocessing.cpu_count() * 1.0))
+parser.add_argument('-v', dest='verbose', action='store_true',
+help='Verbose output')
+parser.add_argument('--clang-path', metavar='clang-path',
+dest='clang_path',
+help='Set path to directory of clang binaries used '
+ '(default taken from CLANG_PATH envvar)',
+default=os.environ.get('CLANG_PATH'))
+mainargs = parser.parse_args()
+
+if mainargs.verbose:
+logging.getLogger().setLevel(logging.INFO)
+
+if mainargs.clang_path is None:
+clang_path = ''
+else:
+clang_path = os.path.abspath(mainargs.clang_path)
+logging.info('CTU uses clang dir: ' +
+ (clang_path if clang_path != '' else ''))
+
+return mainargs, clang_path
+
+
+def process_buildlog(buildlog_filename, src_2_dir, src_2_cmd, src_order,
+ cmd_2_src, cmd_order):
+with open(buildlog_filename, 'r') as buildlog_file:
+buildlog = json.load(buildlog_file)
+for step in buildlog:
+if SOURCE_PATTERN.match(step['file']):
+if step['file'] not in src_2_dir:
+src_2_dir[step['file']] = step['directory']
+src_2_cmd[step['file']] = step['command']
+src_order.append(step['file'])
+ 

[PATCH] D32427: Fix float abi for SUSE ARM triples

2017-04-24 Thread İsmail Dönmez via Phabricator via cfe-commits
ismail created this revision.
Herald added a subscriber: aemerson.

SUSE's ARM triples always ends with -gnueabi but all the targets are hard-float


https://reviews.llvm.org/D32427

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/linux-as.c


Index: test/Driver/linux-as.c
===
--- test/Driver/linux-as.c
+++ test/Driver/linux-as.c
@@ -174,3 +174,9 @@
 // RUN:   -no-integrated-as -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-Z-ARCH-Z196 %s
 // CHECK-Z-ARCH-Z196: as{{.*}} "-march=z196"
+//
+// RUN: %clang -target armv7hl-suse-linux-gnueabi -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SUSE-ARMV7 %s
+// CHECK-SUSE-ARMV7: as{{.*}}" "-mfloat-abi=hard"
+
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -227,6 +227,10 @@
 }
   }
 
+  // SUSE triples ends with -gnueabi but all targets are hard-float
+  if (Triple.getVendor() == llvm::Triple::SUSE)
+  ABI = FloatABI::Hard;
+
   assert(ABI != FloatABI::Invalid && "must select an ABI");
   return ABI;
 }


Index: test/Driver/linux-as.c
===
--- test/Driver/linux-as.c
+++ test/Driver/linux-as.c
@@ -174,3 +174,9 @@
 // RUN:   -no-integrated-as -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-Z-ARCH-Z196 %s
 // CHECK-Z-ARCH-Z196: as{{.*}} "-march=z196"
+//
+// RUN: %clang -target armv7hl-suse-linux-gnueabi -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SUSE-ARMV7 %s
+// CHECK-SUSE-ARMV7: as{{.*}}" "-mfloat-abi=hard"
+
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -227,6 +227,10 @@
 }
   }
 
+  // SUSE triples ends with -gnueabi but all targets are hard-float
+  if (Triple.getVendor() == llvm::Triple::SUSE)
+  ABI = FloatABI::Hard;
+
   assert(ABI != FloatABI::Invalid && "must select an ABI");
   return ABI;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32427: Fix float abi for SUSE ARM triples

2017-04-24 Thread İsmail Dönmez via Phabricator via cfe-commits
ismail updated this revision to Diff 96382.
ismail added a comment.

Fix typo


https://reviews.llvm.org/D32427

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/linux-as.c


Index: test/Driver/linux-as.c
===
--- test/Driver/linux-as.c
+++ test/Driver/linux-as.c
@@ -174,3 +174,9 @@
 // RUN:   -no-integrated-as -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-Z-ARCH-Z196 %s
 // CHECK-Z-ARCH-Z196: as{{.*}} "-march=z196"
+//
+// RUN: %clang -target armv7hl-suse-linux-gnueabi -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SUSE-ARMV7 %s
+// CHECK-SUSE-ARMV7: as{{.*}}" "-mfloat-abi=hard"
+
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -227,6 +227,10 @@
 }
   }
 
+  // SUSE triples end with -gnueabi but all targets are hard-float
+  if (Triple.getVendor() == llvm::Triple::SUSE)
+  ABI = FloatABI::Hard;
+
   assert(ABI != FloatABI::Invalid && "must select an ABI");
   return ABI;
 }


Index: test/Driver/linux-as.c
===
--- test/Driver/linux-as.c
+++ test/Driver/linux-as.c
@@ -174,3 +174,9 @@
 // RUN:   -no-integrated-as -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-Z-ARCH-Z196 %s
 // CHECK-Z-ARCH-Z196: as{{.*}} "-march=z196"
+//
+// RUN: %clang -target armv7hl-suse-linux-gnueabi -### \
+// RUN:   -no-integrated-as -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SUSE-ARMV7 %s
+// CHECK-SUSE-ARMV7: as{{.*}}" "-mfloat-abi=hard"
+
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -227,6 +227,10 @@
 }
   }
 
+  // SUSE triples end with -gnueabi but all targets are hard-float
+  if (Triple.getVendor() == llvm::Triple::SUSE)
+  ABI = FloatABI::Hard;
+
   assert(ABI != FloatABI::Invalid && "must select an ABI");
   return ABI;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32428: Fix for Itanium mangler issue with templates (bug: 31405)

2017-04-24 Thread Serge Preis via Phabricator via cfe-commits
Serge_Preis created this revision.
Herald added subscribers: rengolin, aemerson.

This fixes problem described as bug:31405

https://bugs.llvm.org//show_bug.cgi?id=31405
Itanium ABI: debug assertion in template mangling with declype return

The problem is that FunctionTypeDepthState is not properly managed in templated 
decltype() construct mangling resulting in assertion inside mangler
mangler: /home/spreis/LLVM/llvm/tools/clang/lib/AST/ItaniumMangle.cpp:3976: 
void (anonymous namespace)::CXXNameMangler::mangleFunctionParam(const 
clang::ParmVarDecl *): Assertion `parmDepth < FunctionTypeDepth.getDepth()' 
failed.
Aborted (core dumped)

for code as simple as `template  auto foo(T x) -> const 
decltype(x);`

The fix is to properly save/restore FunctionTypeDepthState before/after 
mangling of type in decltype. This exactly same way FunctionTypeDepthState 
treated in other similar places in a mangler.

While in normal operation mangling of non-instantiated templates is not needed, 
some tools like source code indexers and others may need this. Also in most 
cases mangling of template functions does work, so described assertion looks 
like a flaw rather than actual guard.

See issue description above for more details including stack trace of the 
issue, reproducer example and simple mangling matcher exhibiting the issue.


https://reviews.llvm.org/D32428

Files:
  lib/AST/ItaniumMangle.cpp


Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -4539,9 +4539,11 @@
 
   const FunctionProtoType *Proto =
   cast(FD->getType()->getAs());
+  FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
   TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
   TrackReturnTypeTags.mangleType(Proto->getReturnType());
   TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
+  TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
 
   return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
 }


Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -4539,9 +4539,11 @@
 
   const FunctionProtoType *Proto =
   cast(FD->getType()->getAs());
+  FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
   TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
   TrackReturnTypeTags.mangleType(Proto->getReturnType());
   TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
+  TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
 
   return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-04-24 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar updated this revision to Diff 96384.
kuhar added a comment.

Don't remove make_pair calls when inserted type is different than std::pair.


https://reviews.llvm.org/D32395

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

Index: test/clang-tidy/modernize-use-emplace.cpp
===
--- test/clang-tidy/modernize-use-emplace.cpp
+++ test/clang-tidy/modernize-use-emplace.cpp
@@ -53,8 +53,8 @@
 };
 
 template 
-pair make_pair(T1, T2) {
-  return pair();
+pair make_pair(T1&&, T2&&) {
+  return {};
 };
 
 template 
@@ -274,18 +274,51 @@
 
 void testMakePair() {
   std::vector> v;
-  // FIXME: add functionality to change calls of std::make_pair
   v.push_back(std::make_pair(1, 2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(1, 2);
 
-  // FIXME: This is not a bug, but call of make_pair should be removed in the
-  // future. This one matches because the return type of make_pair is different
-  // than the pair itself.
   v.push_back(std::make_pair(42LL, 13));
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
-  // CHECK-FIXES: v.emplace_back(std::make_pair(42LL, 13));
+  // CHECK-FIXES: v.emplace_back(42LL, 13);
+
+  v.push_back(std::make_pair(0, 3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(std::make_pair(0, 3));
+  //
+  // Even though the call above could be turned into v.emplace_back(0, 3),
+  // we don't eliminate the make_pair call here, because of the explicit
+  // template parameters provided. make_pair's arguments can be convertible
+  // to its explicitly provided template parameter, but not to the pair's
+  // element type. The examples below illustrate the problem.
+  struct D {
+D(...) {}
+operator char() const { return 0; }
+  };
+  v.push_back(std::make_pair(Something(), 2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(std::make_pair(Something(), 2));
+
+  struct X {
+X(std::pair) {}
+  };
+  std::vector x;
+  x.push_back(std::make_pair(1, 2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: x.emplace_back(std::make_pair(1, 2));
+  // make_pair cannot be removed here, as X is not constructible with two ints.
+
+  struct Y {
+Y(std::pair&&) {}
+  };
+  std::vector y;
+  y.push_back(std::make_pair(2, 3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: y.emplace_back(std::make_pair(2, 3));
+  // make_pair cannot be removed here, as Y is not constructible with two ints.
 }
 
-void testOtherCointainers() {
+void testOtherContainers() {
   std::list l;
   l.push_back(Something(42, 41));
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
Index: docs/clang-tidy/checks/modernize-use-emplace.rst
===
--- docs/clang-tidy/checks/modernize-use-emplace.rst
+++ docs/clang-tidy/checks/modernize-use-emplace.rst
@@ -36,8 +36,7 @@
 
 std::vector> w;
 w.emplace_back(21, 37);
-// This will be fixed to w.emplace_back(21L, 37L); in next version
-w.emplace_back(std::make_pair(21L, 37L);
+w.emplace_back(21L, 37L);
 
 The other situation is when we pass arguments that will be converted to a type
 inside a container.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -101,6 +101,12 @@
   Finds possible inefficient vector operations in for loops that may cause
   unnecessary memory reallocations.
 
+- Improved `modernize-use-emplace
+  `_ check
+
+  Removes unnecessary std::make_pair calls in push_back(std::make_pair(a, b)) calls and turns them
+  into emplace_back(a, b).
+
 Improvements to include-fixer
 -
 
Index: clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -15,6 +15,12 @@
 namespace tidy {
 namespace modernize {
 
+namespace {
+AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) {
+  return Node.hasExplicitTemplateArgs();
+}
+} // namespace
+
 static const auto DefaultContainersWithPushBack =
 "::std::vector; ::std::list; ::std::deque";
 static const auto DefaultSmartPointers =
@@ -80,18 +86,33 @@
   .bind("ctor");
   auto hasConstructExpr = has(ignoringImplicit(soughtConstructExpr));
 
-  auto ctorAsArgument = materializeTemporaryExpr(
-  anyOf(hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
+  auto makePair = ignoringImplicit(
+  callExpr(callee(expr(ignoringParenImpCasts(
+  declRefExpr(

[PATCH] D32427: Fix float abi for SUSE ARM triples

2017-04-24 Thread Renato Golin via Phabricator via cfe-commits
rengolin added reviewers: compnerd, rovka, joerg.
rengolin added a comment.

I'm not sure this will work at all. Not because it doesn't make sense (it 
does), but because of several bugs in the soft vs. hard float implementation in 
the Triple related classes all the way to the back-end.

I'm adding other folks to discuss.


https://reviews.llvm.org/D32427



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


[PATCH] D32427: Fix float abi for SUSE ARM triples

2017-04-24 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

I'm not sure the results will really work that well either.


https://reviews.llvm.org/D32427



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


r301178 - [Devirtualization] Emit invariant.group loads with empty group md

2017-04-24 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Mon Apr 24 07:58:43 2017
New Revision: 301178

URL: http://llvm.org/viewvc/llvm-project?rev=301178&view=rev
Log:
[Devirtualization] Emit invariant.group loads with empty group md

Summary:
As discussed here
http://lists.llvm.org/pipermail/llvm-dev/2017-January/109332.html
having different groups doesn't solve the problem entirly.

Reviewers: rjmccall, rsmith

Subscribers: amharc, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=301178&r1=301177&r2=301178&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Apr 24 07:58:43 2017
@@ -565,12 +565,8 @@ void CodeGenModule::DecorateInstructionW
 
 void CodeGenModule::DecorateInstructionWithInvariantGroup(
 llvm::Instruction *I, const CXXRecordDecl *RD) {
-  llvm::Metadata *MD = 
CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
-  auto *MetaDataNode = dyn_cast(MD);
-  // Check if we have to wrap MDString in MDNode.
-  if (!MetaDataNode)
-MetaDataNode = llvm::MDNode::get(getLLVMContext(), MD);
-  I->setMetadata(llvm::LLVMContext::MD_invariant_group, MetaDataNode);
+  I->setMetadata(llvm::LLVMContext::MD_invariant_group,
+ llvm::MDNode::get(getLLVMContext(), {}));
 }
 
 void CodeGenModule::Error(SourceLocation loc, StringRef message) {

Modified: cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp?rev=301178&r1=301177&r2=301178&view=diff
==
--- cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp Mon Apr 24 07:58:43 
2017
@@ -12,15 +12,15 @@ struct D : A {
 void testExternallyVisible() {
   A *a = new A;
 
-  // CHECK: load {{.*}} !invariant.group ![[A_MD:[0-9]+]]
+  // CHECK: load {{.*}} !invariant.group ![[MD:[0-9]+]]
   a->foo();
 
   D *d = new D;
   // CHECK: call void @_ZN1DC1Ev(
-  // CHECK: load {{.*}} !invariant.group ![[D_MD:[0-9]+]]
+  // CHECK: load {{.*}} !invariant.group ![[MD]]
   d->foo();
   A *a2 = d;
-  // CHECK: load {{.*}} !invariant.group ![[A_MD]]
+  // CHECK: load {{.*}} !invariant.group ![[MD]]
   a2->foo();
 }
 // CHECK-LABEL: {{^}}}
@@ -40,35 +40,32 @@ struct C : B {
 // CHECK-LABEL: define void @_Z21testInternallyVisibleb(
 void testInternallyVisible(bool p) {
   B *b = new B;
-  // CHECK: = load {{.*}}, !invariant.group ![[B_MD:[0-9]+]]
+  // CHECK: = load {{.*}}, !invariant.group ![[MD]]
   b->bar();
 
   // CHECK: call void @_ZN12_GLOBAL__N_11CC1Ev(
   C *c = new C;
-  // CHECK: = load {{.*}}, !invariant.group ![[C_MD:[0-9]+]]
+  // CHECK: = load {{.*}}, !invariant.group ![[MD]]
   c->bar();
 }
 
 // Checking A::A()
 // CHECK-LABEL: define linkonce_odr void @_ZN1AC2Ev(
-// CHECK: store {{.*}}, !invariant.group ![[A_MD]]
+// CHECK: store {{.*}}, !invariant.group ![[MD]]
 // CHECK-LABEL: {{^}}}
 
 // Checking D::D()
 // CHECK-LABEL: define linkonce_odr void @_ZN1DC2Ev(
 // CHECK:  = call i8* @llvm.invariant.group.barrier(i8*
 // CHECK:  call void @_ZN1AC2Ev(%struct.A*
-// CHECK: store {{.*}} !invariant.group ![[D_MD]]
+// CHECK: store {{.*}} !invariant.group ![[MD]]
 
 // Checking B::B()
 // CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11BC2Ev(
-// CHECK:  store {{.*}}, !invariant.group ![[B_MD]]
+// CHECK:  store {{.*}}, !invariant.group ![[MD]]
 
 // Checking C::C()
 // CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11CC2Ev(
-// CHECK:  store {{.*}}, !invariant.group ![[C_MD]]
+// CHECK:  store {{.*}}, !invariant.group ![[MD]]
 
-// CHECK: ![[A_MD]] = !{!"_ZTS1A"}
-// CHECK: ![[D_MD]] = !{!"_ZTS1D"}
-// CHECK: ![[B_MD]] = distinct !{}
-// CHECK: ![[C_MD]] = distinct !{}
+// CHECK: ![[MD]] = !{}


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


[PATCH] D32110: Emit invariant.group loads with empty group md

2017-04-24 Thread Piotr Padlewski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301178: [Devirtualization] Emit invariant.group loads with 
empty group md (authored by Prazek).

Changed prior to commit:
  https://reviews.llvm.org/D32110?vs=95378&id=96387#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32110

Files:
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp


Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -565,12 +565,8 @@
 
 void CodeGenModule::DecorateInstructionWithInvariantGroup(
 llvm::Instruction *I, const CXXRecordDecl *RD) {
-  llvm::Metadata *MD = 
CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
-  auto *MetaDataNode = dyn_cast(MD);
-  // Check if we have to wrap MDString in MDNode.
-  if (!MetaDataNode)
-MetaDataNode = llvm::MDNode::get(getLLVMContext(), MD);
-  I->setMetadata(llvm::LLVMContext::MD_invariant_group, MetaDataNode);
+  I->setMetadata(llvm::LLVMContext::MD_invariant_group,
+ llvm::MDNode::get(getLLVMContext(), {}));
 }
 
 void CodeGenModule::Error(SourceLocation loc, StringRef message) {
Index: cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
===
--- cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
+++ cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
@@ -12,15 +12,15 @@
 void testExternallyVisible() {
   A *a = new A;
 
-  // CHECK: load {{.*}} !invariant.group ![[A_MD:[0-9]+]]
+  // CHECK: load {{.*}} !invariant.group ![[MD:[0-9]+]]
   a->foo();
 
   D *d = new D;
   // CHECK: call void @_ZN1DC1Ev(
-  // CHECK: load {{.*}} !invariant.group ![[D_MD:[0-9]+]]
+  // CHECK: load {{.*}} !invariant.group ![[MD]]
   d->foo();
   A *a2 = d;
-  // CHECK: load {{.*}} !invariant.group ![[A_MD]]
+  // CHECK: load {{.*}} !invariant.group ![[MD]]
   a2->foo();
 }
 // CHECK-LABEL: {{^}}}
@@ -40,35 +40,32 @@
 // CHECK-LABEL: define void @_Z21testInternallyVisibleb(
 void testInternallyVisible(bool p) {
   B *b = new B;
-  // CHECK: = load {{.*}}, !invariant.group ![[B_MD:[0-9]+]]
+  // CHECK: = load {{.*}}, !invariant.group ![[MD]]
   b->bar();
 
   // CHECK: call void @_ZN12_GLOBAL__N_11CC1Ev(
   C *c = new C;
-  // CHECK: = load {{.*}}, !invariant.group ![[C_MD:[0-9]+]]
+  // CHECK: = load {{.*}}, !invariant.group ![[MD]]
   c->bar();
 }
 
 // Checking A::A()
 // CHECK-LABEL: define linkonce_odr void @_ZN1AC2Ev(
-// CHECK: store {{.*}}, !invariant.group ![[A_MD]]
+// CHECK: store {{.*}}, !invariant.group ![[MD]]
 // CHECK-LABEL: {{^}}}
 
 // Checking D::D()
 // CHECK-LABEL: define linkonce_odr void @_ZN1DC2Ev(
 // CHECK:  = call i8* @llvm.invariant.group.barrier(i8*
 // CHECK:  call void @_ZN1AC2Ev(%struct.A*
-// CHECK: store {{.*}} !invariant.group ![[D_MD]]
+// CHECK: store {{.*}} !invariant.group ![[MD]]
 
 // Checking B::B()
 // CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11BC2Ev(
-// CHECK:  store {{.*}}, !invariant.group ![[B_MD]]
+// CHECK:  store {{.*}}, !invariant.group ![[MD]]
 
 // Checking C::C()
 // CHECK-LABEL: define internal void @_ZN12_GLOBAL__N_11CC2Ev(
-// CHECK:  store {{.*}}, !invariant.group ![[C_MD]]
+// CHECK:  store {{.*}}, !invariant.group ![[MD]]
 
-// CHECK: ![[A_MD]] = !{!"_ZTS1A"}
-// CHECK: ![[D_MD]] = !{!"_ZTS1D"}
-// CHECK: ![[B_MD]] = distinct !{}
-// CHECK: ![[C_MD]] = distinct !{}
+// CHECK: ![[MD]] = !{}


Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -565,12 +565,8 @@
 
 void CodeGenModule::DecorateInstructionWithInvariantGroup(
 llvm::Instruction *I, const CXXRecordDecl *RD) {
-  llvm::Metadata *MD = CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
-  auto *MetaDataNode = dyn_cast(MD);
-  // Check if we have to wrap MDString in MDNode.
-  if (!MetaDataNode)
-MetaDataNode = llvm::MDNode::get(getLLVMContext(), MD);
-  I->setMetadata(llvm::LLVMContext::MD_invariant_group, MetaDataNode);
+  I->setMetadata(llvm::LLVMContext::MD_invariant_group,
+ llvm::MDNode::get(getLLVMContext(), {}));
 }
 
 void CodeGenModule::Error(SourceLocation loc, StringRef message) {
Index: cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
===
--- cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
+++ cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
@@ -12,15 +12,15 @@
 void testExternallyVisible() {
   A *a = new A;
 
-  // CHECK: load {{.*}} !invariant.group ![[A_MD:[0-9]+]]
+  // CHECK: load {{.*}} !invariant.group ![[MD:[0-9]+]]
   a->foo();
 
   D *d = new D;
   // CHECK: call void @_ZN1DC1Ev(
-  // CHECK: load {{.*}} !invariant.group ![[D_

[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

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

I see, thanks for explaining. LGTM. Do you need someone to commit it?


https://reviews.llvm.org/D32348



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


[PATCH] D32427: Fix float abi for SUSE ARM triples

2017-04-24 Thread İsmail Dönmez via Phabricator via cfe-commits
ismail added a comment.

I am open to suggestions on how to do this correctly. The problem as stated is 
all SUSE ARM triples end with -gnueabi but they are all hard-float. Environment 
handling in LLVM seems to only check for the last part of the triple and not 
the whole string.


https://reviews.llvm.org/D32427



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


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

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

Maybe it would be better to introduce a `CXTargetInfo` type, and change the API 
to be:

  clang_getTranslationUnitTargetInfo
  clang_TargetInfo_getTriple
  clang_TargetInfo_getPointerWidth

?
This way the `TargetInfo` functions will be cleanly separated, so we can extend 
the API easier in the future.


Repository:
  rL LLVM

https://reviews.llvm.org/D32389



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


[PATCH] D32294: [clang-tidy] run-clang-tidy.py: check if clang-apply-replacements succeeds

2017-04-24 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar requested review of this revision.
kuhar added a comment.

Is the current patch OK? Do you have any other comments?


https://reviews.llvm.org/D32294



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


[PATCH] D32294: [clang-tidy] run-clang-tidy.py: check if clang-apply-replacements succeeds

2017-04-24 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek accepted this revision.
Prazek added a comment.
This revision is now accepted and ready to land.

LGTM after the fixes


https://reviews.llvm.org/D32294



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


[PATCH] D32346: [clang-tidy] New readability check for strlen argument

2017-04-24 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

Thanks for all comments. I am working on fixing them. Updated patch will be 
uploaded soon.

> Have you run it over a big codebase? What is the turnout?

I did not see this warning yet. Maybe after fixing the comments (::strlen) 
there will be a difference.

In https://reviews.llvm.org/D32346#733906, @Eugene.Zelenko wrote:

> It may be good idea to add check for arguments which taken from C++ 
> containers like std::string, std::string_view, etc.


Not sure how you want. Do you envision something like:

  std::string Par;
  strlen(Par.c_str() + 1);




Comment at: test/clang-tidy/readability-strlen-argument.cpp:1
+// RUN: %check_clang_tidy %s readability-strlen-argument %t
+

JonasToth wrote:
> Same as documentation, maybe a little more telling examples to test on.
> What happens with `char**`, an array of strings? Accessing those one by one 
> would be possible with an addition or subscriptoperation.
how do you mean with char**. If you access those one by one it will look 
something like this right?

char **A;
strlen(*(A+N));

such code is not matched as far as I see.


Repository:
  rL LLVM

https://reviews.llvm.org/D32346



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


[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-04-24 Thread Ben Craig via Phabricator via cfe-commits
bcraig added a comment.

In https://reviews.llvm.org/D32411#735128, @halyavin wrote:

> BTW, the list of include files which are located in [PROGRAM_FILES]\Microsoft 
> Visual Studio 14.0\VC\include directory is
>
> - stdbool.h
> - limits.h
> - stdint.h
> - setjmp.h
>
>   The rest is in [PROGRAM_FILES]\Windows Kits\10\Include\10.0.whatever.0\ucrt 
> directory. Which directory @_LIBCPP_INCLUDE_NEXT@ is supposed to point to?


My immediate goal is getting a sort-of freestanding implementation of libc++ to 
work in the Windows kernel.  That means that I have _LIBCPP_INCLUDE_NEXT 
defined as ../../km/crt.

I'll have to stew on what I want the solution to this to be.  I don't feel bad 
at all switching between one compiler extension (#include_next) and another 
(computed includes).  I would feel a little bad cooking in more knowledge of 
the MSVC directory layout though.  Maybe that's just the cost to pay though.  
There is some pretty deep knowledge of glibc headers in libc++, so it wouldn't 
be terribly unusual to have similar knowledge of the MSVC CRT.

The errno changes you are suggesting may be fine, but I wasn't planning on 
addressing them with this patch.


https://reviews.llvm.org/D32411



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


[PATCH] D32346: [clang-tidy] New readability check for strlen argument

2017-04-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

> In https://reviews.llvm.org/D32346#733906, @Eugene.Zelenko wrote:
> 
>> It may be good idea to add check for arguments which taken from C++ 
>> containers like std::string, std::string_view, etc.
> 
> 
> Not sure how you want. Do you envision something like:
> 
>   std::string Par;
>   strlen(Par.c_str() + 1);

Even strlen(Par.c_str()) will be reasonable.


Repository:
  rL LLVM

https://reviews.llvm.org/D32346



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-04-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1105-1119
+  // Alloca always returns a pointer in alloca address space, which may
+  // be different from the type defined by the language. For example,
+  // in C++ the auto variables are in the default address space. Therefore
+  // cast alloca to the expected address space when necessary.
+  auto Addr = address.getPointer();
+  auto AddrTy = cast(Addr->getType());
+  auto ExpectedAddrSpace = 
CGM.getTypes().getVariableType(D)->getAddressSpace();

yaxunl wrote:
> yaxunl wrote:
> > t-tye wrote:
> > > Is any assert done to ensure that it is legal to address space cast from 
> > > variable address space to expected address space? Presumably the 
> > > language, by definition, will only be causing legal casts. For example 
> > > from alloca address space to generic (which includes the alloca address 
> > > space).
> > > 
> > > For OpenCL, can you explain how the local variable can have the constant 
> > > address space and use an alloca for allocation? Wouldn't a constant 
> > > address space mean it was static and so should not be using alloca? And 
> > > if it is using an alloca, how can it then be accessed as if it was in 
> > > constant address space?
> > If the auto var has address space qualifier specified through 
> > `__attribute__((address_space(n)))`, there is not much we can check in 
> > clang since it is target dependent. We will just emit address space cast 
> > when necessary and let the backend check the validity of the address space 
> > cast.
> > 
> > Otherwise, for OpenCL, we can assert the expected address space is default 
> > (for OpenCL default address space in AST represents private address space 
> > in source language) or constant. For other languages we can assert the 
> > expected address space qualifier is default (no address space qualifier). 
> > It is not convenient to further check whether the emitted LLVM address 
> > space cast instruction is valid since it requires target specific 
> > information, therefore such check is better deferred to the backend.
> > 
> > For OpenCL, currently automatic variable in constant address space is 
> > emitted in private address space. For example, currently Clang does not 
> > diagnose the following code
> > 
> > ```
> > void f(global int* a) {
> >   global int* constant p = a;
> > }
> > 
> > ```
> > Instead, it emits alloca for p, essentially treats it as `global int* const 
> > p`. This seems to be a bug to me (or maybe we can call it a feature? since 
> > there seems no better way to translate this to LLVM IR, or simply diagnose 
> > this as an error). However, this is better addressed by another patch.
> 
> Hi Anastasia,
> 
> Any comments about the automatic variable in constant address space? Thanks.
From the spec s6.5.3 it feels like we should follow the same implementation 
path in Clang for constant AS inside kernel function as local AS. Because 
constant AS objects are essentially global objects.

 Although, we didn't have any issues up to now because const just does the 
trick of optimising the objects out eventually. I am not clear if this creates 
any issue now with your allocation change. It feels though that it should 
probably work fine just as is?


https://reviews.llvm.org/D32248



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


[PATCH] D32346: [clang-tidy] New readability check for strlen argument

2017-04-24 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added inline comments.



Comment at: test/clang-tidy/readability-strlen-argument.cpp:11
+  X = strlen(Str + 10);
+  // CHECK-FIXES: {{^}}  X = (strlen(Str) - 10);{{$}}
+

but if any of the first ten chars in Str can be NUL, then the change is bogus?  
(I guess I fail to see the reason for this check)


Repository:
  rL LLVM

https://reviews.llvm.org/D32346



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


r301180 - [index] The relation between the declarations in template specializations

2017-04-24 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon Apr 24 09:04:58 2017
New Revision: 301180

URL: http://llvm.org/viewvc/llvm-project?rev=301180&view=rev
Log:
[index] The relation between the declarations in template specializations
that 'override' declarations in the base template should be recorded

This can be used for improved "go to definition" feature in Xcode.

rdar://31604739

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

Modified:
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/lib/Index/IndexingContext.cpp
cfe/trunk/lib/Index/IndexingContext.h
cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=301180&r1=301179&r2=301180&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Mon Apr 24 09:04:58 2017
@@ -144,6 +144,53 @@ public:
 return true;
   }
 
+  /// Gather the declarations which the given declaration \D overrides in a
+  /// pseudo-override manner.
+  ///
+  /// Pseudo-overrides occur when a class template specialization declares
+  /// a declaration that has the same name as a similar declaration in the
+  /// non-specialized template.
+  void
+  gatherTemplatePseudoOverrides(const NamedDecl *D,
+SmallVectorImpl &Relations) {
+if (!IndexCtx.getLangOpts().CPlusPlus)
+  return;
+const auto *CTSD =
+dyn_cast(D->getLexicalDeclContext());
+if (!CTSD)
+  return;
+llvm::PointerUnion
+Template = CTSD->getSpecializedTemplateOrPartial();
+if (const auto *CTD = Template.dyn_cast()) {
+  const CXXRecordDecl *Pattern = CTD->getTemplatedDecl();
+  bool TypeOverride = isa(D);
+  for (const NamedDecl *ND : Pattern->lookup(D->getDeclName())) {
+if (const auto *CTD = dyn_cast(ND))
+  ND = CTD->getTemplatedDecl();
+if (ND->isImplicit())
+  continue;
+// Types can override other types.
+if (!TypeOverride) {
+  if (ND->getKind() != D->getKind())
+continue;
+} else if (!isa(ND))
+  continue;
+if (const auto *FD = dyn_cast(ND)) {
+  const auto *DFD = cast(D);
+  // Function overrides are approximated using the number of 
parameters.
+  if (FD->getStorageClass() != DFD->getStorageClass() ||
+  FD->getNumParams() != DFD->getNumParams())
+continue;
+}
+Relations.emplace_back(
+SymbolRoleSet(SymbolRole::RelationOverrideOf) |
+SymbolRoleSet(SymbolRole::RelationSpecializationOf),
+ND);
+  }
+}
+  }
+
   bool VisitFunctionDecl(const FunctionDecl *D) {
 if (D->isDeleted())
   return true;
@@ -158,6 +205,7 @@ public:
 Relations.emplace_back((unsigned)SymbolRole::RelationOverrideOf, *I);
   }
 }
+gatherTemplatePseudoOverrides(D, Relations);
 
 TRY_DECL(D, IndexCtx.handleDecl(D, Roles, Relations));
 handleDeclarator(D);
@@ -194,14 +242,18 @@ public:
   }
 
   bool VisitVarDecl(const VarDecl *D) {
-TRY_DECL(D, IndexCtx.handleDecl(D));
+SmallVector Relations;
+gatherTemplatePseudoOverrides(D, Relations);
+TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
 handleDeclarator(D);
 IndexCtx.indexBody(D->getInit(), D);
 return true;
   }
 
   bool VisitFieldDecl(const FieldDecl *D) {
-TRY_DECL(D, IndexCtx.handleDecl(D));
+SmallVector Relations;
+gatherTemplatePseudoOverrides(D, Relations);
+TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
 handleDeclarator(D);
 if (D->isBitField())
   IndexCtx.indexBody(D->getBitWidth(), D);
@@ -233,7 +285,9 @@ public:
 
   bool VisitTypedefNameDecl(const TypedefNameDecl *D) {
 if (!D->isTransparentTag()) {
-  TRY_DECL(D, IndexCtx.handleDecl(D));
+  SmallVector Relations;
+  gatherTemplatePseudoOverrides(D, Relations);
+  TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
   IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D);
 }
 return true;
@@ -243,7 +297,9 @@ public:
 // Non-free standing tags are handled in indexTypeSourceInfo.
 if (D->isFreeStanding()) {
   if (D->isThisDeclarationADefinition()) {
-IndexCtx.indexTagDecl(D);
+SmallVector Relations;
+gatherTemplatePseudoOverrides(D, Relations);
+IndexCtx.indexTagDecl(D, Relations);
   } else {
 auto *Parent = dyn_cast(D->getDeclContext());
 return IndexCtx.handleReference(D, D->getLocation(), Parent,

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=301180&r1=301179&r2=301180&view=diff
==
--- cfe/trunk/lib/Index/IndexingContext.c

[PATCH] D32020: [indexer] The relationship between the declarations in template specializations that 'override' declarations in the base template should be recorded

2017-04-24 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301180: [index] The relation between the declarations in 
template specializations (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D32020?vs=95940&id=96396#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32020

Files:
  cfe/trunk/lib/Index/IndexDecl.cpp
  cfe/trunk/lib/Index/IndexingContext.cpp
  cfe/trunk/lib/Index/IndexingContext.h
  cfe/trunk/test/Index/Core/index-source.cpp

Index: cfe/trunk/test/Index/Core/index-source.cpp
===
--- cfe/trunk/test/Index/Core/index-source.cpp
+++ cfe/trunk/test/Index/Core/index-source.cpp
@@ -111,3 +111,112 @@
 class PartialSpecilizationClass { };
 // CHECK: [[@LINE-1]]:7 | class(Gen,TS)/C++ | PartialSpecilizationClass | c:@S@PartialSpecilizationClass>#I#I |  | Def,RelSpecialization | rel: 1
 // CHECK-NEXT: RelSpecialization | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass
+
+template
+class PseudoOverridesInSpecializations {
+  void function() { }
+  void function(int) { }
+
+  static void staticFunction() { }
+
+  int field;
+  static int variable;
+
+  typedef T TypeDef;
+  using TypeAlias = T;
+
+  enum anEnum { };
+
+  struct Struct { };
+  union Union { };
+
+  using TypealiasOrRecord = void;
+
+  template struct InnerTemplate { };
+  template struct InnerTemplate  { };
+};
+
+template<>
+class PseudoOverridesInSpecializations {
+  void function() { }
+// CHECK: [[@LINE-1]]:8 | instance-method/C++ | function | c:@S@PseudoOverridesInSpecializations>#d#I@F@function# | __ZN32PseudoOverridesInSpecializationsIdiE8functionEv | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | function | c:@ST>2#T#T@PseudoOverridesInSpecializations@F@function#
+
+  void staticFunction() { }
+// CHECK: [[@LINE-1]]:8 | instance-method/C++ | staticFunction | c:@S@PseudoOverridesInSpecializations>#d#I@F@staticFunction# | __ZN32PseudoOverridesInSpecializationsIdiE14staticFunctionEv | Def,RelChild | rel: 1
+// CHECK-NOT: RelOver
+
+  int notOverridingField = 0;
+
+// CHECK-LABEL: checLabelBreak
+  int checLabelBreak = 0;
+
+  int field = 0;
+// CHECK: [[@LINE-1]]:7 | field/C++ | field | c:@S@PseudoOverridesInSpecializations>#d#I@FI@field |  | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | field | c:@ST>2#T#T@PseudoOverridesInSpecializations@FI@field
+
+  static double variable;
+// CHECK: [[@LINE-1]]:17 | static-property/C++ | variable | c:@S@PseudoOverridesInSpecializations>#d#I@variable | __ZN32PseudoOverridesInSpecializationsIdiE8variableE | Decl,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | variable | c:@ST>2#T#T@PseudoOverridesInSpecializations@variable
+
+  typedef double TypeDef;
+// CHECK: [[@LINE-1]]:18 | type-alias/C | TypeDef | c:index-source.cpp@S@PseudoOverridesInSpecializations>#d#I@T@TypeDef |  | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | TypeDef | c:index-source.cpp@ST>2#T#T@PseudoOverridesInSpecializations@T@TypeDef
+
+  using TypeAlias = int;
+// CHECK: [[@LINE-1]]:9 | type-alias/C++ | TypeAlias | c:@S@PseudoOverridesInSpecializations>#d#I@TypeAlias |  | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | TypeAlias | c:@ST>2#T#T@PseudoOverridesInSpecializations@TypeAlias
+
+  enum anEnum { };
+// CHECK: [[@LINE-1]]:8 | enum/C | anEnum | c:@S@PseudoOverridesInSpecializations>#d#I@E@anEnum |  | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | anEnum | c:@ST>2#T#T@PseudoOverridesInSpecializations@E@anEnum
+  class Struct { };
+// CHECK: [[@LINE-1]]:9 | class/C++ | Struct | c:@S@PseudoOverridesInSpecializations>#d#I@S@Struct |  | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | Struct | c:@ST>2#T#T@PseudoOverridesInSpecializations@S@Struct
+  union Union { };
+// CHECK: [[@LINE-1]]:9 | union/C | Union | c:@S@PseudoOverridesInSpecializations>#d#I@U@Union |  | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | Union | c:@ST>2#T#T@PseudoOverridesInSpecializations@U@Union
+
+  struct TypealiasOrRecord { };
+// CHECK: [[@LINE-1]]:10 | struct/C | TypealiasOrRecord | c:@S@PseudoOverridesInSpecializations>#d#I@S@TypealiasOrRecord |  | Def,RelChild,RelOver,RelSpecialization | rel: 2
+// CHECK-NEXT: RelChild
+// CHECK-NEXT: RelOver,RelSpecialization | TypealiasOrRecord | c:@ST>2#T#T@PseudoOverridesInSpecializations@TypealiasOrRecord
+
+  template struct InnerTemplate { };
+// CHECK: [[@LINE-1]]:31 | struct(Gen)/C++ | InnerTemplate | c:@S@PseudoOverr

[PATCH] D31646: [coroutines] Build GRO declaration and return GRO statement

2017-04-24 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

barely audible ping for coroutines


https://reviews.llvm.org/D31646



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


[PATCH] D31608: [coroutines] Add emission of initial and final suspends

2017-04-24 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

Tiny ping


https://reviews.llvm.org/D31608



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


[PATCH] D32428: Fix for Itanium mangler issue with templates (bug: 31405)

2017-04-24 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

LGTM


https://reviews.llvm.org/D32428



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-04-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1115
+  if (AddrTy->getAddressSpace() != ExpectedAddrSpace &&
+  Ty.getAddressSpace() != LangAS::opencl_constant) {
+address = Address(Builder.CreateAddrSpaceCast(Addr,

Do you need to check this? I thought your change doesn't affect OpenCL because 
alloca AS == private AS in OpenCL  and constant AS local objects are treated as 
private const objects anyways.



Comment at: test/CodeGen/address-space.c:3
 // RUN: %clang_cc1 -triple amdgcn -emit-llvm < %s | FileCheck 
-check-prefixes=CHECK,PIZ %s
 // RUN: %clang_cc1 -triple amdgcn---amdgiz -emit-llvm < %s | FileCheck 
-check-prefixes=CHeCK,GIZ %s
 

CHeCK -> CHECK



Comment at: test/CodeGenCXX/amdgcn-automatic-variable.cpp:25
+  // CHECK: store i32 2, i32* %[[r1]]
+  int lv1;
+  lv1 = 1;

I am wondering if all these different test cases are really needed. Are we 
testing any different program paths from the patch?

Also would it make sense to add a test case with an object in an AS different 
to 0 (i.e. with `__attribute__((address_space(n)))`)


https://reviews.llvm.org/D32248



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


[PATCH] D32346: [clang-tidy] New readability check for strlen argument

2017-04-24 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/readability-strlen-argument.cpp:1
+// RUN: %check_clang_tidy %s readability-strlen-argument %t
+

danielmarjamaki wrote:
> JonasToth wrote:
> > Same as documentation, maybe a little more telling examples to test on.
> > What happens with `char**`, an array of strings? Accessing those one by one 
> > would be possible with an addition or subscriptoperation.
> how do you mean with char**. If you access those one by one it will look 
> something like this right?
> 
> char **A;
> strlen(*(A+N));
> 
> such code is not matched as far as I see.
Iam not sure if I understood the goal of the check.
For me, it looks like the determination of the length of a substring, say we 
skip the first 10 characters, who long would the end still be.

your example is correctly what i thought of and i think as well it would not be 
matched .

```strlen(A+N)``` would not compile? The types do not match, but could there 
weird things happen?



Comment at: test/clang-tidy/readability-strlen-argument.cpp:11
+  X = strlen(Str + 10);
+  // CHECK-FIXES: {{^}}  X = (strlen(Str) - 10);{{$}}
+

sberg wrote:
> but if any of the first ten chars in Str can be NUL, then the change is 
> bogus?  (I guess I fail to see the reason for this check)
intersting point. If the Array holds a long list of string concatenated and 
seperated by `0`, the offsetting would be a valid usecase.
(are strings in programm executables stored like this?)

But i have no idea if that is actually a scenario. usually i use `std::string` 
:)


Repository:
  rL LLVM

https://reviews.llvm.org/D32346



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


r301182 - clang-format: Fix bad corner case in formatting of function types.

2017-04-24 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Apr 24 09:28:49 2017
New Revision: 301182

URL: http://llvm.org/viewvc/llvm-project?rev=301182&view=rev
Log:
clang-format: Fix bad corner case in formatting of function types.

Before:
  std::function<
  LngTemplatedType*(
  LongType
  type)>
  function;

After:
  std::function<
  LngTemplatedType<
  SomeType>*(
  LongType type)>
  function;

clang-format generally avoids having lines like "SomeType>*(" as they
lead to parameter lists that don't belong together to be aligned. However, in
case it is better than the alternative, which can even be violating the column
limit.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=301182&r1=301181&r2=301182&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Apr 24 09:28:49 2017
@@ -792,7 +792,8 @@ unsigned ContinuationIndenter::moveState
 if (Previous && Previous->is(tok::question))
   State.Stack.back().QuestionColumn = State.Column;
   }
-  if (!Current.opensScope() && !Current.closesScope())
+  if (!Current.opensScope() && !Current.closesScope() &&
+  !Current.is(TT_PointerOrReference))
 State.LowestLevelOnLine =
 std::min(State.LowestLevelOnLine, Current.NestingLevel);
   if (Current.isMemberAccess())

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=301182&r1=301181&r2=301182&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 24 09:28:49 2017
@@ -5221,6 +5221,12 @@ TEST_F(FormatTest, FormatsFunctionTypes)
   verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }");
   verifyFormat("int x = f(&h)();");
   verifyFormat("returnsFunction(¶m1, ¶m2)(param);");
+  verifyFormat("std::function<\n"
+   "LooongTemplatedType<\n"
+   "SomeType>*(\n"
+   "LongType type)>\n"
+   "function;",
+   getGoogleStyleWithColumns(40));
 }
 
 TEST_F(FormatTest, FormatsPointersToArrayTypes) {


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


[PATCH] D31814: Add option to add command-line options and version info to output file

2017-04-24 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:4222
+  std::string line;
+  while (std::getline(iss, s, ';')) {
+if ((s.length() + line.length()) < 80) {

I wonder if this also works if the original compiler invokation included a ";" 
? Something like (in a Unix like shell)

```
clang -DFOO="\";\"" -c file.c
```


https://reviews.llvm.org/D31814



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


[PATCH] D31542: [clang-tidy] Extend readability-container-size-empty to add comparisons to newly-constructed objects

2017-04-24 Thread Josh Zimmerman via Phabricator via cfe-commits
joshz added a comment.

In https://reviews.llvm.org/D31542#734809, @aaron.ballman wrote:

> In https://reviews.llvm.org/D31542#734455, @joshz wrote:
>
> > Are there any further changes I should make, or is this good to submit now?
> >
> > Thanks!
>
>
> This still LGTM, so it's good to submit. Do you still need someone to land 
> the patch for you?


I don't have commit access, so that would be great.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D31542



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


[PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.

https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/ makes it 
sound like this is similar to -pedantic, which we currently don't expose from 
clang-cl. So map it to that for now and see how that feels in practice.

Looks like cl.exe only has a flag for /permissive-, but no explicit flag for 
/permissive (the default).


https://reviews.llvm.org/D32435

Files:
  include/clang/Driver/CLCompatOptions.td
  test/Driver/cl-options.c


Index: test/Driver/cl-options.c
===
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -180,6 +180,9 @@
 // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- -### -- %s 2>&1 | 
FileCheck -check-prefix=Oy_ %s
 // Oy_: -mdisable-fp-elim
 
+// RUN: %clang_cl /permissive- --target=i686-pc-windows-msvc -### -- %s 2>&1 | 
FileCheck -check-prefix=permissive_ %s
+// permissive_: -pedantic
+
 // RUN: %clang_cl /Qvec -### -- %s 2>&1 | FileCheck -check-prefix=Qvec %s
 // Qvec: -vectorize-loops
 
Index: include/clang/Driver/CLCompatOptions.td
===
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -111,6 +111,8 @@
   AliasArgs<["s"]>;
 def _SLASH_Ot : CLFlag<"Ot">, HelpText<"Optimize for speed">, Alias,
   AliasArgs<["2"]>;
+def _SLASH_permissive_ : CLFlag<"permissive-">, Alias,
+  HelpText<"Diagnose use of nonstandard language extensions">;
 def _SLASH_QUESTION : CLFlag<"?">, Alias,
   HelpText<"Display available options">;
 def _SLASH_Qvec : CLFlag<"Qvec">,


Index: test/Driver/cl-options.c
===
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -180,6 +180,9 @@
 // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- -### -- %s 2>&1 | FileCheck -check-prefix=Oy_ %s
 // Oy_: -mdisable-fp-elim
 
+// RUN: %clang_cl /permissive- --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=permissive_ %s
+// permissive_: -pedantic
+
 // RUN: %clang_cl /Qvec -### -- %s 2>&1 | FileCheck -check-prefix=Qvec %s
 // Qvec: -vectorize-loops
 
Index: include/clang/Driver/CLCompatOptions.td
===
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -111,6 +111,8 @@
   AliasArgs<["s"]>;
 def _SLASH_Ot : CLFlag<"Ot">, HelpText<"Optimize for speed">, Alias,
   AliasArgs<["2"]>;
+def _SLASH_permissive_ : CLFlag<"permissive-">, Alias,
+  HelpText<"Diagnose use of nonstandard language extensions">;
 def _SLASH_QUESTION : CLFlag<"?">, Alias,
   HelpText<"Display available options">;
 def _SLASH_Qvec : CLFlag<"Qvec">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r301183 - [index] If the 'external_source_symbol' attribute indicates 'Swift' as the language then report it accordingly

2017-04-24 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Mon Apr 24 09:52:00 2017
New Revision: 301183

URL: http://llvm.org/viewvc/llvm-project?rev=301183&view=rev
Log:
[index] If the 'external_source_symbol' attribute indicates 'Swift' as the 
language then report it accordingly

Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/include/clang/Index/IndexSymbol.h
cfe/trunk/lib/Index/IndexSymbol.cpp
cfe/trunk/test/Index/Core/external-source-symbol-attr.m
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=301183&r1=301182&r2=301183&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Mon Apr 24 09:52:00 2017
@@ -5600,7 +5600,8 @@ typedef enum {
   CXIdxEntityLang_None = 0,
   CXIdxEntityLang_C= 1,
   CXIdxEntityLang_ObjC = 2,
-  CXIdxEntityLang_CXX  = 3
+  CXIdxEntityLang_CXX  = 3,
+  CXIdxEntityLang_Swift  = 4
 } CXIdxEntityLanguage;
 
 /**

Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=301183&r1=301182&r2=301183&view=diff
==
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Mon Apr 24 09:52:00 2017
@@ -59,6 +59,7 @@ enum class SymbolLanguage {
   C,
   ObjC,
   CXX,
+  Swift,
 };
 
 /// Language specific sub-kinds.

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=301183&r1=301182&r2=301183&view=diff
==
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Mon Apr 24 09:52:00 2017
@@ -318,6 +318,20 @@ SymbolInfo index::getSymbolInfo(const De
   if (Info.Properties & (unsigned)SymbolProperty::Generic)
 Info.Lang = SymbolLanguage::CXX;
 
+  auto getExternalSymAttr = [](const Decl *D) -> ExternalSourceSymbolAttr* {
+if (auto *attr = D->getAttr())
+  return attr;
+if (auto *dcd = dyn_cast(D->getDeclContext())) {
+  if (auto *attr = dcd->getAttr())
+return attr;
+}
+return nullptr;
+  };
+  if (auto *attr = getExternalSymAttr(D)) {
+if (attr->getLanguage() == "Swift")
+  Info.Lang = SymbolLanguage::Swift;
+  }
+
   return Info;
 }
 
@@ -458,6 +472,7 @@ StringRef index::getSymbolLanguageString
   case SymbolLanguage::C: return "C";
   case SymbolLanguage::ObjC: return "ObjC";
   case SymbolLanguage::CXX: return "C++";
+  case SymbolLanguage::Swift: return "Swift";
   }
   llvm_unreachable("invalid symbol language kind");
 }

Modified: cfe/trunk/test/Index/Core/external-source-symbol-attr.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/external-source-symbol-attr.m?rev=301183&r1=301182&r2=301183&view=diff
==
--- cfe/trunk/test/Index/Core/external-source-symbol-attr.m (original)
+++ cfe/trunk/test/Index/Core/external-source-symbol-attr.m Mon Apr 24 09:52:00 
2017
@@ -14,20 +14,20 @@ GEN_DECL("some_module")
 
 EXT_DECL("some_module")
 @interface I2
-// CHECK: [[@LINE-1]]:12 | class/ObjC | I2 | c:@M@some_module@objc(cs)I2 | 
{{.*}} | Decl | rel: 0
+// CHECK: [[@LINE-1]]:12 | class/Swift | I2 | c:@M@some_module@objc(cs)I2 | 
{{.*}} | Decl | rel: 0
 -(void)method;
-// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | method | 
c:@M@some_module@objc(cs)I2(im)method | -[I2 method] | Decl,Dyn,RelChild | rel: 
1
+// CHECK: [[@LINE-1]]:8 | instance-method/Swift | method | 
c:@M@some_module@objc(cs)I2(im)method | -[I2 method] | Decl,Dyn,RelChild | rel: 
1
 @end
 
 void test1(I1 *o) {
-// CHECK: [[@LINE-1]]:12 | class/ObjC | I1 | c:@M@some_module@objc(cs)I1 |
+// CHECK: [[@LINE-1]]:12 | class/Swift | I1 | c:@M@some_module@objc(cs)I1 |
   [o method];
-  // CHECK: [[@LINE-1]]:6 | instance-method/ObjC | method | 
c:@M@some_module@objc(cs)I1(im)method |
+  // CHECK: [[@LINE-1]]:6 | instance-method/Swift | method | 
c:@M@some_module@objc(cs)I1(im)method |
 }
 
 EXT_DECL("some_module")
 @protocol ExtProt
-// CHECK: [[@LINE-1]]:11 | protocol/ObjC | ExtProt | 
c:@M@some_module@objc(pl)ExtProt |
+// CHECK: [[@LINE-1]]:11 | protocol/Swift | ExtProt | 
c:@M@some_module@objc(pl)ExtProt |
 @end
 
 @interface I1(cat)
@@ -38,9 +38,9 @@ EXT_DECL("some_module")
 
 EXT_DECL("cat_module")
 @interface I1(cat2)
-// CHECK: [[@LINE-1]]:15 | extension/ObjC | cat2 | 
c:@CM@cat_module@some_module@objc(cy)I1@cat2 |
+// CHECK: [[@LINE-1]]:15 | extension/Swift | cat2 | 
c:@CM@cat_module@some_module@objc(cy)I1@cat2 |
 -(void)cat_method2;
-// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | cat_method2 | 
c:@CM@cat_module@

[clang-tools-extra] r301185 - Extend readability-container-size-empty to add comparisons to empty-state objects.

2017-04-24 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Mon Apr 24 09:57:09 2017
New Revision: 301185

URL: http://llvm.org/viewvc/llvm-project?rev=301185&view=rev
Log:
Extend readability-container-size-empty to add comparisons to empty-state 
objects.

Patch by Josh Zimmerman.

Modified:
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=301185&r1=301184&r2=301185&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
Mon Apr 24 09:57:09 2017
@@ -7,6 +7,7 @@
 //
 
//===--===//
 #include "ContainerSizeEmptyCheck.h"
+#include "../utils/ASTUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -19,6 +20,8 @@ namespace clang {
 namespace tidy {
 namespace readability {
 
+using utils::IsBinaryOrTernary;
+
 ContainerSizeEmptyCheck::ContainerSizeEmptyCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context) {}
@@ -62,23 +65,70 @@ void ContainerSizeEmptyCheck::registerMa
 ofClass(equalsBoundNode("container"))
   .bind("SizeCallExpr"),
   this);
+
+  // Empty constructor matcher.
+  const auto DefaultConstructor = cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(isDefaultConstructor(;
+  // Comparison to empty string or empty constructor.
+  const auto WrongComparend = anyOf(
+  ignoringImpCasts(stringLiteral(hasSize(0))),
+  ignoringImpCasts(cxxBindTemporaryExpr(has(DefaultConstructor))),
+  ignoringImplicit(DefaultConstructor),
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
+  has(expr(ignoringImpCasts(DefaultConstructor,
+  cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(isMoveConstructor())),
+  has(expr(ignoringImpCasts(DefaultConstructor);
+  // Match the object being compared.
+  const auto STLArg =
+  anyOf(unaryOperator(
+hasOperatorName("*"),
+hasUnaryOperand(
+expr(hasType(pointsTo(ValidContainer))).bind("Pointee"))),
+expr(hasType(ValidContainer)).bind("STLObject"));
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  anyOf(hasOverloadedOperatorName("=="),
+hasOverloadedOperatorName("!=")),
+  anyOf(allOf(hasArgument(0, WrongComparend), hasArgument(1, STLArg)),
+allOf(hasArgument(0, STLArg), hasArgument(1, WrongComparend))),
+  unless(hasAncestor(
+  cxxMethodDecl(ofClass(equalsBoundNode("container"))
+  .bind("BinCmp"),
+  this);
 }
 
 void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *MemberCall =
   Result.Nodes.getNodeAs("SizeCallExpr");
+  const auto *BinCmp = Result.Nodes.getNodeAs("BinCmp");
   const auto *BinaryOp = 
Result.Nodes.getNodeAs("SizeBinaryOp");
-  const auto *E = MemberCall->getImplicitObjectArgument();
+  const auto *Pointee = Result.Nodes.getNodeAs("Pointee");
+  const auto *E =
+  MemberCall
+  ? MemberCall->getImplicitObjectArgument()
+  : (Pointee ? Pointee : Result.Nodes.getNodeAs("STLObject"));
   FixItHint Hint;
   std::string ReplacementText =
   Lexer::getSourceText(CharSourceRange::getTokenRange(E->getSourceRange()),
*Result.SourceManager, getLangOpts());
+  if (BinCmp && IsBinaryOrTernary(E)) {
+// Not just a DeclRefExpr, so parenthesize to be on the safe side.
+ReplacementText = "(" + ReplacementText + ")";
+  }
   if (E->getType()->isPointerType())
 ReplacementText += "->empty()";
   else
 ReplacementText += ".empty()";
 
-  if (BinaryOp) { // Determine the correct transformation.
+  if (BinCmp) {
+if (BinCmp->getOperator() == OO_ExclaimEqual) {
+  ReplacementText = "!" + ReplacementText;
+}
+Hint =
+FixItHint::CreateReplacement(BinCmp->getSourceRange(), 
ReplacementText);
+  } else if (BinaryOp) {  // Determine the correct transformation.
 bool Negation = false;
 const bool ContainerIsLHS =
 !llvm::isa(BinaryOp->getLHS()->IgnoreImpCasts());
@@ -148,9 +198,17 @@ void ContainerSizeEmptyCheck::check(cons
   "!" + ReplacementText);
   }
 
-  diag(MemberCall->getLoc

[PATCH] D31542: [clang-tidy] Extend readability-container-size-empty to add comparisons to newly-constructed objects

2017-04-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit in r301185, thank you!


Repository:
  rL LLVM

https://reviews.llvm.org/D31542



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


[PATCH] D32436: [clang-tidy] Support detecting for-range loop in inefficient-vector-operation check.

2017-04-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.

Also add an option "VectorLikeClasses" allowing user specify customized
vectors.


https://reviews.llvm.org/D32436

Files:
  clang-tidy/performance/InefficientVectorOperationCheck.cpp
  clang-tidy/performance/InefficientVectorOperationCheck.h
  docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
  test/clang-tidy/performance-inefficient-vector-operation.cpp

Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- test/clang-tidy/performance-inefficient-vector-operation.cpp
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -1,9 +1,27 @@
-// RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- -format-style=llvm --
+// RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- -format-style=llvm -- --std=c++11
 
 namespace std {
 
 typedef int size_t;
 
+template class initializer_list {
+public:
+  using value_type = E;
+  using reference = E&;
+  using const_reference = const E&;
+  using size_type = size_t;
+  using iterator = const E*;
+  using const_iterator = const E*;
+  initializer_list();
+  size_t size() const; // number of elements
+  const E* begin() const; // first element
+  const E* end() const; // one past the last element
+};
+
+// initializer list range access
+template const E* begin(initializer_list il);
+template const E* end(initializer_list il);
+
 template 
 class vector {
  public:
@@ -23,9 +41,24 @@
   size_t size();
   const_reference operator[] (size_type) const;
   reference operator[] (size_type);
+
+  const_iterator begin() const;
+  const_iterator end() const;
 };
 } // namespace std
 
+class Foo {
+ public:
+  explicit Foo(int);
+};
+
+class Bar {
+ public:
+  Bar(int);
+};
+
+int Op(int);
+
 void f(std::vector& t) {
   {
 std::vector v;
@@ -85,7 +118,38 @@
   v.push_back(t[i]);
 } // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
   }
-
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (const auto &e : t) {
+  v.push_back(e);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (const auto &e : t) {
+  v.push_back(Op(e));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (const auto &e : t) {
+  v.push_back(Foo(e));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (const auto &e : t) {
+  v.push_back(e);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
+}
+  }
   //  Non-fixed Cases 
   {
 std::vector v;
@@ -181,4 +245,21 @@
   v.push_back(t[i]);
 }
   }
+  {
+std::vector v;
+// initializer_list should not trigger the check.
+for (int e : {1, 2, 3, 4, 5}) {
+  v.push_back(e);
+}
+  }
+  {
+std::vector v;
+std::vector* v2 = &t;
+// We only support detecting the range init expression which references
+// container directly.
+// Complex range init expressions like `*v2` is not supported.
+for (const auto &e : *v2) {
+  v.push_back(e);
+}
+  }
 }
Index: docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
===
--- docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
+++ docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
@@ -6,8 +6,10 @@
 Finds possible inefficient `std::vector` operations (e.g. `push_back`) that may
 cause unnecessary memory reallocations.
 
-Currently, the check only detects a typical counter-based for loop with a single
-statement in it, see below:
+Currently, the check only detects following kinds of loops with a single
+statement body:
+
+* Counter-based for loops start with 0:
 
 .. code-block:: c++
 
@@ -18,3 +20,29 @@
 // memory reallocations in v. This can be avoid by inserting a 'reserve(n)'
 // statment before the for statment.
   }
+
+
+* For-range loops like `for (range-declaration : range_expression)`, the type of
+  `range_expression` can be `std::vector`, `std::array`, `std::dequeue`,
+  `std::set`, `std::unordered_set`, `std::map`, `std::unordered_set`:
+
+.. code-block:: c++
+
+  std::vector data;
+  std::vector v;
+
+  for (auto element : data) {
+v.push_back(element);
+// This will trigger the warning since the 'push_back' may cause multiple
+// memory reallocations in v. This can be avoid by inserting a
+// 'reserve(data.size())' statment before the for statment.
+  }
+
+
+Options
+---
+
+.. option:: VectorLikeClasses
+
+   Semicolon-separated list of names of vector-like classes. By default only
+   ``::std::vector`` is considered.
Ind

[PATCH] D32437: [analyzer] Nullability: fix a crash when adding notes inside a synthesized property accessor.

2017-04-24 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.

In this test case, the body of a property is autosynthesized, and its source 
locations are invalid. Path diagnostic locations must refer to valid source 
locations, hence we're hitting an assertion. This patch disables the 
bugvisitor's note, however we'd need to figure out where to stick it 
eventually. These new "extra notes" of mine might be useful (we could put them 
at property declaration), i could add them if everybody likes this idea.


https://reviews.llvm.org/D32437

Files:
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  test/Analysis/nullability.mm


Index: test/Analysis/nullability.mm
===
--- test/Analysis/nullability.mm
+++ test/Analysis/nullability.mm
@@ -525,3 +525,15 @@
   return nil; // no-warning
 }
 @end
+
+void takesNonnull(NSObject *_Nonnull y);
+
+@interface ClassWithProperties: NSObject
+@property(copy, nullable) NSObject *x;
+-(void) method;
+@end;
+@implementation ClassWithProperties
+-(void) method {
+  takesNonnull(self.x); // expected-warning{{Nullable pointer is passed to a 
callee that requires a non-null 1st parameter}}
+}
+@end
Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -324,6 +324,10 @@
   TrackedNullabPrev->getValue() == TrackedNullab->getValue())
 return nullptr;
 
+  if (N->getLocationContext()->getAnalysisDeclContext()
+ ->isBodyAutosynthesized())
+return nullptr;
+
   // Retrieve the associated statement.
   const Stmt *S = TrackedNullab->getNullabilitySource();
   if (!S) {


Index: test/Analysis/nullability.mm
===
--- test/Analysis/nullability.mm
+++ test/Analysis/nullability.mm
@@ -525,3 +525,15 @@
   return nil; // no-warning
 }
 @end
+
+void takesNonnull(NSObject *_Nonnull y);
+
+@interface ClassWithProperties: NSObject
+@property(copy, nullable) NSObject *x;
+-(void) method;
+@end;
+@implementation ClassWithProperties
+-(void) method {
+  takesNonnull(self.x); // expected-warning{{Nullable pointer is passed to a callee that requires a non-null 1st parameter}}
+}
+@end
Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -324,6 +324,10 @@
   TrackedNullabPrev->getValue() == TrackedNullab->getValue())
 return nullptr;
 
+  if (N->getLocationContext()->getAnalysisDeclContext()
+ ->isBodyAutosynthesized())
+return nullptr;
+
   // Retrieve the associated statement.
   const Stmt *S = TrackedNullab->getNullabilitySource();
   if (!S) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D32435



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


Re: r300523 - Debug Info: Remove special-casing of indirect function argument handling.

2017-04-24 Thread David Blaikie via cfe-commits
\o/ awesome! (I added that "indirect" hack ages ago, unfortunately - one
consolation is that it was worse before: Clang would describe the
parameter's type as "T&" in the DWARF, instead of as "T"... )

On Mon, Apr 17, 2017 at 6:34 PM Adrian Prantl via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: adrian
> Date: Mon Apr 17 20:22:01 2017
> New Revision: 300523
>
> URL: http://llvm.org/viewvc/llvm-project?rev=300523&view=rev
> Log:
> Debug Info: Remove special-casing of indirect function argument handling.
>
> LLVM has changed the semantics of dbg.declare for describing function
> arguments. After this patch a dbg.declare always takes the *address*
> of a variable as the first argument, even if the argument is not an
> alloca.
>
> https://bugs.llvm.org/show_bug.cgi?id=32382
> rdar://problem/31205000
>
> Modified:
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/test/CodeGen/debug-info-vla.c
> cfe/trunk/test/CodeGenCXX/debug-info.cpp
> cfe/trunk/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=300523&r1=300522&r2=300523&view=diff
>
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr 17 20:22:01 2017
> @@ -3466,17 +3466,17 @@ void CGDebugInfo::EmitDeclare(const VarD
>// functions there won't be an implicit param at arg1 and
>// otherwise it is 'self' or 'this'.
>if (isa(VD) && ArgNo && *ArgNo == 1)
> -Flags |= llvm::DINode::FlagObjectPointer;
> -  if (auto *Arg = dyn_cast(Storage))
> -if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() &&
> -!VD->getType()->isPointerType())
> -  Expr.push_back(llvm::dwarf::DW_OP_deref);
> +  Flags |= llvm::DINode::FlagObjectPointer;
>
> +  // Note: Older versions of clang used to emit byval references with an
> extra
> +  // DW_OP_deref, because they referenced the IR arg directly instead of
> +  // referencing an alloca. Newer versions of LLVM don't treat allocas
> +  // differently from other function arguments when used in a dbg.declare.
>auto *Scope = cast(LexicalBlockStack.back());
> -
>StringRef Name = VD->getName();
>if (!Name.empty()) {
>  if (VD->hasAttr()) {
> +  // Here, we need an offset *into* the alloca.
>CharUnits offset = CharUnits::fromQuantity(32);
>Expr.push_back(llvm::dwarf::DW_OP_plus);
>// offset of __forwarding field
> @@ -3488,22 +3488,7 @@ void CGDebugInfo::EmitDeclare(const VarD
>// offset of x field
>offset = CGM.getContext().toCharUnitsFromBits(XOffset);
>Expr.push_back(offset.getQuantity());
> -
> -  // Create the descriptor for the variable.
> -  auto *D = ArgNo
> -? DBuilder.createParameterVariable(Scope,
> VD->getName(),
> -   *ArgNo, Unit,
> Line, Ty)
> -: DBuilder.createAutoVariable(Scope, VD->getName(),
> Unit,
> -  Line, Ty, Align);
> -
> -  // Insert an llvm.dbg.declare into the current block.
> -  DBuilder.insertDeclare(
> -  Storage, D, DBuilder.createExpression(Expr),
> -  llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
> -  Builder.GetInsertBlock());
> -  return;
> -} else if (isa(VD->getType()))
> -  Expr.push_back(llvm::dwarf::DW_OP_deref);
> +}
>} else if (const auto *RT = dyn_cast(VD->getType())) {
>  // If VD is an anonymous union then Storage represents value for
>  // all union fields.
> @@ -3606,8 +3591,7 @@ void CGDebugInfo::EmitDeclareOfBlockDecl
>->getElementOffset(blockInfo.getCapture(VD).getIndex()));
>
>SmallVector addr;
> -  if (isa(Storage))
> -addr.push_back(llvm::dwarf::DW_OP_deref);
> +  addr.push_back(llvm::dwarf::DW_OP_deref);
>addr.push_back(llvm::dwarf::DW_OP_plus);
>addr.push_back(offset.getQuantity());
>if (isByRef) {
> @@ -3633,12 +3617,11 @@ void CGDebugInfo::EmitDeclareOfBlockDecl
>// Insert an llvm.dbg.declare into the current block.
>auto DL =
>llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back(),
> CurInlinedAt);
> +  auto *Expr = DBuilder.createExpression(addr);
>if (InsertPoint)
> -DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr),
> DL,
> -   InsertPoint);
> +DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
>else
> -DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr),
> DL,
> -   Builder.GetInsertBlock());
> +DBuilder.insertDeclare(Storage, D, Expr, DL,
> Builder.GetInsertBlock());
>  }
>
>  void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value
> *AI,
>
> Modified: cfe/trunk/test/CodeGen/deb

[PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread David Majnemer via Phabricator via cfe-commits
majnemer requested changes to this revision.
majnemer added a comment.
This revision now requires changes to proceed.

I don't think this is correct. GDR (of Microsoft) says the behavior is 
different: 
https://www.reddit.com/r/cpp/comments/5dh7j5/visual_c_introduces_permissive_for_conformance/da5fxjj/


https://reviews.llvm.org/D32435



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


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-04-24 Thread Serge Preis via Phabricator via cfe-commits
Serge_Preis created this revision.

This patch fixes incorrect source positions of dependent c'tor initializers 
like in the following code:

template
struct Derived:  MyBase::InnerIterator
{

  Derived() : MyBase::InnerIterator() {}  /// This line is problematic: all 
positions point to InnerIterator and nothing points to MyBase

};

Bug is described at https://bugs.llvm.org/show_bug.cgi?id=26195 in comments. 
The issue affects TypeLoc for 'MyBase', NestedNameSpecifierLoc for 'MyBase' and 
CXXCtorInitializer for MyBase::InnerIterator. Reproducing matcher and source 
codes for bad (dependent name) and good (indepent name) behaviors are attached. 
Reports of bad, good and bad with patch are given in comments for comparison.

The patch basically replicates code found later in routine for 
ElaboratedTypeLoc and adapted to DependentTypeLoc returned from 
CheckTypenameType().


https://reviews.llvm.org/D32439

Files:
  SemaDeclCXX.cpp


Index: SemaDeclCXX.cpp
===
--- SemaDeclCXX.cpp
+++ SemaDeclCXX.cpp
@@ -3767,6 +3767,12 @@
   if (BaseType.isNull())
 return true;
 
+  TInfo = Context.CreateTypeSourceInfo(BaseType);
+  DependentNameTypeLoc TL = 
TInfo->getTypeLoc().castAs();
+  TL.setNameLoc(IdLoc);
+  TL.setElaboratedKeywordLoc(SourceLocation());
+  TL.setQualifierLoc(SS.getWithLocInContext(Context));
+
   R.clear();
   R.setLookupName(MemberOrBase);
 }


Index: SemaDeclCXX.cpp
===
--- SemaDeclCXX.cpp
+++ SemaDeclCXX.cpp
@@ -3767,6 +3767,12 @@
   if (BaseType.isNull())
 return true;
 
+  TInfo = Context.CreateTypeSourceInfo(BaseType);
+  DependentNameTypeLoc TL = TInfo->getTypeLoc().castAs();
+  TL.setNameLoc(IdLoc);
+  TL.setElaboratedKeywordLoc(SourceLocation());
+  TL.setQualifierLoc(SS.getWithLocInContext(Context));
+
   R.clear();
   R.setLookupName(MemberOrBase);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r301188 - [clang-tidy] Some Cleanups for performance-faster-string-find check.

2017-04-24 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Apr 24 11:41:00 2017
New Revision: 301188

URL: http://llvm.org/viewvc/llvm-project?rev=301188&view=rev
Log:
[clang-tidy] Some Cleanups for performance-faster-string-find check.

NFC

Modified:
clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp?rev=301188&r1=301187&r2=301188&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp 
Mon Apr 24 11:41:00 2017
@@ -65,29 +65,19 @@ void FasterStringFindCheck::registerMatc
 
   const auto SingleChar =
   expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal")));
-
   const auto StringFindFunctions =
-  anyOf(hasName("find"), hasName("rfind"), hasName("find_first_of"),
-hasName("find_first_not_of"), hasName("find_last_of"),
-hasName("find_last_not_of"));
-
-  llvm::Optional> IsStringClass;
-
-  for (const auto &ClassName : StringLikeClasses) {
-const auto HasName = hasName(ClassName);
-IsStringClass = IsStringClass ? anyOf(*IsStringClass, HasName) : HasName;
-  }
+  hasAnyName("find", "rfind", "find_first_of", "find_first_not_of",
+ "find_last_of", "find_last_not_of");
 
-  if (IsStringClass) {
-Finder->addMatcher(
-cxxMemberCallExpr(
-callee(functionDecl(StringFindFunctions).bind("func")),
-anyOf(argumentCountIs(1), argumentCountIs(2)),
-hasArgument(0, SingleChar),
-on(expr(hasType(recordDecl(*IsStringClass)),
-unless(hasSubstitutedType(),
-this);
-  }
+  Finder->addMatcher(
+  cxxMemberCallExpr(
+  callee(functionDecl(StringFindFunctions).bind("func")),
+  anyOf(argumentCountIs(1), argumentCountIs(2)),
+  hasArgument(0, SingleChar),
+  on(expr(hasType(recordDecl(hasAnyName(SmallVector(
+  StringLikeClasses.begin(), StringLikeClasses.end(),
+  unless(hasSubstitutedType(),
+  this);
 }
 
 void FasterStringFindCheck::check(const MatchFinder::MatchResult &Result) {


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


r301202 - [Docs] Correct the path to the clang-format-diff.py script to include the clang-format directory.

2017-04-24 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Apr 24 12:39:35 2017
New Revision: 301202

URL: http://llvm.org/viewvc/llvm-project?rev=301202&view=rev
Log:
[Docs] Correct the path to the clang-format-diff.py script to include the 
clang-format directory.

Modified:
cfe/trunk/docs/ClangFormat.rst

Modified: cfe/trunk/docs/ClangFormat.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=301202&r1=301201&r2=301202&view=diff
==
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Mon Apr 24 12:39:35 2017
@@ -162,8 +162,9 @@ Download the latest Visual Studio extens
 Script for patch reformatting
 =
 
-The python script `clang/tools/clang-format-diff.py` parses the output of
-a unified diff and reformats all contained lines with :program:`clang-format`.
+The python script `clang/tools/clang-format/clang-format-diff.py` parses the
+output of a unified diff and reformats all contained lines with
+:program:`clang-format`.
 
 .. code-block:: console
 


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


Re: [PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread Nico Weber via cfe-commits
It does sound pretty similar to me from the blog post. I think this is a
decent place to start from.

On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> majnemer requested changes to this revision.
> majnemer added a comment.
> This revision now requires changes to proceed.
>
> I don't think this is correct. GDR (of Microsoft) says the behavior is
> different: https://www.reddit.com/r/cpp/comments/5dh7j5/visual_c_
> introduces_permissive_for_conformance/da5fxjj/
>
>
> https://reviews.llvm.org/D32435
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread David Majnemer via cfe-commits
-pedantic means "Issue all the warnings demanded by strict ISO C and ISO
C++; reject all programs that use forbidden extensions, and some other
programs that do not follow ISO C and ISO C++."
I believe it is more akin to -fno-ms-compatibility as it disables
compatibility hacks.

On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber  wrote:

> It does sound pretty similar to me from the blog post. I think this is a
> decent place to start from.
>
> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via cfe-commits"
>  wrote:
>
>> majnemer requested changes to this revision.
>> majnemer added a comment.
>> This revision now requires changes to proceed.
>>
>> I don't think this is correct. GDR (of Microsoft) says the behavior is
>> different: https://www.reddit.com/r/cpp/comments/5dh7j5/visual_c_introd
>> uces_permissive_for_conformance/da5fxjj/
>>
>>
>> https://reviews.llvm.org/D32435
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32406: [Coverage][Windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl (fixes PR32761)

2017-04-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks for your patch! I have a few requests.

First, please split off the SkipCoverageMapping change from this patch. If you 
don't have commit access yet, let me know and I can commit it for you. You can 
also ping Chris L for commit access.

Second, the test can be minimized a bit further. Here's what I got:

  // RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj 
-fprofile-instrument=clang -fdelayed-template-parsing -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only -main-file-name empty-destructor.cpp -o 
- %s




  struct A {



virtual ~A();   



  };







  void PR32761() {  



A a;



  }


https://reviews.llvm.org/D32406



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-04-24 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1105-1119
+  // Alloca always returns a pointer in alloca address space, which may
+  // be different from the type defined by the language. For example,
+  // in C++ the auto variables are in the default address space. Therefore
+  // cast alloca to the expected address space when necessary.
+  auto Addr = address.getPointer();
+  auto AddrTy = cast(Addr->getType());
+  auto ExpectedAddrSpace = 
CGM.getTypes().getVariableType(D)->getAddressSpace();

Anastasia wrote:
> yaxunl wrote:
> > yaxunl wrote:
> > > t-tye wrote:
> > > > Is any assert done to ensure that it is legal to address space cast 
> > > > from variable address space to expected address space? Presumably the 
> > > > language, by definition, will only be causing legal casts. For example 
> > > > from alloca address space to generic (which includes the alloca address 
> > > > space).
> > > > 
> > > > For OpenCL, can you explain how the local variable can have the 
> > > > constant address space and use an alloca for allocation? Wouldn't a 
> > > > constant address space mean it was static and so should not be using 
> > > > alloca? And if it is using an alloca, how can it then be accessed as if 
> > > > it was in constant address space?
> > > If the auto var has address space qualifier specified through 
> > > `__attribute__((address_space(n)))`, there is not much we can check in 
> > > clang since it is target dependent. We will just emit address space cast 
> > > when necessary and let the backend check the validity of the address 
> > > space cast.
> > > 
> > > Otherwise, for OpenCL, we can assert the expected address space is 
> > > default (for OpenCL default address space in AST represents private 
> > > address space in source language) or constant. For other languages we can 
> > > assert the expected address space qualifier is default (no address space 
> > > qualifier). It is not convenient to further check whether the emitted 
> > > LLVM address space cast instruction is valid since it requires target 
> > > specific information, therefore such check is better deferred to the 
> > > backend.
> > > 
> > > For OpenCL, currently automatic variable in constant address space is 
> > > emitted in private address space. For example, currently Clang does not 
> > > diagnose the following code
> > > 
> > > ```
> > > void f(global int* a) {
> > >   global int* constant p = a;
> > > }
> > > 
> > > ```
> > > Instead, it emits alloca for p, essentially treats it as `global int* 
> > > const p`. This seems to be a bug to me (or maybe we can call it a 
> > > feature? since there seems no better way to translate this to LLVM IR, or 
> > > simply diagnose this as an error). However, this is better addressed by 
> > > another patch.
> > 
> > Hi Anastasia,
> > 
> > Any comments about the automatic variable in constant address space? Thanks.
> From the spec s6.5.3 it feels like we should follow the same implementation 
> path in Clang for constant AS inside kernel function as local AS. Because 
> constant AS objects are essentially global objects.
> 
>  Although, we didn't have any issues up to now because const just does the 
> trick of optimising the objects out eventually. I am not clear if this 
> creates any issue now with your allocation change. It feels though that it 
> should probably work fine just as is?
If these __constant locals are required to be const (or are implicitly const?) 
and have constant initializers, it seems to me the implementation obviously 
intended by the spec is that you allocate them statically in the constant 
address space.  It's likely that just implicitly making the variable static in 
Sema, the same way you make it implicitly const, will make IRGen and various 
other parts of the compiler just do the right thing.


https://reviews.llvm.org/D32248



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


r301212 - Flag -fsanitize=fuzzer to enable libfuzzer

2017-04-24 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Apr 24 13:23:24 2017
New Revision: 301212

URL: http://llvm.org/viewvc/llvm-project?rev=301212&view=rev
Log:
Flag -fsanitize=fuzzer to enable libfuzzer

Previously, adding libfuzzer to a project was a multi-step procedure,
involving libfuzzer compilation, linking the library, and specifying
coverage flags.
With this change,libfuzzer can be enabled by adding a single
-fsanitize=fuzzer flag instead.

Added:
cfe/trunk/test/Driver/fuzzer.c
Modified:
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/include/clang/Driver/SanitizerArgs.h
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/lib/Driver/ToolChains/Darwin.h
cfe/trunk/lib/Driver/ToolChains/Linux.cpp

Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=301212&r1=301211&r2=301212&view=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Mon Apr 24 13:23:24 2017
@@ -47,6 +47,9 @@ SANITIZER("kernel-address", KernelAddres
 // MemorySanitizer
 SANITIZER("memory", Memory)
 
+// libFuzzer
+SANITIZER("fuzzer", Fuzzer)
+
 // ThreadSanitizer
 SANITIZER("thread", Thread)
 

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=301212&r1=301211&r2=301212&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Mon Apr 24 13:23:24 2017
@@ -50,6 +50,7 @@ class SanitizerArgs {
   bool needsSharedAsanRt() const { return AsanSharedRuntime; }
   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
+  bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
   bool needsLsanRt() const {
 return Sanitizers.has(SanitizerKind::Leak) &&
!Sanitizers.has(SanitizerKind::Address);

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=301212&r1=301211&r2=301212&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Mon Apr 24 13:23:24 2017
@@ -265,6 +265,10 @@ SanitizerArgs::SanitizerArgs(const ToolC
   Add &= ~InvalidTrappingKinds;
   Add &= Supported;
 
+  // Enable coverage if the fuzzing flag is set.
+  if (Add & Fuzzer)
+CoverageFeatures |= CoverageTracePCGuard | CoverageIndirCall | 
CoverageTraceCmp;
+
   Kinds |= Add;
 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) {
   Arg->claim();

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=301212&r1=301211&r2=301212&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Mon Apr 24 13:23:24 2017
@@ -577,6 +577,17 @@ collectSanitizerRuntimes(const ToolChain
 StaticRuntimes.push_back("esan");
 }
 
+static void addLibFuzzerRuntime(const ToolChain &TC,
+const ArgList &Args,
+ArgStringList &CmdArgs) {
+StringRef ParentDir = 
llvm::sys::path::parent_path(TC.getDriver().InstalledDir);
+SmallString<128> P(ParentDir);
+llvm::sys::path::append(P, "lib", "libLLVMFuzzer.a");
+CmdArgs.push_back(Args.MakeArgString(P));
+TC.AddCXXStdlibLibArgs(Args, CmdArgs);
+}
+
+
 // Should be called before we add system libraries (C++ ABI, libstdc++/libc++,
 // C runtime, etc). Returns true if sanitizer system deps need to be linked in.
 bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
@@ -586,6 +597,11 @@ bool tools::addSanitizerRuntimes(const T
   collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
NonWholeStaticRuntimes, HelperStaticRuntimes,
RequiredSymbols);
+  // Inject libfuzzer dependencies.
+  if (TC.getSanitizerArgs().needsFuzzer()) {
+addLibFuzzerRuntime(TC, Args, CmdArgs);
+  }
+
   for (auto RT : SharedRuntimes)
 addSanitizerRuntime(TC, Args, CmdArgs, RT, true, false);
   for (auto RT : HelperStaticRuntimes)

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=301212&r1=301211&r2=301212&view=diff
=

r301216 - Remove erroneous driver test for -fsanitize=fuzzer flag

2017-04-24 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Apr 24 13:36:31 2017
New Revision: 301216

URL: http://llvm.org/viewvc/llvm-project?rev=301216&view=rev
Log:
Remove erroneous driver test for -fsanitize=fuzzer flag

libfuzzer is not available on all platforms, and hence we can not always
rely that it was compiled.

Modified:
cfe/trunk/test/Driver/fuzzer.c

Modified: cfe/trunk/test/Driver/fuzzer.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuzzer.c?rev=301216&r1=301215&r2=301216&view=diff
==
--- cfe/trunk/test/Driver/fuzzer.c (original)
+++ cfe/trunk/test/Driver/fuzzer.c Mon Apr 24 13:36:31 2017
@@ -15,8 +15,6 @@
 //
 // CHECK-LIBCXX-DARWIN: -lc++
 
-// RUN: %clang -fsanitize=fuzzer %s
-
 int LLVMFuzzerTestOneInput(const char *Data, long Size) {
   return 0;
 }


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


r301218 - Pragma: Fix DebugOverflowStack() resulting in endless loop.

2017-04-24 Thread Matthias Braun via cfe-commits
Author: matze
Date: Mon Apr 24 13:41:00 2017
New Revision: 301218

URL: http://llvm.org/viewvc/llvm-project?rev=301218&view=rev
Log:
Pragma: Fix DebugOverflowStack() resulting in endless loop.

Drive-by fix (noticed while working on https://reviews.llvm.org/D32205):
DebugOverflowStack() is supposed to provoke a stack overflow, however
LLVM was smart enough to use the red-zone and fold the load into a tail
jump on x86_64 optimizing this to an endless loop instead of a stack
overflow.

Modified:
cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=301218&r1=301217&r2=301218&view=diff
==
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Mon Apr 24 13:41:00 2017
@@ -989,9 +989,9 @@ struct PragmaDebugHandler : public Pragm
 #ifdef _MSC_VER
 #pragma warning(disable : 4717)
 #endif
-  static void DebugOverflowStack() {
-void (*volatile Self)() = DebugOverflowStack;
-Self();
+  static void DebugOverflowStack(void (*P)() = nullptr) {
+void (*volatile Self)(void(*P)()) = DebugOverflowStack;
+Self(reinterpret_cast(Self));
   }
 #ifdef _MSC_VER
 #pragma warning(default : 4717)


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


Re: [PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread Nico Weber via cfe-commits
"Opting into the conforming mode, /permissive-, during the series of VS
2017 update is a commitment to keeping your code base clean and to fixing
non-conforming constructs we fix conformance issues in Visual C++." [...]
"By contrast /permissive- offers a useful conformance mode where input C++
code is interpreted according to ISO C++ rules but also allows conforming
extensions necessary to compile C++ on targets supported by Visual C++."

I guess the second quote agrees with your interpretation.

We already diag most of the things they already mention. The one thing we
don't diag by default is Wmicrosoft-enum-forward-reference since that's
only an Extension and not an ExtWarn. We don't expose -pedantic from
clang-cl, so this seemed like a somewhat natural mapping to me.

Should /permissive- map to -Wmicrosoft instead and turn on the parts of
-Wmicrosoft that are Extensions? Should we just ignore /permissive- and
possibly make some of our -Wmicrosoft Extensions ExtWarns instead?

On Mon, Apr 24, 2017 at 2:10 PM, David Majnemer 
wrote:

> -pedantic means "Issue all the warnings demanded by strict ISO C and ISO
> C++; reject all programs that use forbidden extensions, and some other
> programs that do not follow ISO C and ISO C++."
> I believe it is more akin to -fno-ms-compatibility as it disables
> compatibility hacks.
>
> On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber  wrote:
>
>> It does sound pretty similar to me from the blog post. I think this is a
>> decent place to start from.
>>
>> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via
>> cfe-commits"  wrote:
>>
>>> majnemer requested changes to this revision.
>>> majnemer added a comment.
>>> This revision now requires changes to proceed.
>>>
>>> I don't think this is correct. GDR (of Microsoft) says the behavior is
>>> different: https://www.reddit.com/r/cpp/comments/5dh7j5/visual_c_introd
>>> uces_permissive_for_conformance/da5fxjj/
>>>
>>>
>>> https://reviews.llvm.org/D32435
>>>
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32449: Modifying PthreadLockChecker.cpp to reduce false positives.

2017-04-24 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 created this revision.

I am currently working on to avoid false positives which currently occur as the 
return values of mutex functions like pthread_mutex_destroy() are not taken 
into consideration.

The precise description of the bug can be found here: 
https://bugs.llvm.org/show_bug.cgi?id=32455

Dr. Devin and Dr. Artem have been guiding me to fix PthreadLockChecker to avoid 
such false positives. The patch I'm attaching is not 100% correct and hence I 
need your advice to proceed further.

Thank you.


Repository:
  rL LLVM

https://reviews.llvm.org/D32449

Files:
  lib/.DS_Store
  lib/StaticAnalyzer/.DS_Store
  lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp

Index: lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -18,6 +18,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include 
 
 using namespace clang;
 using namespace ento;
@@ -25,7 +26,7 @@
 namespace {
 
 struct LockState {
-  enum Kind { Destroyed, Locked, Unlocked } K;
+  enum Kind { Destroyed, Locked, Unlocked, SchrodingerLocked, SchrodingerUnlocked } K;
 
 private:
   LockState(Kind K) : K(K) {}
@@ -34,6 +35,8 @@
   static LockState getLocked() { return LockState(Locked); }
   static LockState getUnlocked() { return LockState(Unlocked); }
   static LockState getDestroyed() { return LockState(Destroyed); }
+  static LockState getSchrodingerLocked() { return LockState(SchrodingerLocked); }
+  static LockState getSchrodingerUnlocked() { return LockState(SchrodingerUnlocked); }
 
   bool operator==(const LockState &X) const {
 return K == X.K;
@@ -42,13 +45,15 @@
   bool isLocked() const { return K == Locked; }
   bool isUnlocked() const { return K == Unlocked; }
   bool isDestroyed() const { return K == Destroyed; }
+  bool isSchrodingerLocked() const { return K == SchrodingerLocked; }
+  bool isSchrodingerUnlocked() const { return K == SchrodingerUnlocked; }
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddInteger(K);
   }
 };
 
-class PthreadLockChecker : public Checker< check::PostStmt > {
+class PthreadLockChecker : public Checker< check::PostStmt, check::DeadSymbols > {
   mutable std::unique_ptr BT_doublelock;
   mutable std::unique_ptr BT_doubleunlock;
   mutable std::unique_ptr BT_destroylock;
@@ -61,6 +66,7 @@
   };
 public:
   void checkPostStmt(const CallExpr *CE, CheckerContext &C) const;
+  void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
   void AcquireLock(CheckerContext &C, const CallExpr *CE, SVal lock,
bool isTryLock, enum LockingSemantics semantics) const;
@@ -76,6 +82,7 @@
 REGISTER_LIST_WITH_PROGRAMSTATE(LockSet, const MemRegion *)
 
 REGISTER_MAP_WITH_PROGRAMSTATE(LockMap, const MemRegion *, LockState)
+REGISTER_MAP_WITH_PROGRAMSTATE(DestroyRetVal, const MemRegion *, SymbolRef)
 
 void PthreadLockChecker::checkPostStmt(const CallExpr *CE,
CheckerContext &C) const {
@@ -126,10 +133,30 @@
 
   const MemRegion *lockR = lock.getAsRegion();
   if (!lockR)
-return;
+return; 
 
   ProgramStateRef state = C.getState();
 
+  // CHECK THIS
+  const SymbolRef* sym = state->get(lockR);
+  if(sym){
+const LockState* lstate = state->get(lockR);
+if(lstate){
+  ConstraintManager &CMgr = state->getConstraintManager();
+  ConditionTruthVal retZero = CMgr.isNull(state, *sym);
+  if(retZero.isConstrainedFalse()){
+if(lstate->isSchrodingerLocked())
+  state = state->set(lockR, LockState::getLocked());
+else if(lstate->isSchrodingerUnlocked())
+  state = state->set(lockR, LockState::getUnlocked());
+  }
+  else{
+if(!lstate || lstate->isSchrodingerLocked() || lstate->isSchrodingerUnlocked())
+  state = state->set(lockR, LockState::getDestroyed());
+  }
+}
+  }
+
   SVal X = state->getSVal(CE, C.getLocationContext());
   if (X.isUnknownOrUndef())
 return;
@@ -198,6 +225,26 @@
 
   ProgramStateRef state = C.getState();
 
+  // CHECK THIS
+  const SymbolRef* sym = state->get(lockR);
+  if(sym){
+const LockState* lstate = state->get(lockR);
+if(lstate){
+  ConstraintManager &CMgr = state->getConstraintManager();
+  ConditionTruthVal retZero = CMgr.isNull(state, *sym);
+  if(retZero.isConstrainedFalse()){
+if(lstate->isSchrodingerLocked())
+  state = state->set(lockR, LockState::getLocked());
+else if(lstate->isSchrodingerUnlocked())
+  state = state->set(lockR, LockState::getUnlocked());
+  }
+  else{
+if(!lstate || lstate->isSchrodingerLocked() || lstate->isSchrodingerUnlocked())
+  state = state->set(lockR, LockState::getDest

[PATCH] D23796: [libcxx] Make it possible to test static builds of libc++ on OSX

2017-04-24 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath abandoned this revision.
rmaprath added a comment.

Looks like I'm the only one interested in this - abandoning.


https://reviews.llvm.org/D23796



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


[PATCH] D32406: [Coverage][Windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl (fixes PR32761)

2017-04-24 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D32406#735725, @vsk wrote:

> // RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj 
> -fprofile-instrument=clang -fdelayed-template-parsing -fcoverage-mapping 
> -dump-coverage-mapping -emit-llvm-only -main-file-name empty-destructor.cpp 
> -o - %s


This is probably closer to a minimal command line:
`%clang_cc1 -triple i686-windows -emit-llvm-only -fcoverage-mapping 
-dump-coverage-mapping %s`

Is there something we can FileCheck in the IR?


https://reviews.llvm.org/D32406



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


[PATCH] D31856: Headers: Make the type of SIZE_MAX the same as size_t

2017-04-24 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision now requires changes to proceed.

LGTM.


https://reviews.llvm.org/D31856



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


cfe-commits@lists.llvm.org

2017-04-24 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Apr 24 14:30:33 2017
New Revision: 301224

URL: http://llvm.org/viewvc/llvm-project?rev=301224&view=rev
Log:
[analyzer] Improve suppression for inlined defensive checks before operator &.

Null dereferences are suppressed if the lvalue was constrained to 0 for the
first time inside a sub-function that was inlined during analysis, because
such constraint is a valid defensive check that does not, by itself,
indicate that null pointer case is anyhow special for the caller.

If further operations on the lvalue are performed, the symbolic lvalue is
collapsed to concrete null pointer, and we need to track where does the null
pointer come from.

Improve such tracking for lvalue operations involving operator &.

rdar://problem/27876009

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

Added:
cfe/trunk/test/Analysis/null-deref-offsets.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
cfe/trunk/test/Analysis/inlining/inline-defensive-checks.c
cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp
cfe/trunk/test/Analysis/uninit-const.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=301224&r1=301223&r2=301224&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Apr 24 
14:30:33 2017
@@ -961,6 +961,26 @@ bool bugreporter::trackNullOrUndefValue(
   const Expr *Inner = nullptr;
   if (const Expr *Ex = dyn_cast(S)) {
 Ex = Ex->IgnoreParenCasts();
+
+// Performing operator `&' on an lvalue expression is essentially a no-op.
+// Then, if we are taking addresses of fields or elements, these are also
+// unlikely to matter.
+// FIXME: There's a hack in our Store implementation that always computes
+// field offsets around null pointers as if they are always equal to 0.
+// The idea here is to report accesses to fields as null dereferences
+// even though the pointer value that's being dereferenced is actually
+// the offset of the field rather than exactly 0.
+// See the FIXME in StoreManager's getLValueFieldOrIvar() method.
+// This code interacts heavily with this hack; otherwise the value
+// would not be null at all for most fields, so we'd be unable to track it.
+if (const auto *Op = dyn_cast(Ex))
+  if (Op->getOpcode() == UO_AddrOf && Op->getSubExpr()->isLValue()) {
+Ex = Op->getSubExpr()->IgnoreParenCasts();
+while (const auto *ME = dyn_cast(Ex)) {
+  Ex = ME->getBase()->IgnoreParenCasts();
+}
+  }
+
 if (ExplodedGraph::isInterestingLValueExpr(Ex) || 
CallEvent::isCallStmt(Ex))
   Inner = Ex;
   }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp?rev=301224&r1=301223&r2=301224&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp Mon Apr 24 14:30:33 2017
@@ -404,9 +404,15 @@ SVal StoreManager::getLValueFieldOrIvar(
 
   case loc::ConcreteIntKind:
 // While these seem funny, this can happen through casts.
-// FIXME: What we should return is the field offset.  For example,
-//  add the field offset to the integer value.  That way funny things
+// FIXME: What we should return is the field offset, not base. For example,
+//  add the field offset to the integer value.  That way things
 //  like this work properly:  &(((struct foo *) 0xa)->f)
+//  However, that's not easy to fix without reducing our abilities
+//  to catch null pointer dereference. Eg., ((struct foo *)0x0)->f = 7
+//  is a null dereference even though we're dereferencing offset of f
+//  rather than null. Coming up with an approach that computes offsets
+//  over null pointers properly while still being able to catch null
+//  dereferences might be worth it.
 return Base;
 
   default:
@@ -431,7 +437,7 @@ SVal StoreManager::getLValueElement(Qual
   // If the base is an unknown or undefined value, just return it back.
   // FIXME: For absolute pointer addresses, we just return that value back as
   //  well, although in reality we should return the offset added to that
-  //  value.
+  //  value. See also the similar FIXME in getLValueFieldOrIvar().
   if (Base.isUnknownOrUndef() || Base.getAs())
 return Base;
 

Modified: cfe/trunk/test/Analysis/inlining/inline-defensive-checks.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/inline-defensive-checks.c?rev=301224&r1=301223&r2=301224&view=diff
==

[PATCH] D31982: [analyzer] Improve suppression for inlined defensive checks when operator& is involved.

2017-04-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301224: [analyzer] Improve suppression for inlined defensive 
checks before operator &. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D31982?vs=95890&id=96446#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31982

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
  cfe/trunk/test/Analysis/inlining/inline-defensive-checks.c
  cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp
  cfe/trunk/test/Analysis/null-deref-offsets.c
  cfe/trunk/test/Analysis/uninit-const.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -961,6 +961,26 @@
   const Expr *Inner = nullptr;
   if (const Expr *Ex = dyn_cast(S)) {
 Ex = Ex->IgnoreParenCasts();
+
+// Performing operator `&' on an lvalue expression is essentially a no-op.
+// Then, if we are taking addresses of fields or elements, these are also
+// unlikely to matter.
+// FIXME: There's a hack in our Store implementation that always computes
+// field offsets around null pointers as if they are always equal to 0.
+// The idea here is to report accesses to fields as null dereferences
+// even though the pointer value that's being dereferenced is actually
+// the offset of the field rather than exactly 0.
+// See the FIXME in StoreManager's getLValueFieldOrIvar() method.
+// This code interacts heavily with this hack; otherwise the value
+// would not be null at all for most fields, so we'd be unable to track it.
+if (const auto *Op = dyn_cast(Ex))
+  if (Op->getOpcode() == UO_AddrOf && Op->getSubExpr()->isLValue()) {
+Ex = Op->getSubExpr()->IgnoreParenCasts();
+while (const auto *ME = dyn_cast(Ex)) {
+  Ex = ME->getBase()->IgnoreParenCasts();
+}
+  }
+
 if (ExplodedGraph::isInterestingLValueExpr(Ex) || CallEvent::isCallStmt(Ex))
   Inner = Ex;
   }
Index: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
@@ -404,9 +404,15 @@
 
   case loc::ConcreteIntKind:
 // While these seem funny, this can happen through casts.
-// FIXME: What we should return is the field offset.  For example,
-//  add the field offset to the integer value.  That way funny things
+// FIXME: What we should return is the field offset, not base. For example,
+//  add the field offset to the integer value.  That way things
 //  like this work properly:  &(((struct foo *) 0xa)->f)
+//  However, that's not easy to fix without reducing our abilities
+//  to catch null pointer dereference. Eg., ((struct foo *)0x0)->f = 7
+//  is a null dereference even though we're dereferencing offset of f
+//  rather than null. Coming up with an approach that computes offsets
+//  over null pointers properly while still being able to catch null
+//  dereferences might be worth it.
 return Base;
 
   default:
@@ -431,7 +437,7 @@
   // If the base is an unknown or undefined value, just return it back.
   // FIXME: For absolute pointer addresses, we just return that value back as
   //  well, although in reality we should return the offset added to that
-  //  value.
+  //  value. See also the similar FIXME in getLValueFieldOrIvar().
   if (Base.isUnknownOrUndef() || Base.getAs())
 return Base;
 
Index: cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp
===
--- cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp
+++ cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp
@@ -70,4 +70,17 @@
 void test(int *p1, int *p2) {
   idc(p1);
 	Foo f(p1);
-}
\ No newline at end of file
+}
+
+struct Bar {
+  int x;
+};
+void idcBar(Bar *b) {
+  if (b)
+;
+}
+void testRefToField(Bar *b) {
+  idcBar(b);
+  int &x = b->x; // no-warning
+  x = 5;
+}
Index: cfe/trunk/test/Analysis/inlining/inline-defensive-checks.c
===
--- cfe/trunk/test/Analysis/inlining/inline-defensive-checks.c
+++ cfe/trunk/test/Analysis/inlining/inline-defensive-checks.c
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config suppress-inlined-defensive-checks=true -verify %s
 
 // Perform inline defensive checks.
-void idc(int *p) {
+void idc(void *p) {
 	if (p)
 		;
 }
@@ -139,3 +139,42 @@
   int z = y;
   idcTriggerZeroValueThroughCall(z);
 }
+
+struct S {
+  int f1;
+  int f2;
+};
+
+void idcTrackZeroValueThroughUnaryPointerOperators(struct S *s) {
+  idc(s);
+  *(&(s->f1)) 

r301225 - [asan] Disable ASan global-GC depending on the target and compiler flags.

2017-04-24 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon Apr 24 14:34:12 2017
New Revision: 301225

URL: http://llvm.org/viewvc/llvm-project?rev=301225&view=rev
Log:
[asan] Disable ASan global-GC depending on the target and compiler flags.

Added:
cfe/trunk/test/CodeGen/asan-globals-gc.cpp
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=301225&r1=301224&r2=301225&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Apr 24 14:34:12 2017
@@ -129,16 +129,20 @@ public:
 // that we add to the PassManagerBuilder.
 class PassManagerBuilderWrapper : public PassManagerBuilder {
 public:
-  PassManagerBuilderWrapper(const CodeGenOptions &CGOpts,
+  PassManagerBuilderWrapper(const Triple &TargetTriple,
+const CodeGenOptions &CGOpts,
 const LangOptions &LangOpts)
-  : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {}
+  : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts),
+LangOpts(LangOpts) {}
+  const Triple &getTargetTriple() const { return TargetTriple; }
   const CodeGenOptions &getCGOpts() const { return CGOpts; }
   const LangOptions &getLangOpts() const { return LangOpts; }
+
 private:
+  const Triple &TargetTriple;
   const CodeGenOptions &CGOpts;
   const LangOptions &LangOpts;
 };
-
 }
 
 static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, 
PassManagerBase &PM) {
@@ -185,16 +189,36 @@ static void addSanitizerCoveragePass(con
   PM.add(createSanitizerCoverageModulePass(Opts));
 }
 
+// Check if ASan should use GC-friendly instrumentation for globals.
+// First of all, there is no point if -fdata-sections is off (expect for MachO,
+// where this is not a factor). Also, on ELF this feature requires an assembler
+// extension that only works with -integrated-as at the moment.
+static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) {
+  switch (T.getObjectFormat()) {
+  case Triple::MachO:
+return true;
+  case Triple::COFF:
+return CGOpts.DataSections;
+  case Triple::ELF:
+return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
+  default:
+return false;
+  }
+}
+
 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
   legacy::PassManagerBase &PM) {
   const PassManagerBuilderWrapper &BuilderWrapper =
   static_cast(Builder);
+  const Triple &T = BuilderWrapper.getTargetTriple();
   const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
   bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Address);
   bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope;
+  bool UseGlobalsGC = asanUseGlobalsGC(T, CGOpts);
   PM.add(createAddressSanitizerFunctionPass(/*CompileKernel*/ false, Recover,
 UseAfterScope));
-  PM.add(createAddressSanitizerModulePass(/*CompileKernel*/false, Recover));
+  PM.add(createAddressSanitizerModulePass(/*CompileKernel*/ false, Recover,
+  UseGlobalsGC));
 }
 
 static void addKernelAddressSanitizerPasses(const PassManagerBuilder &Builder,
@@ -436,8 +460,6 @@ void EmitAssemblyHelper::CreatePasses(le
   if (CodeGenOpts.DisableLLVMPasses)
 return;
 
-  PassManagerBuilderWrapper PMBuilder(CodeGenOpts, LangOpts);
-
   // Figure out TargetLibraryInfo.  This needs to be added to MPM and FPM
   // manually (and not via PMBuilder), since some passes (eg. InstrProfiling)
   // are inserted before PMBuilder ones - they'd get the default-constructed
@@ -446,6 +468,8 @@ void EmitAssemblyHelper::CreatePasses(le
   std::unique_ptr TLII(
   createTLII(TargetTriple, CodeGenOpts));
 
+  PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);
+
   // At O0 and O1 we only run the always inliner which is more efficient. At
   // higher optimization levels we run the normal inliner.
   if (CodeGenOpts.OptimizationLevel <= 1) {

Added: cfe/trunk/test/CodeGen/asan-globals-gc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asan-globals-gc.cpp?rev=301225&view=auto
==
--- cfe/trunk/test/CodeGen/asan-globals-gc.cpp (added)
+++ cfe/trunk/test/CodeGen/asan-globals-gc.cpp Mon Apr 24 14:34:12 2017
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC
+
+int global;
+
+// WITH-GC-NOT: call void @__asan_register_globals
+// WITHOUT-GC: call void @__asan_register_globals


___
cfe-commits ma

[PATCH] D32406: [Coverage][Windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl (fixes PR32761)

2017-04-24 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D32406#735725, @vsk wrote:

> First, please split off the SkipCoverageMapping change from this patch. If 
> you don't have commit access yet, let me know and I can commit it for you. 
> You can also ping Chris L for commit access.


Are you sure you want to do that? This is the only use of this boolean.


https://reviews.llvm.org/D32406



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


[PATCH] D32406: [Coverage][Windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl (fixes PR32761)

2017-04-24 Thread Adam Folwarczny via Phabricator via cfe-commits
adamf updated this revision to Diff 96454.
adamf added a comment.

Thanks for your comments!

Updated test case according to @vsk comment about test case reduction.

@rnk, your compilation command probably exposes another issue (with your 
compilation command the test still failure). I don't have time to analyze it 
now.

I don't have write access to svn so if you think this change is ok please 
commit it.


https://reviews.llvm.org/D32406

Files:
  lib/CodeGen/CodeGenPGO.cpp
  lib/CodeGen/CodeGenPGO.h
  test/CoverageMapping/empty-destructor.cpp


Index: test/CoverageMapping/empty-destructor.cpp
===
--- test/CoverageMapping/empty-destructor.cpp
+++ test/CoverageMapping/empty-destructor.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj 
-fprofile-instrument=clang -fdelayed-template-parsing -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only -main-file-name empty-destructor.cpp -o 
- %s
+
+struct A {
+  virtual ~A();
+};
+
+void PR32761() {
+  A a;
+}
Index: lib/CodeGen/CodeGenPGO.h
===
--- lib/CodeGen/CodeGenPGO.h
+++ lib/CodeGen/CodeGenPGO.h
@@ -40,14 +40,11 @@
   std::unique_ptr ProfRecord;
   std::vector RegionCounts;
   uint64_t CurrentRegionCount;
-  /// \brief A flag that is set to true when this function doesn't need
-  /// to have coverage mapping data.
-  bool SkipCoverageMapping;
 
 public:
   CodeGenPGO(CodeGenModule &CGM)
   : CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0),
-FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {}
+FunctionHash(0), CurrentRegionCount(0) {}
 
   /// Whether or not we have PGO region data for the current function. This is
   /// false both when we have no data at all and when our data has been
Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -666,7 +666,7 @@
 }
 
 bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
-  if (SkipCoverageMapping)
+  if (!D->hasBody())
 return true;
 
   // Don't map the functions in system headers.


Index: test/CoverageMapping/empty-destructor.cpp
===
--- test/CoverageMapping/empty-destructor.cpp
+++ test/CoverageMapping/empty-destructor.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj -fprofile-instrument=clang -fdelayed-template-parsing -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name empty-destructor.cpp -o - %s
+
+struct A {
+  virtual ~A();
+};
+
+void PR32761() {
+  A a;
+}
Index: lib/CodeGen/CodeGenPGO.h
===
--- lib/CodeGen/CodeGenPGO.h
+++ lib/CodeGen/CodeGenPGO.h
@@ -40,14 +40,11 @@
   std::unique_ptr ProfRecord;
   std::vector RegionCounts;
   uint64_t CurrentRegionCount;
-  /// \brief A flag that is set to true when this function doesn't need
-  /// to have coverage mapping data.
-  bool SkipCoverageMapping;
 
 public:
   CodeGenPGO(CodeGenModule &CGM)
   : CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0),
-FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {}
+FunctionHash(0), CurrentRegionCount(0) {}
 
   /// Whether or not we have PGO region data for the current function. This is
   /// false both when we have no data at all and when our data has been
Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -666,7 +666,7 @@
 }
 
 bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
-  if (SkipCoverageMapping)
+  if (!D->hasBody())
 return true;
 
   // Don't map the functions in system headers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31777: [ASTImporter] Move structural equivalence context to its own file. NFCI

2017-04-24 Thread Sean Callanan via Phabricator via cfe-commits
spyffe accepted this revision.
spyffe added a comment.
This revision is now accepted and ready to land.

Looks good to me.  This is a good step toward simplifying the ASTImporter and 
breaking out its parts to be useful on their own.
Obviously make sure the tests pass :)


https://reviews.llvm.org/D31777



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


[PATCH] D32043: [Driver] Load all necessary default sanitizer blacklists

2017-04-24 Thread Evgeniy Stepanov via Phabricator via cfe-commits
eugenis added a comment.

We definitely want different blacklists for ASan and MSan.


https://reviews.llvm.org/D32043



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


[PATCH] D32043: [Driver] Load all necessary default sanitizer blacklists

2017-04-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Ok. I will take a step back and see what it will take to implement 
per-sanitizer blacklists.


https://reviews.llvm.org/D32043



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


r301246 - Specify a target explicitly in libfuzzer driver flag test

2017-04-24 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Apr 24 15:38:56 2017
New Revision: 301246

URL: http://llvm.org/viewvc/llvm-project?rev=301246&view=rev
Log:
Specify a target explicitly in libfuzzer driver flag test

Modified:
cfe/trunk/test/Driver/fuzzer.c

Modified: cfe/trunk/test/Driver/fuzzer.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuzzer.c?rev=301246&r1=301245&r2=301246&view=diff
==
--- cfe/trunk/test/Driver/fuzzer.c (original)
+++ cfe/trunk/test/Driver/fuzzer.c Mon Apr 24 15:38:56 2017
@@ -1,6 +1,6 @@
 // Test flags inserted by -fsanitize=fuzzer.
 
-// RUN: %clang -fsanitize=fuzzer %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-FUZZER-LIB,CHECK-COVERAGE-FLAGS %s
+// RUN: %clang -fsanitize=fuzzer %s -target x86_64-apple-darwin14 -### 2>&1 | 
FileCheck --check-prefixes=CHECK-FUZZER-LIB,CHECK-COVERAGE-FLAGS %s
 //
 // CHECK-FUZZER-LIB: libLLVMFuzzer.a
 // CHECK-COVERAGE: -fsanitize-coverage-trace-pc-guard


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


[PATCH] D32406: [Coverage][Windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl (fixes PR32761)

2017-04-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

> Are you sure you want to do that? This is the only use of this boolean.

IMO removing 'SkipCoverageMapping' isn't related to fixing the original bug. 
Since it's simple enough to make it a separate change, I thought it'd be best.

In https://reviews.llvm.org/D32406#735847, @rnk wrote:

> In https://reviews.llvm.org/D32406#735725, @vsk wrote:
>
> > // RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj 
> > -fprofile-instrument=clang -fdelayed-template-parsing -fcoverage-mapping 
> > -dump-coverage-mapping -emit-llvm-only -main-file-name empty-destructor.cpp 
> > -o - %s
>
>
> This is probably closer to a minimal command line:
>  `%clang_cc1 -triple i686-windows -emit-llvm-only -fcoverage-mapping 
> -dump-coverage-mapping %s`


I'll go with this. @adamf this is just missing '-fprofile-instrument=clang', 
otherwise it's fine.

> Is there something we can FileCheck in the IR?

Absolutely, I'll add in the checks.


https://reviews.llvm.org/D32406



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


[PATCH] D32424: Add a fix-it for -Wunguarded-availability

2017-04-24 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Do we want to enclose declaration statements in "if (@available)" too? I think 
doing so can cause compilation errors.

  int x = function();
  
  ++x; // if declaration is wrapped, this is an error because x is undeclared 
in this scope.

Also,  when function is used in a case clause, the whole case clause will be 
wrapped in "if (@available)". This won't cause a compilation error, but it's 
probably better to enclose only the statement of the case label.

  switch (c) {
  case1: t1 = function();
  default: break;
  }


Repository:
  rL LLVM

https://reviews.llvm.org/D32424



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


r301249 - [Coverage] Avoid null deref in skipRegionMappingForDecl (fixes PR32761)

2017-04-24 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Mon Apr 24 15:52:04 2017
New Revision: 301249

URL: http://llvm.org/viewvc/llvm-project?rev=301249&view=rev
Log:
[Coverage] Avoid null deref in skipRegionMappingForDecl (fixes PR32761)

Patch by Adam Folwarczny!

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

Added:
cfe/trunk/test/CoverageMapping/empty-destructor.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=301249&r1=301248&r2=301249&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Mon Apr 24 15:52:04 2017
@@ -669,6 +669,9 @@ bool CodeGenPGO::skipRegionMappingForDec
   if (SkipCoverageMapping)
 return true;
 
+  if (!D->getBody())
+return true;
+
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getLocStart();

Added: cfe/trunk/test/CoverageMapping/empty-destructor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/empty-destructor.cpp?rev=301249&view=auto
==
--- cfe/trunk/test/CoverageMapping/empty-destructor.cpp (added)
+++ cfe/trunk/test/CoverageMapping/empty-destructor.cpp Mon Apr 24 15:52:04 2017
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows -emit-llvm-only -fcoverage-mapping 
-dump-coverage-mapping -fprofile-instrument=clang %s | FileCheck %s
+
+struct A {
+  virtual ~A();
+};
+
+// CHECK: ?PR32761@@YAXXZ:
+// CHECK-NEXT: File 0, [[@LINE+1]]:16 -> [[@LINE+3]]:2 = #0
+void PR32761() {
+  A a;
+}


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


[PATCH] D32406: [Coverage][Windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl (fixes PR32761)

2017-04-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301249: [Coverage] Avoid null deref in 
skipRegionMappingForDecl (fixes PR32761) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D32406?vs=96454&id=96467#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32406

Files:
  cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
  cfe/trunk/test/CoverageMapping/empty-destructor.cpp


Index: cfe/trunk/test/CoverageMapping/empty-destructor.cpp
===
--- cfe/trunk/test/CoverageMapping/empty-destructor.cpp
+++ cfe/trunk/test/CoverageMapping/empty-destructor.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows -emit-llvm-only -fcoverage-mapping 
-dump-coverage-mapping -fprofile-instrument=clang %s | FileCheck %s
+
+struct A {
+  virtual ~A();
+};
+
+// CHECK: ?PR32761@@YAXXZ:
+// CHECK-NEXT: File 0, [[@LINE+1]]:16 -> [[@LINE+3]]:2 = #0
+void PR32761() {
+  A a;
+}
Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -669,6 +669,9 @@
   if (SkipCoverageMapping)
 return true;
 
+  if (!D->getBody())
+return true;
+
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getLocStart();


Index: cfe/trunk/test/CoverageMapping/empty-destructor.cpp
===
--- cfe/trunk/test/CoverageMapping/empty-destructor.cpp
+++ cfe/trunk/test/CoverageMapping/empty-destructor.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows -emit-llvm-only -fcoverage-mapping -dump-coverage-mapping -fprofile-instrument=clang %s | FileCheck %s
+
+struct A {
+  virtual ~A();
+};
+
+// CHECK: ?PR32761@@YAXXZ:
+// CHECK-NEXT: File 0, [[@LINE+1]]:16 -> [[@LINE+3]]:2 = #0
+void PR32761() {
+  A a;
+}
Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -669,6 +669,9 @@
   if (SkipCoverageMapping)
 return true;
 
+  if (!D->getBody())
+return true;
+
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getLocStart();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r301250 - Remove a dead field. NFC.

2017-04-24 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Mon Apr 24 15:54:36 2017
New Revision: 301250

URL: http://llvm.org/viewvc/llvm-project?rev=301250&view=rev
Log:
Remove a dead field. NFC.

Suggested by Adam Folwarczny!

Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
cfe/trunk/lib/CodeGen/CodeGenPGO.h

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=301250&r1=301249&r2=301250&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Mon Apr 24 15:54:36 2017
@@ -666,9 +666,6 @@ void CodeGenPGO::mapRegionCounters(const
 }
 
 bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
-  if (SkipCoverageMapping)
-return true;
-
   if (!D->getBody())
 return true;
 

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.h?rev=301250&r1=301249&r2=301250&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenPGO.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.h Mon Apr 24 15:54:36 2017
@@ -40,14 +40,11 @@ private:
   std::unique_ptr ProfRecord;
   std::vector RegionCounts;
   uint64_t CurrentRegionCount;
-  /// \brief A flag that is set to true when this function doesn't need
-  /// to have coverage mapping data.
-  bool SkipCoverageMapping;
 
 public:
   CodeGenPGO(CodeGenModule &CGM)
-  : CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0),
-FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {}
+  : CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0), FunctionHash(0),
+CurrentRegionCount(0) {}
 
   /// Whether or not we have PGO region data for the current function. This is
   /// false both when we have no data at all and when our data has been


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


r301251 - [analyzer] Improve subscripting null arrays for catching null dereferences.

2017-04-24 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Apr 24 15:55:07 2017
New Revision: 301251

URL: http://llvm.org/viewvc/llvm-project?rev=301251&view=rev
Log:
[analyzer] Improve subscripting null arrays for catching null dereferences.

Array-to-pointer cast now works correctly when the pointer to the array
is concrete, eg. null, which allows further symbolic calculations involving
such values.

Inlined defensive checks are now detected correctly when the resulting null
symbol is being array-subscripted before dereference.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/null-deref-offsets.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=301251&r1=301250&r2=301251&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Apr 24 
15:55:07 2017
@@ -61,7 +61,9 @@ const Expr *bugreporter::getDerefExpr(co
 return U->getSubExpr()->IgnoreParenCasts();
 }
 else if (const MemberExpr *ME = dyn_cast(E)) {
-  if (ME->isArrow() || isDeclRefExprToReference(ME->getBase())) {
+  if (ME->isImplicitAccess()) {
+return ME;
+  } else if (ME->isArrow() || isDeclRefExprToReference(ME->getBase())) {
 return ME->getBase()->IgnoreParenCasts();
   } else {
 // If we have a member expr with a dot, the base must have been
@@ -73,9 +75,9 @@ const Expr *bugreporter::getDerefExpr(co
   return IvarRef->getBase()->IgnoreParenCasts();
 }
 else if (const ArraySubscriptExpr *AE = dyn_cast(E)) {
-  return AE->getBase();
+  return getDerefExpr(AE->getBase());
 }
-else if (isDeclRefExprToReference(E)) {
+else if (isa(E)) {
   return E;
 }
 break;
@@ -974,14 +976,11 @@ bool bugreporter::trackNullOrUndefValue(
 // This code interacts heavily with this hack; otherwise the value
 // would not be null at all for most fields, so we'd be unable to track it.
 if (const auto *Op = dyn_cast(Ex))
-  if (Op->getOpcode() == UO_AddrOf && Op->getSubExpr()->isLValue()) {
-Ex = Op->getSubExpr()->IgnoreParenCasts();
-while (const auto *ME = dyn_cast(Ex)) {
-  Ex = ME->getBase()->IgnoreParenCasts();
-}
-  }
+  if (Op->getOpcode() == UO_AddrOf && Op->getSubExpr()->isLValue())
+if (const Expr *DerefEx = getDerefExpr(Op->getSubExpr()))
+  Ex = DerefEx;
 
-if (ExplodedGraph::isInterestingLValueExpr(Ex) || 
CallEvent::isCallStmt(Ex))
+if (Ex && (ExplodedGraph::isInterestingLValueExpr(Ex) || 
CallEvent::isCallStmt(Ex)))
   Inner = Ex;
   }
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=301251&r1=301250&r2=301251&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Mon Apr 24 15:55:07 2017
@@ -1338,6 +1338,9 @@ RegionStoreManager::getSizeInElements(Pr
 ///  the array).  This is called by ExprEngine when evaluating casts
 ///  from arrays to pointers.
 SVal RegionStoreManager::ArrayToPointer(Loc Array, QualType T) {
+  if (Array.getAs())
+return Array;
+
   if (!Array.getAs())
 return UnknownVal();
 

Modified: cfe/trunk/test/Analysis/null-deref-offsets.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-offsets.c?rev=301251&r1=301250&r2=301251&view=diff
==
--- cfe/trunk/test/Analysis/null-deref-offsets.c (original)
+++ cfe/trunk/test/Analysis/null-deref-offsets.c Mon Apr 24 15:55:07 2017
@@ -7,7 +7,7 @@ struct S {
   int z[2];
 };
 
-void testOffsets(struct S *s) {
+void testOffsets(struct S *s, int coin) {
   if (s != 0)
 return;
 
@@ -21,14 +21,17 @@ void testOffsets(struct S *s) {
 
   // FIXME: These should ideally be true.
   clang_analyzer_eval(&(s->y) == 4); // expected-warning{{FALSE}}
-  clang_analyzer_eval(&(s->z[0]) == 8); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(&(s->z[1]) == 12); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(&(s->z[0]) == 8); // expected-warning{{FALSE}}
+  clang_analyzer_eval(&(s->z[1]) == 12); // expected-warning{{FALSE}}
 
   // FIXME: These should ideally be false.
   clang_analyzer_eval(&(s->y) == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(&(s->z[0]) == 0); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(&(s->z[1]) == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(&(s->z[0]) == 0); // expected-warning{{TR

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

2017-04-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301251: [analyzer] Improve subscripting null arrays for 
catching null dereferences. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D32291?vs=95943&id=96468#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32291

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/null-deref-offsets.c


Index: cfe/trunk/test/Analysis/null-deref-offsets.c
===
--- cfe/trunk/test/Analysis/null-deref-offsets.c
+++ cfe/trunk/test/Analysis/null-deref-offsets.c
@@ -7,7 +7,7 @@
   int z[2];
 };
 
-void testOffsets(struct S *s) {
+void testOffsets(struct S *s, int coin) {
   if (s != 0)
 return;
 
@@ -21,14 +21,17 @@
 
   // FIXME: These should ideally be true.
   clang_analyzer_eval(&(s->y) == 4); // expected-warning{{FALSE}}
-  clang_analyzer_eval(&(s->z[0]) == 8); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(&(s->z[1]) == 12); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(&(s->z[0]) == 8); // expected-warning{{FALSE}}
+  clang_analyzer_eval(&(s->z[1]) == 12); // expected-warning{{FALSE}}
 
   // FIXME: These should ideally be false.
   clang_analyzer_eval(&(s->y) == 0); // expected-warning{{TRUE}}
-  clang_analyzer_eval(&(s->z[0]) == 0); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(&(s->z[1]) == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(&(s->z[0]) == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(&(s->z[1]) == 0); // expected-warning{{TRUE}}
 
-  // But this should still be a null dereference.
-  s->y = 5; // expected-warning{{Access to field 'y' results in a dereference 
of a null pointer (loaded from variable 's')}}
+  // But these should still be reported as null dereferences.
+  if (coin)
+s->y = 5; // expected-warning{{Access to field 'y' results in a 
dereference of a null pointer (loaded from variable 's')}}
+  else
+s->z[1] = 6; // expected-warning{{Array access (via field 'z') results in 
a null pointer dereference}}
 }
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -61,7 +61,9 @@
 return U->getSubExpr()->IgnoreParenCasts();
 }
 else if (const MemberExpr *ME = dyn_cast(E)) {
-  if (ME->isArrow() || isDeclRefExprToReference(ME->getBase())) {
+  if (ME->isImplicitAccess()) {
+return ME;
+  } else if (ME->isArrow() || isDeclRefExprToReference(ME->getBase())) {
 return ME->getBase()->IgnoreParenCasts();
   } else {
 // If we have a member expr with a dot, the base must have been
@@ -73,9 +75,9 @@
   return IvarRef->getBase()->IgnoreParenCasts();
 }
 else if (const ArraySubscriptExpr *AE = dyn_cast(E)) {
-  return AE->getBase();
+  return getDerefExpr(AE->getBase());
 }
-else if (isDeclRefExprToReference(E)) {
+else if (isa(E)) {
   return E;
 }
 break;
@@ -974,14 +976,11 @@
 // This code interacts heavily with this hack; otherwise the value
 // would not be null at all for most fields, so we'd be unable to track it.
 if (const auto *Op = dyn_cast(Ex))
-  if (Op->getOpcode() == UO_AddrOf && Op->getSubExpr()->isLValue()) {
-Ex = Op->getSubExpr()->IgnoreParenCasts();
-while (const auto *ME = dyn_cast(Ex)) {
-  Ex = ME->getBase()->IgnoreParenCasts();
-}
-  }
+  if (Op->getOpcode() == UO_AddrOf && Op->getSubExpr()->isLValue())
+if (const Expr *DerefEx = getDerefExpr(Op->getSubExpr()))
+  Ex = DerefEx;
 
-if (ExplodedGraph::isInterestingLValueExpr(Ex) || 
CallEvent::isCallStmt(Ex))
+if (Ex && (ExplodedGraph::isInterestingLValueExpr(Ex) || 
CallEvent::isCallStmt(Ex)))
   Inner = Ex;
   }
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1338,6 +1338,9 @@
 ///  the array).  This is called by ExprEngine when evaluating casts
 ///  from arrays to pointers.
 SVal RegionStoreManager::ArrayToPointer(Loc Array, QualType T) {
+  if (Array.getAs())
+return Array;
+
   if (!Array.getAs())
 return UnknownVal();
 


Index: cfe/trunk/test/Analysis/null-deref-offsets.c
===
--- cfe/trunk/test/Analysis/null-deref-offsets.c
+++ cfe/trunk/test/Analysis/null-deref-offsets.c
@@ -7,7 +7,7 @@
   int z[2];
 };
 
-void testOffsets(struct S *s) {
+void testOffsets(struct S *s, int coin) {
   if (s != 0)
 return;
 
@@ -21,14 +21,17 @@
 
   // FIXME: These should ide

[PATCH] D32455: detect integer overflow inside arms of conditional operator with non-constant expression

2017-04-24 Thread Nick Lewycky via Phabricator via cfe-commits
nlewycky created this revision.
Herald added subscribers: rengolin, aemerson.

Descend into both the true and false expressions of a ConditionalOperator when 
the condition can't be evaluated and we're in an evaluation-mode that says we 
should continue evaluating.


https://reviews.llvm.org/D32455

Files:
  lib/AST/ExprConstant.cpp
  test/Sema/integer-overflow.c


Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -148,6 +148,9 @@
   a[4608 * 1024 * 1024] = 1i;
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
+  (void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
 }
 
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4418,8 +4418,14 @@
   bool HandleConditionalOperator(const ConditionalOperator *E) {
 bool BoolResult;
 if (!EvaluateAsBooleanCondition(E->getCond(), BoolResult, Info)) {
-  if (Info.checkingPotentialConstantExpression() && Info.noteFailure())
+  if (Info.checkingPotentialConstantExpression() && Info.noteFailure()) {
 CheckPotentialConstantConditional(E);
+return false;
+  }
+  if (Info.noteFailure()) {
+StmtVisitorTy::Visit(E->getTrueExpr());
+StmtVisitorTy::Visit(E->getFalseExpr());
+  }
   return false;
 }
 


Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -148,6 +148,9 @@
   a[4608 * 1024 * 1024] = 1i;
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+  (void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
 }
 
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4418,8 +4418,14 @@
   bool HandleConditionalOperator(const ConditionalOperator *E) {
 bool BoolResult;
 if (!EvaluateAsBooleanCondition(E->getCond(), BoolResult, Info)) {
-  if (Info.checkingPotentialConstantExpression() && Info.noteFailure())
+  if (Info.checkingPotentialConstantExpression() && Info.noteFailure()) {
 CheckPotentialConstantConditional(E);
+return false;
+  }
+  if (Info.noteFailure()) {
+StmtVisitorTy::Visit(E->getTrueExpr());
+StmtVisitorTy::Visit(E->getFalseExpr());
+  }
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r300140 - [libcxx] Fix __compressed_pair so it doesn't copy the argument multiple times, and add constexpr.

2017-04-24 Thread Lang Hames via cfe-commits
Hi Eric,

Renaming __compressed_pair_elem's member from __first_ to __value_ has
broken a lot of LLDB's data formatters. Would it be possible to rename it
back for consistency? If it's just a rename it would be preferable to the
alternative, which would be to add some clumsy fallback logic in LLDB:

if (auto *Entry = find_element("__first_"))
  // ...
else if (auto *Entry = find_element("__value_"))
  // ...
else
  // ...

Cheers,
Lang.


On Wed, Apr 12, 2017 at 4:45 PM, Eric Fiselier via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ericwf
> Date: Wed Apr 12 18:45:53 2017
> New Revision: 300140
>
> URL: http://llvm.org/viewvc/llvm-project?rev=300140&view=rev
> Log:
> [libcxx] Fix __compressed_pair so it doesn't copy the argument multiple
> times, and add constexpr.
>
> Summary:
> __compressed_pair takes and passes it's constructor arguments by value.
> This causes arguments to be moved 3 times instead of once. This patch
> addresses that issue and fixes `constexpr` on the constructors.
>
> I would rather have this fix than D27564, and I'm fairly confident it's
> not ABI breaking but I'm not 100% sure.
>
> I prefer this solution because it removes a lot of code and makes the
> implementation *much* smaller.
>
> Reviewers: mclow.lists, K-ballo
>
> Reviewed By: K-ballo
>
> Subscribers: K-ballo, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D27565
>
> Modified:
> libcxx/trunk/include/__hash_table
> libcxx/trunk/include/memory
> libcxx/trunk/include/string
> libcxx/trunk/test/std/utilities/memory/unique.ptr/
> unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp
>
> Modified: libcxx/trunk/include/__hash_table
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/_
> _hash_table?rev=300140&r1=300139&r2=300140&view=diff
> 
> ==
> --- libcxx/trunk/include/__hash_table (original)
> +++ libcxx/trunk/include/__hash_table Wed Apr 12 18:45:53 2017
> @@ -1402,7 +1402,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
> const key_equal&
> __eql,
> const
> allocator_type& __a)
>  : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a),
> 0)),
> -  __p1_(__node_allocator(__a)),
> +  __p1_(__second_tag(), __node_allocator(__a)),
>__p2_(0, __hf),
>__p3_(1.0f, __eql)
>  {
> @@ -1411,7 +1411,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
>  template 
>  __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const
> allocator_type& __a)
>  : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a),
> 0)),
> -  __p1_(__node_allocator(__a)),
> +  __p1_(__second_tag(), __node_allocator(__a)),
>__p2_(0),
>__p3_(1.0f)
>  {
> @@ -1423,7 +1423,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
>__bucket_list_deleter(allocator_traits<__pointer_allocator>::
>select_on_container_copy_construction(
>__u.__bucket_list_.get_deleter().__alloc()), 0)),
> -  __p1_(allocator_traits<__node_allocator>::
> +  __p1_(__second_tag(), allocator_traits<__node_allocator>::
>select_on_container_copy_construction(__u.__node_alloc())),
>__p2_(0, __u.hash_function()),
>__p3_(__u.__p3_)
> @@ -1434,7 +1434,7 @@ template   __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const
> __hash_table& __u,
> const
> allocator_type& __a)
>  : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a),
> 0)),
> -  __p1_(__node_allocator(__a)),
> +  __p1_(__second_tag(), __node_allocator(__a)),
>__p2_(0, __u.hash_function()),
>__p3_(__u.__p3_)
>  {
> @@ -1468,7 +1468,7 @@ template   __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&&
> __u,
> const
> allocator_type& __a)
>  : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a),
> 0)),
> -  __p1_(__node_allocator(__a)),
> +  __p1_(__second_tag(), __node_allocator(__a)),
>__p2_(0, _VSTD::move(__u.hash_function())),
>__p3_(_VSTD::move(__u.__p3_))
>  {
>
> Modified: libcxx/trunk/include/memory
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/
> memory?rev=300140&r1=300139&r2=300140&view=diff
> 
> ==
> --- libcxx/trunk/include/memory (original)
> +++ libcxx/trunk/include/memory Wed Apr 12 18:45:53 2017
> @@ -653,7 +653,7 @@ void* align(size_t alignment, size_t siz
>  #include 
>  #include 
>  #include 
> -
> +#include 
>  #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
>  #  include 
>  #endif
> @@ -2070,307 +2070,174 @@ public:
>  };
>  #endif
>
> -template  remove_cv<_T1>::type,
> -

[PATCH] D32436: [clang-tidy] Support detecting for-range loop in inefficient-vector-operation check.

2017-04-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
docs/clang-tidy/checks/performance-inefficient-vector-operation.rst:6
 
 Finds possible inefficient `std::vector` operations (e.g. `push_back`) that may
 cause unnecessary memory reallocations.

Please use `` to highlight language elements. Same below.


https://reviews.llvm.org/D32436



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


r301261 - [Modules] Fix test to wipe out the cache before using it

2017-04-24 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Mon Apr 24 16:58:13 2017
New Revision: 301261

URL: http://llvm.org/viewvc/llvm-project?rev=301261&view=rev
Log:
[Modules] Fix test to wipe out the cache before using it

This should appease bots:
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental_check/35914

rdar://problem/31796737

Modified:
cfe/trunk/test/Modules/localsubmodulevis.m

Modified: cfe/trunk/test/Modules/localsubmodulevis.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/localsubmodulevis.m?rev=301261&r1=301260&r2=301261&view=diff
==
--- cfe/trunk/test/Modules/localsubmodulevis.m (original)
+++ cfe/trunk/test/Modules/localsubmodulevis.m Mon Apr 24 16:58:13 2017
@@ -1,4 +1,4 @@
-// RUN: rm -rf %t
+// RUN: rm -rf %t.a %t.b
 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility 
-fimplicit-module-maps -fmodules-cache-path=%t.a -I %S/Inputs/preprocess 
-verify %s
 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility 
-fimplicit-module-maps -fmodules-cache-path=%t.b -I %S/Inputs/preprocess -x c 
-verify -x c %s
 


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


[PATCH] D31269: [Modules] Allow modules specified by -fmodule-map-file to shadow implicitly found ones

2017-04-24 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Ping!


https://reviews.llvm.org/D31269



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


[PATCH] D28832: Improve redefinition errors pointing to the same header.

2017-04-24 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Ping


https://reviews.llvm.org/D28832



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


[PATCH] D32456: [ubsan] Make the alignment check work with some extern decls (PR32630)

2017-04-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

UBSan's alignment check does not detect unaligned loads and stores from
extern struct declarations. Example:

  struct S { int i; };
  extern struct S g_S; // &g_S may not be aligned properly.
  
  int main() {
return g_S.i; // No alignment check for &g_S.i is emitted.
  }

The frontend skips the alignment check for &g_S.i because the check is
constant-folded to 'NOT NULL' by the IR builder.

If we drop the alignment information from extern struct declarations,
the IR builder would no longer be able to constant-fold the checks away.
That would make the alignment check more useful.

Note: it would still not be able to catch the following case --

  extern int i; // &i is not aligned properly.

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

Testing: check-clang, check-ubsan.


https://reviews.llvm.org/D32456

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/ubsan-global-alignment.cpp


Index: test/CodeGenCXX/ubsan-global-alignment.cpp
===
--- test/CodeGenCXX/ubsan-global-alignment.cpp
+++ test/CodeGenCXX/ubsan-global-alignment.cpp
@@ -5,18 +5,27 @@
 };
 
 extern S g_S;
+__private_extern__ S pe_S;
 extern S array_S[];
 
-// CHECK-LABEL: define i32 @_Z18load_extern_global
-int load_extern_global() {
-  // FIXME: The IR builder constant-folds the alignment check away to 'true'
-  // here, so we never call the diagnostic. This is PR32630.
-  // CHECK-NOT: ptrtoint i32* {{.*}} to i32, !nosanitize
+// CHECK-LABEL: define i32 @_Z19load_extern_global1
+int load_extern_global1() {
+  // CHECK: br i1 icmp eq (i64 and (i64 ptrtoint (%struct.S* @g_S to i64), i64 
3), i64 0), {{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_type_mismatch
   // CHECK: [[I:%.*]] = load i32, i32* getelementptr inbounds (%struct.S, 
%struct.S* @g_S, i32 0, i32 0), align 4
   // CHECK-NEXT: ret i32 [[I]]
   return g_S.I;
 }
 
+// CHECK-LABEL: define i32 @_Z19load_extern_global2
+int load_extern_global2() {
+  // CHECK: br i1 icmp eq (i64 and (i64 ptrtoint (%struct.S* @pe_S to i64), 
i64 3), i64 0), {{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_type_mismatch
+  // CHECK: [[I:%.*]] = load i32, i32* getelementptr inbounds (%struct.S, 
%struct.S* @pe_S, i32 0, i32 0), align 4
+  // CHECK-NEXT: ret i32 [[I]]
+  return pe_S.I;
+}
+
 // CHECK-LABEL: define i32 @_Z22load_from_extern_array
 int load_from_extern_array(int I) {
   // CHECK: [[I:%.*]] = getelementptr inbounds %struct.S, %struct.S* {{.*}}, 
i32 0, i32 0
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2312,7 +2312,14 @@
 // handling.
 GV->setConstant(isTypeConstant(D->getType(), false));
 
-GV->setAlignment(getContext().getDeclAlign(D).getQuantity());
+if (LangOpts.Sanitize.has(SanitizerKind::Alignment) && !IsForDefinition &&
+(D->getStorageClass() == SC_Extern ||
+ D->getStorageClass() == SC_PrivateExtern)) {
+  // The alignment sanitizer can catch more bugs if we don't attach
+  // alignment info to extern globals.
+} else {
+  GV->setAlignment(getContext().getDeclAlign(D).getQuantity());
+}
 
 setLinkageAndVisibilityForGV(GV, D);
 


Index: test/CodeGenCXX/ubsan-global-alignment.cpp
===
--- test/CodeGenCXX/ubsan-global-alignment.cpp
+++ test/CodeGenCXX/ubsan-global-alignment.cpp
@@ -5,18 +5,27 @@
 };
 
 extern S g_S;
+__private_extern__ S pe_S;
 extern S array_S[];
 
-// CHECK-LABEL: define i32 @_Z18load_extern_global
-int load_extern_global() {
-  // FIXME: The IR builder constant-folds the alignment check away to 'true'
-  // here, so we never call the diagnostic. This is PR32630.
-  // CHECK-NOT: ptrtoint i32* {{.*}} to i32, !nosanitize
+// CHECK-LABEL: define i32 @_Z19load_extern_global1
+int load_extern_global1() {
+  // CHECK: br i1 icmp eq (i64 and (i64 ptrtoint (%struct.S* @g_S to i64), i64 3), i64 0), {{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_type_mismatch
   // CHECK: [[I:%.*]] = load i32, i32* getelementptr inbounds (%struct.S, %struct.S* @g_S, i32 0, i32 0), align 4
   // CHECK-NEXT: ret i32 [[I]]
   return g_S.I;
 }
 
+// CHECK-LABEL: define i32 @_Z19load_extern_global2
+int load_extern_global2() {
+  // CHECK: br i1 icmp eq (i64 and (i64 ptrtoint (%struct.S* @pe_S to i64), i64 3), i64 0), {{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_type_mismatch
+  // CHECK: [[I:%.*]] = load i32, i32* getelementptr inbounds (%struct.S, %struct.S* @pe_S, i32 0, i32 0), align 4
+  // CHECK-NEXT: ret i32 [[I]]
+  return pe_S.I;
+}
+
 // CHECK-LABEL: define i32 @_Z22load_from_extern_array
 int load_from_extern_array(int I) {
   // CHECK: [[I:%.*]] = getelementptr inbounds %struct.S, %struct.S* {{.*}}, i32 0, i32 0
Index: lib/CodeGen/CodeGenModule.cpp
=

Re: [libcxx] r300140 - [libcxx] Fix __compressed_pair so it doesn't copy the argument multiple times, and add constexpr.

2017-04-24 Thread Eric Fiselier via cfe-commits
There is no easy way to change their names back. The same class is used to
store the first and second element, both have the name `__value_` now.

Sorry

/Eric

On Mon, Apr 24, 2017 at 4:02 PM, Lang Hames  wrote:

> Hi Eric,
>
> Renaming __compressed_pair_elem's member from __first_ to __value_ has
> broken a lot of LLDB's data formatters. Would it be possible to rename it
> back for consistency? If it's just a rename it would be preferable to the
> alternative, which would be to add some clumsy fallback logic in LLDB:
>
> if (auto *Entry = find_element("__first_"))
>   // ...
> else if (auto *Entry = find_element("__value_"))
>   // ...
> else
>   // ...
>
> Cheers,
> Lang.
>
>
> On Wed, Apr 12, 2017 at 4:45 PM, Eric Fiselier via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: ericwf
>> Date: Wed Apr 12 18:45:53 2017
>> New Revision: 300140
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=300140&view=rev
>> Log:
>> [libcxx] Fix __compressed_pair so it doesn't copy the argument multiple
>> times, and add constexpr.
>>
>> Summary:
>> __compressed_pair takes and passes it's constructor arguments by value.
>> This causes arguments to be moved 3 times instead of once. This patch
>> addresses that issue and fixes `constexpr` on the constructors.
>>
>> I would rather have this fix than D27564, and I'm fairly confident it's
>> not ABI breaking but I'm not 100% sure.
>>
>> I prefer this solution because it removes a lot of code and makes the
>> implementation *much* smaller.
>>
>> Reviewers: mclow.lists, K-ballo
>>
>> Reviewed By: K-ballo
>>
>> Subscribers: K-ballo, cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D27565
>>
>> Modified:
>> libcxx/trunk/include/__hash_table
>> libcxx/trunk/include/memory
>> libcxx/trunk/include/string
>> libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.
>> ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp
>>
>> Modified: libcxx/trunk/include/__hash_table
>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__
>> hash_table?rev=300140&r1=300139&r2=300140&view=diff
>> 
>> ==
>> --- libcxx/trunk/include/__hash_table (original)
>> +++ libcxx/trunk/include/__hash_table Wed Apr 12 18:45:53 2017
>> @@ -1402,7 +1402,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
>> const key_equal&
>> __eql,
>> const
>> allocator_type& __a)
>>  : __bucket_list_(nullptr, 
>> __bucket_list_deleter(__pointer_allocator(__a),
>> 0)),
>> -  __p1_(__node_allocator(__a)),
>> +  __p1_(__second_tag(), __node_allocator(__a)),
>>__p2_(0, __hf),
>>__p3_(1.0f, __eql)
>>  {
>> @@ -1411,7 +1411,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
>>  template 
>>  __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const
>> allocator_type& __a)
>>  : __bucket_list_(nullptr, 
>> __bucket_list_deleter(__pointer_allocator(__a),
>> 0)),
>> -  __p1_(__node_allocator(__a)),
>> +  __p1_(__second_tag(), __node_allocator(__a)),
>>__p2_(0),
>>__p3_(1.0f)
>>  {
>> @@ -1423,7 +1423,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
>>__bucket_list_deleter(allocator_traits<__pointer_allocator>::
>>select_on_container_copy_construction(
>>__u.__bucket_list_.get_deleter().__alloc()), 0)),
>> -  __p1_(allocator_traits<__node_allocator>::
>> +  __p1_(__second_tag(), allocator_traits<__node_allocator>::
>>select_on_container_copy_construction(__u.__node_alloc())),
>>__p2_(0, __u.hash_function()),
>>__p3_(__u.__p3_)
>> @@ -1434,7 +1434,7 @@ template >  __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const
>> __hash_table& __u,
>> const
>> allocator_type& __a)
>>  : __bucket_list_(nullptr, 
>> __bucket_list_deleter(__pointer_allocator(__a),
>> 0)),
>> -  __p1_(__node_allocator(__a)),
>> +  __p1_(__second_tag(), __node_allocator(__a)),
>>__p2_(0, __u.hash_function()),
>>__p3_(__u.__p3_)
>>  {
>> @@ -1468,7 +1468,7 @@ template >  __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&&
>> __u,
>> const
>> allocator_type& __a)
>>  : __bucket_list_(nullptr, 
>> __bucket_list_deleter(__pointer_allocator(__a),
>> 0)),
>> -  __p1_(__node_allocator(__a)),
>> +  __p1_(__second_tag(), __node_allocator(__a)),
>>__p2_(0, _VSTD::move(__u.hash_function())),
>>__p3_(_VSTD::move(__u.__p3_))
>>  {
>>
>> Modified: libcxx/trunk/include/memory
>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/mem
>> ory?rev=300140&r1=300139&r2=300140&view=diff
>> 
>> ==
>> --- libcxx/trunk/include/memory (original)
>>

r301271 - [modules ts] Diagnose 'export' declarations outside of a module interface.

2017-04-24 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Apr 24 18:12:30 2017
New Revision: 301271

URL: http://llvm.org/viewvc/llvm-project?rev=301271&view=rev
Log:
[modules ts] Diagnose 'export' declarations outside of a module interface.

Added:
cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.interface/p1.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/Module.h
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Parser/cxx-modules-interface.cppm
cfe/trunk/test/SemaCXX/modules-ts.cppm

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=301271&r1=301270&r2=301271&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Apr 24 18:12:30 
2017
@@ -8804,7 +8804,7 @@ let CategoryName = "Modules Issue" in {
 def err_module_decl_in_module_map_module : Error<
   "'module' declaration found while building module from module map">;
 def err_module_interface_implementation_mismatch : Error<
-  "missing 'export' specifier in 'module' declaration while "
+  "missing 'export' specifier in module declaration while "
   "building module interface">;
 def err_current_module_name_mismatch : Error<
   "module name '%0' specified on command line does not match name of module">;
@@ -8848,8 +8848,13 @@ def err_module_self_import : Error<
   "import of module '%0' appears within same top-level module '%1'">;
 def err_module_import_in_implementation : Error<
   "@import of module '%0' in implementation of '%1'; use #import">;
+
+// C++ Modules TS
 def err_export_within_export : Error<
   "export declaration appears within another export declaration">;
+def err_export_not_in_module_interface : Error<
+  "export declaration can only be used within a module interface unit after "
+  "the module declaration">;
 
 def ext_equivalent_internal_linkage_decl_in_modules : ExtWarn<
   "ambiguous use of internal linkage declaration %0 defined in multiple 
modules">,

Modified: cfe/trunk/include/clang/Basic/Module.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=301271&r1=301270&r2=301271&view=diff
==
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Mon Apr 24 18:12:30 2017
@@ -62,6 +62,18 @@ public:
   /// \brief The location of the module definition.
   SourceLocation DefinitionLoc;
 
+  enum ModuleKind {
+/// \brief This is a module that was defined by a module map and built out
+/// of header files.
+ModuleMapModule,
+
+/// \brief This is a C++ Modules TS module interface unit.
+ModuleInterfaceUnit
+  };
+
+  /// \brief The kind of this module.
+  ModuleKind Kind = ModuleMapModule;
+
   /// \brief The parent of this module. This will be NULL for the top-level
   /// module.
   Module *Parent;

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=301271&r1=301270&r2=301271&view=diff
==
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Mon Apr 24 18:12:30 2017
@@ -581,6 +581,7 @@ Module *ModuleMap::createModuleForInterf
   auto *Result =
   new Module(Name, Loc, nullptr, /*IsFramework*/ false,
  /*IsExplicit*/ false, NumCreatedModules++);
+  Result->Kind = Module::ModuleInterfaceUnit;
   Modules[Name] = SourceModule = Result;
 
   // Mark the main source file as being within the newly-created module so that

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=301271&r1=301270&r2=301271&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Apr 24 18:12:30 2017
@@ -15922,6 +15922,12 @@ Decl *Sema::ActOnStartExportDecl(Scope *
   ExportDecl *D = ExportDecl::Create(Context, CurContext, ExportLoc);
 
   // C++ Modules TS draft:
+  //   An export-declaration shall appear in the purview of a module other than
+  //   the global module.
+  if (ModuleScopes.empty() || !ModuleScopes.back().Module ||
+  ModuleScopes.back().Module->Kind != Module::ModuleInterfaceUnit)
+Diag(ExportLoc, diag::err_export_not_in_module_interface);
+
   //   An export-declaration [...] shall not contain more than one
   //   export keyword.
   //

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/A

[PATCH] D32456: [ubsan] Make the alignment check work with some extern decls (PR32630)

2017-04-24 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> Note: it would still not be able to catch the following case --

Do you know why?




Comment at: lib/CodeGen/CodeGenModule.cpp:2319
+  // The alignment sanitizer can catch more bugs if we don't attach
+  // alignment info to extern globals.
+} else {

If we don't explicitly set the alignment, is it 1?  Or is it picking up the 
alignment from the type somehow?


https://reviews.llvm.org/D32456



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


[PATCH] D32427: Fix float abi for SUSE ARM triples

2017-04-24 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

I think that you should mutate the environment in the canonicalisation phase of 
the triple.  That will allow you to use `armv7-suse-linux-gnueabi` and 
`armv7-suse-linux-gnueabihf` in the frontend, but have the backend always get 
`armv7-suse-linux-gnueabihf`.


https://reviews.llvm.org/D32427



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


[PATCH] D32269: [Driver] Add iSOFTLinux to GNU ToolChains X86Triple

2017-04-24 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added a comment.
This revision now requires changes to proceed.

Is this to actually get the correct GCC search dir?  Your test doesnt really 
test anything AFAICT, as it is just invoking clang with a target that it would 
accept anyways.


Repository:
  rL LLVM

https://reviews.llvm.org/D32269



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


[PATCH] D32109: [Driver] Limit .exe extension addition to Windows hosts

2017-04-24 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added a comment.

Why not always replace the extension?  Windows doesnt require the .exe suffix 
IIRC.


https://reviews.llvm.org/D32109



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


[PATCH] D28832: Improve redefinition errors pointing to the same header.

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

LGTM. I'd like to make sure we try to use something better than the first 
import location for a module (that location is especially meaningless under 
`-fmodules-local-submodule-visibility`), but I'm happy for that (the big 
comment) to be dealt with as a follow-on change, and all the other comments 
here are minor, so feel free to commit after addressing those.




Comment at: include/clang/Basic/DiagnosticSemaKinds.td:8710
+def note_redefinition_modules_same_file_modulemap : Note<
+   "consider adding '%0' as part of '%1' definition in">;
 }

rsmith wrote:
> This note ends in the middle of a sentence.
... this note still ends in the middle of a sentence.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:4584
+def note_use_ifdef_guards :
+  Note <"unguarded header; consider using #ifdef guards or #pragma once">;
 

Nit: we generally put the `Note<` on the prior line.



Comment at: lib/Sema/SemaDecl.cpp:3594
+notePreviousDefinition(Previous.getRepresentativeDecl()->getLocation(),
+ New->getLocation());
 return New->setInvalidDecl();

Reindent.



Comment at: lib/Sema/SemaDecl.cpp:3812
+
+if (!IncLoc.isInvalid()) {
+  if (Mod) {

Use `isValid` to avoid double-negative.



Comment at: lib/Sema/SemaDecl.cpp:3747
+  // is confusing, try to get better diagnostics when modules is on.
+  auto OldModLoc = SrcMgr.getModuleImportLoc(Old);
+  if (!OldModLoc.first.isInvalid()) {

bruno wrote:
> rsmith wrote:
> > Rather than listing where the module was first imported (which could be 
> > unrelated to the problem), it would make more sense to list the location at 
> > which the previous declaration was made visible. You can get that by 
> > querying the `VisibleModuleSet` for the owning module of the definition and 
> > every other module in its merged definitions set (see 
> > `Sema::hasVisibleMergedDefinition`).
> I tried this, but AFAIU the Decls coming from non-modular headers are usually 
> hidden, and since it has not been merged, which happens in the testcase 
> because it's a var redefinition error, then we have no import location to get 
> information from. Do you have a synthetic testcase in mind that I can use? 
> I'm happy to follow up with that (here or in a next patch).
The `int c = 1;` testcase seems like it ought to be pretty rare (defining a 
variable in a header), and it might make more sense to say "hey, you probably 
didn't want a strong definition in a header at all" rather than pointing out 
the header was included twice.

Here's one pattern we've seen a few times that might be useful as a testcase:

== foo.h:
```
#ifndef FOO
#define FOO
#include "bar.h"
struct A {};
#endif
```

== bar.h:
```
#ifndef BAR
#define BAR
#include "foo.h"
#endif
```

== module.map:
```
module bar { header "bar.h" }
```

== x.c:
```
#include "foo.h"
```

[This results in us entering the FOO include guard, importing bar.h (including 
a definition of A) and then parsing another definition of A.]


https://reviews.llvm.org/D28832



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


[PATCH] D32109: [Driver] Limit .exe extension addition to Windows hosts

2017-04-24 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

> Why not always replace the extension? Windows doesnt require the .exe suffix 
> IIRC.

CreateProcess documentation says "This parameter must include the file name 
extension; no default extension is assumed.". That's kinda surprising to me, 
since LoadLibrary assumes a `.dll` extension.


https://reviews.llvm.org/D32109



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


r301285 - Placate MSVC's narrowing conversion unhappiness.

2017-04-24 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Apr 24 19:40:40 2017
New Revision: 301285

URL: http://llvm.org/viewvc/llvm-project?rev=301285&view=rev
Log:
Placate MSVC's narrowing conversion unhappiness.

Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=301285&r1=301284&r2=301285&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Apr 24 19:40:40 2017
@@ -2697,7 +2697,7 @@ void ASTWriter::WriteSubmodules(Module *
   RecordData::value_type Record[] = {
   getNumberOfModules(WritingModule),
   FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS,
-  WritingModule->Kind};
+  (unsigned)WritingModule->Kind};
   Stream.EmitRecord(SUBMODULE_METADATA, Record);
   
   // Write all of the submodules.


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


Re: [PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread Nico Weber via cfe-commits
majnemer: opinion on the above?

On Apr 24, 2017 2:56 PM, "Nico Weber"  wrote:

> "Opting into the conforming mode, /permissive-, during the series of VS
> 2017 update is a commitment to keeping your code base clean and to fixing
> non-conforming constructs we fix conformance issues in Visual C++." [...]
> "By contrast /permissive- offers a useful conformance mode where input C++
> code is interpreted according to ISO C++ rules but also allows conforming
> extensions necessary to compile C++ on targets supported by Visual C++."
>
> I guess the second quote agrees with your interpretation.
>
> We already diag most of the things they already mention. The one thing we
> don't diag by default is Wmicrosoft-enum-forward-reference since that's
> only an Extension and not an ExtWarn. We don't expose -pedantic from
> clang-cl, so this seemed like a somewhat natural mapping to me.
>
> Should /permissive- map to -Wmicrosoft instead and turn on the parts of
> -Wmicrosoft that are Extensions? Should we just ignore /permissive- and
> possibly make some of our -Wmicrosoft Extensions ExtWarns instead?
>
> On Mon, Apr 24, 2017 at 2:10 PM, David Majnemer 
> wrote:
>
>> -pedantic means "Issue all the warnings demanded by strict ISO C and ISO
>> C++; reject all programs that use forbidden extensions, and some other
>> programs that do not follow ISO C and ISO C++."
>> I believe it is more akin to -fno-ms-compatibility as it disables
>> compatibility hacks.
>>
>> On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber  wrote:
>>
>>> It does sound pretty similar to me from the blog post. I think this is a
>>> decent place to start from.
>>>
>>> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via
>>> cfe-commits"  wrote:
>>>
 majnemer requested changes to this revision.
 majnemer added a comment.
 This revision now requires changes to proceed.

 I don't think this is correct. GDR (of Microsoft) says the behavior is
 different: https://www.reddit.com/r/cpp/comments/5dh7j5/visual_c_introd
 uces_permissive_for_conformance/da5fxjj/


 https://reviews.llvm.org/D32435



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

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


[PATCH] D32269: [Driver] Add iSOFTLinux to GNU ToolChains X86Triple

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

Hi Saleem,

Thanks for pointing out my fault, I will update my patch to add, for example:

  -L[[SYSROOT]]/usr/lib/gcc/x86_64-isoft-linux/6.3.1

to the testcase.

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D32269



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


Re: [PATCH] D32435: clang-cl: Add support for /permissive-

2017-04-24 Thread David Majnemer via cfe-commits
On Mon, Apr 24, 2017 at 11:56 AM, Nico Weber  wrote:

> "Opting into the conforming mode, /permissive-, during the series of VS
> 2017 update is a commitment to keeping your code base clean and to fixing
> non-conforming constructs we fix conformance issues in Visual C++." [...]
> "By contrast /permissive- offers a useful conformance mode where input C++
> code is interpreted according to ISO C++ rules but also allows conforming
> extensions necessary to compile C++ on targets supported by Visual C++."
>
> I guess the second quote agrees with your interpretation.
>
> We already diag most of the things they already mention. The one thing we
> don't diag by default is Wmicrosoft-enum-forward-reference since that's
> only an Extension and not an ExtWarn. We don't expose -pedantic from
> clang-cl, so this seemed like a somewhat natural mapping to me.
>
> Should /permissive- map to -Wmicrosoft instead and turn on the parts of
> -Wmicrosoft that are Extensions?
>

Did you mean on or off? I think that their intent is that things like
__declspec remain OK. They want to diagnose non-conforming extensions like
crazy template stuff, bogus typedef syntax, bad main function definitions,
etc.


> Should we just ignore /permissive- and possibly make some of our
> -Wmicrosoft Extensions ExtWarns instead?
>
> On Mon, Apr 24, 2017 at 2:10 PM, David Majnemer 
> wrote:
>
>> -pedantic means "Issue all the warnings demanded by strict ISO C and ISO
>> C++; reject all programs that use forbidden extensions, and some other
>> programs that do not follow ISO C and ISO C++."
>> I believe it is more akin to -fno-ms-compatibility as it disables
>> compatibility hacks.
>>
>> On Mon, Apr 24, 2017 at 11:02 AM, Nico Weber  wrote:
>>
>>> It does sound pretty similar to me from the blog post. I think this is a
>>> decent place to start from.
>>>
>>> On Apr 24, 2017 11:55 AM, "David Majnemer via Phabricator via
>>> cfe-commits"  wrote:
>>>
 majnemer requested changes to this revision.
 majnemer added a comment.
 This revision now requires changes to proceed.

 I don't think this is correct. GDR (of Microsoft) says the behavior is
 different: https://www.reddit.com/r/cpp/comm
 
   LOG(INFO) << "n_window_index: " << n_window_index;
 ents/5dh7j5/visual_c_introduces_permissive_for_conformance/da5fxjj/
 


 https://reviews.llvm.org/D32435



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

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


[PATCH] D32269: [Driver] Add iSOFTLinux to GNU ToolChains X86Triple

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

Hi Saleem,

Please check whether or not "the correct GCC search dir" for x86_64-isoft-linux 
firstly, please point out my fault, thanks!

And sysroot structure shown as:

  $ tree clang/test/Driver/Inputs/isoft_linux_4_tree
  
  ├── lib
  └── usr
  ├── lib
  │   └── gcc
  │   └── x86_64-isoft-linux
  │   └── 6.3.0
  │   ├── crtbegin.o
  │   ├── crtbeginT.o
  │   └── crtfastmath.o
  └── x86_64-isoft-linux
  └── lib

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D32269

Files:
  lib/Driver/ToolChains/Gnu.cpp
  test/Driver/linux-ld.c


Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -443,6 +443,33 @@
 // CHECK-BASIC-LIBCXX-C-LINK: "--sysroot=[[SYSROOT]]"
 // CHECK-BASIC-LIBCXX-C-LINK: "-L[[SYSROOT]]/usr/bin/../lib"
 //
+// Check iSOFTLinux v4.0 on x86
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-isoft-linux -rtlib=platform \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/isoft_linux_4_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ISOFT-4-X86_64 %s
+// CHECK-ISOFT-4-X86_64--NOT: warning:
+// CHECK-ISOFT-4-X86_64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-ISOFT-4-X86_64: "--eh-frame-hdr"
+// CHECK-ISOFT-4-X86_64: "-m" "elf_x86_64"
+// CHECK-ISOFT-4-X86_64: "-dynamic-linker"
+// CHECK-ISOFT-4-X86_64: 
"{{.*}}/usr/lib/gcc/x86_64-isoft-linux/6.3.0{{/|}}crtbegin.o"
+// CHECK-ISOFT-4-X86_64: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-isoft-linux/6.3.0"
+// CHECK-ISOFT-4-X86_64: 
"-L[[SYSROOT]]/usr/lib/gcc/x86_64-isoft-linux/6.3.0/../../../../x86_64-isoft-linux/lib"
+// CHECK-ISOFT-4-X86_64: 
"-L[[SYSROOT]]/usr/lib/gcc/x86_64-isoft-linux/6.3.0/../../.."
+// CHECK-ISOFT-4-X86_64: "-L[[SYSROOT]]/lib"
+// CHECK-ISOFT-4-X86_64: "-L[[SYSROOT]]/usr/lib"
+// CHECK-ISOFT-4-X86_64: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
+// CHECK-ISOFT-4-X86_64: "-lc"
+// CHECK-ISOFT-4-X86_64: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
+//
+// RUN: %clang %s -### -o %t.o 2>&1 --target=x86_64-everest-linux
+// RUN: %clang %s -### -o %t.o 2>&1 --target=x86_64-pure64-linux
+// RUN: %clang %s -### -o %t.o 2>&1 --target=i686-isoft-linux
+// RUN: %clang %s -### -o %t.o 2>&1 --target=i686-everest-linux
+// RUN: %clang %s -### -o %t.o 2>&1 --target=i686-pure64-linux
+//
 // Test a very broken version of multiarch that shipped in Ubuntu 11.04.
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=i386-unknown-linux \
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1759,6 +1759,9 @@
   static const char *const X86_64LibDirs[] = {"/lib64", "/lib"};
   static const char *const X86_64Triples[] = {
   "x86_64-linux-gnu",   "x86_64-unknown-linux-gnu",
+  "x86_64-isoft-linux", "x86_64-isoft-linux-gnu",
+  "x86_64-everest-linux",   "x86_64-everest-linux-gnu",
+  "x86_64-pure64-linux","x86_64-pure64-linux-gnu",
   "x86_64-pc-linux-gnu","x86_64-redhat-linux6E",
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
@@ -1768,6 +1771,9 @@
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {
   "i686-linux-gnu",   "i686-pc-linux-gnu", "i486-linux-gnu",
+  "i686-isoft-linux", "i686-isoft-linux-gnu",
+  "i686-everest-linux",   "i686-everest-linux-gnu",
+  "i686-pure64-linux","i686-pure64-linux-gnu",
   "i386-linux-gnu",   "i386-redhat-linux6E",   "i686-redhat-linux",
   "i586-redhat-linux","i386-redhat-linux", "i586-suse-linux",
   "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android",


Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -443,6 +443,33 @@
 // CHECK-BASIC-LIBCXX-C-LINK: "--sysroot=[[SYSROOT]]"
 // CHECK-BASIC-LIBCXX-C-LINK: "-L[[SYSROOT]]/usr/bin/../lib"
 //
+// Check iSOFTLinux v4.0 on x86
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-isoft-linux -rtlib=platform \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/isoft_linux_4_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ISOFT-4-X86_64 %s
+// CHECK-ISOFT-4-X86_64--NOT: warning:
+// CHECK-ISOFT-4-X86_64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-ISOFT-4-X86_64: "--eh-frame-hdr"
+// CHECK-ISOFT-4-X86_64: "-m" "elf_x86_64"
+// CHECK-ISOFT-4-X86_64: "-dynamic-linker"
+// CHECK-ISOFT-4-X86_64: "{{.*}}/usr/lib/gcc/x86_64-isoft-linux/6.3.0{{/|}}crtbegin.o"
+

[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-04-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1105-1119
+  // Alloca always returns a pointer in alloca address space, which may
+  // be different from the type defined by the language. For example,
+  // in C++ the auto variables are in the default address space. Therefore
+  // cast alloca to the expected address space when necessary.
+  auto Addr = address.getPointer();
+  auto AddrTy = cast(Addr->getType());
+  auto ExpectedAddrSpace = 
CGM.getTypes().getVariableType(D)->getAddressSpace();

rjmccall wrote:
> Anastasia wrote:
> > yaxunl wrote:
> > > yaxunl wrote:
> > > > t-tye wrote:
> > > > > Is any assert done to ensure that it is legal to address space cast 
> > > > > from variable address space to expected address space? Presumably the 
> > > > > language, by definition, will only be causing legal casts. For 
> > > > > example from alloca address space to generic (which includes the 
> > > > > alloca address space).
> > > > > 
> > > > > For OpenCL, can you explain how the local variable can have the 
> > > > > constant address space and use an alloca for allocation? Wouldn't a 
> > > > > constant address space mean it was static and so should not be using 
> > > > > alloca? And if it is using an alloca, how can it then be accessed as 
> > > > > if it was in constant address space?
> > > > If the auto var has address space qualifier specified through 
> > > > `__attribute__((address_space(n)))`, there is not much we can check in 
> > > > clang since it is target dependent. We will just emit address space 
> > > > cast when necessary and let the backend check the validity of the 
> > > > address space cast.
> > > > 
> > > > Otherwise, for OpenCL, we can assert the expected address space is 
> > > > default (for OpenCL default address space in AST represents private 
> > > > address space in source language) or constant. For other languages we 
> > > > can assert the expected address space qualifier is default (no address 
> > > > space qualifier). It is not convenient to further check whether the 
> > > > emitted LLVM address space cast instruction is valid since it requires 
> > > > target specific information, therefore such check is better deferred to 
> > > > the backend.
> > > > 
> > > > For OpenCL, currently automatic variable in constant address space is 
> > > > emitted in private address space. For example, currently Clang does not 
> > > > diagnose the following code
> > > > 
> > > > ```
> > > > void f(global int* a) {
> > > >   global int* constant p = a;
> > > > }
> > > > 
> > > > ```
> > > > Instead, it emits alloca for p, essentially treats it as `global int* 
> > > > const p`. This seems to be a bug to me (or maybe we can call it a 
> > > > feature? since there seems no better way to translate this to LLVM IR, 
> > > > or simply diagnose this as an error). However, this is better addressed 
> > > > by another patch.
> > > 
> > > Hi Anastasia,
> > > 
> > > Any comments about the automatic variable in constant address space? 
> > > Thanks.
> > From the spec s6.5.3 it feels like we should follow the same implementation 
> > path in Clang for constant AS inside kernel function as local AS. Because 
> > constant AS objects are essentially global objects.
> > 
> >  Although, we didn't have any issues up to now because const just does the 
> > trick of optimising the objects out eventually. I am not clear if this 
> > creates any issue now with your allocation change. It feels though that it 
> > should probably work fine just as is?
> If these __constant locals are required to be const (or are implicitly 
> const?) and have constant initializers, it seems to me the implementation 
> obviously intended by the spec is that you allocate them statically in the 
> constant address space.  It's likely that just implicitly making the variable 
> static in Sema, the same way you make it implicitly const, will make IRGen 
> and various other parts of the compiler just do the right thing.
My patch does not change the current behaviour of Clang regarding 
function-scope variable in constant address space. Basically there is no issue 
if there is no address taken. However, if there is address taken, there will be 
assertion due to casting private pointer to constant address space. I think 
probably it is better to emit function-scope variable in constant address space 
as global variable in constant address space instead of alloca, as John 
suggested.




Comment at: lib/CodeGen/CGDecl.cpp:1105-1119
+  // Alloca always returns a pointer in alloca address space, which may
+  // be different from the type defined by the language. For example,
+  // in C++ the auto variables are in the default address space. Therefore
+  // cast alloca to the expected address space when necessary.
+  auto Addr = address.getPointer();
+  auto AddrTy = cast(Addr->getType());
+  auto ExpectedAddrSpace = 
CGM.getTypes().getVariableType(D)->getAddressSpace();

[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-04-24 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1105-1119
+  // Alloca always returns a pointer in alloca address space, which may
+  // be different from the type defined by the language. For example,
+  // in C++ the auto variables are in the default address space. Therefore
+  // cast alloca to the expected address space when necessary.
+  auto Addr = address.getPointer();
+  auto AddrTy = cast(Addr->getType());
+  auto ExpectedAddrSpace = 
CGM.getTypes().getVariableType(D)->getAddressSpace();

yaxunl wrote:
> yaxunl wrote:
> > rjmccall wrote:
> > > Anastasia wrote:
> > > > yaxunl wrote:
> > > > > yaxunl wrote:
> > > > > > t-tye wrote:
> > > > > > > Is any assert done to ensure that it is legal to address space 
> > > > > > > cast from variable address space to expected address space? 
> > > > > > > Presumably the language, by definition, will only be causing 
> > > > > > > legal casts. For example from alloca address space to generic 
> > > > > > > (which includes the alloca address space).
> > > > > > > 
> > > > > > > For OpenCL, can you explain how the local variable can have the 
> > > > > > > constant address space and use an alloca for allocation? Wouldn't 
> > > > > > > a constant address space mean it was static and so should not be 
> > > > > > > using alloca? And if it is using an alloca, how can it then be 
> > > > > > > accessed as if it was in constant address space?
> > > > > > If the auto var has address space qualifier specified through 
> > > > > > `__attribute__((address_space(n)))`, there is not much we can check 
> > > > > > in clang since it is target dependent. We will just emit address 
> > > > > > space cast when necessary and let the backend check the validity of 
> > > > > > the address space cast.
> > > > > > 
> > > > > > Otherwise, for OpenCL, we can assert the expected address space is 
> > > > > > default (for OpenCL default address space in AST represents private 
> > > > > > address space in source language) or constant. For other languages 
> > > > > > we can assert the expected address space qualifier is default (no 
> > > > > > address space qualifier). It is not convenient to further check 
> > > > > > whether the emitted LLVM address space cast instruction is valid 
> > > > > > since it requires target specific information, therefore such check 
> > > > > > is better deferred to the backend.
> > > > > > 
> > > > > > For OpenCL, currently automatic variable in constant address space 
> > > > > > is emitted in private address space. For example, currently Clang 
> > > > > > does not diagnose the following code
> > > > > > 
> > > > > > ```
> > > > > > void f(global int* a) {
> > > > > >   global int* constant p = a;
> > > > > > }
> > > > > > 
> > > > > > ```
> > > > > > Instead, it emits alloca for p, essentially treats it as `global 
> > > > > > int* const p`. This seems to be a bug to me (or maybe we can call 
> > > > > > it a feature? since there seems no better way to translate this to 
> > > > > > LLVM IR, or simply diagnose this as an error). However, this is 
> > > > > > better addressed by another patch.
> > > > > 
> > > > > Hi Anastasia,
> > > > > 
> > > > > Any comments about the automatic variable in constant address space? 
> > > > > Thanks.
> > > > From the spec s6.5.3 it feels like we should follow the same 
> > > > implementation path in Clang for constant AS inside kernel function as 
> > > > local AS. Because constant AS objects are essentially global objects.
> > > > 
> > > >  Although, we didn't have any issues up to now because const just does 
> > > > the trick of optimising the objects out eventually. I am not clear if 
> > > > this creates any issue now with your allocation change. It feels though 
> > > > that it should probably work fine just as is?
> > > If these __constant locals are required to be const (or are implicitly 
> > > const?) and have constant initializers, it seems to me the implementation 
> > > obviously intended by the spec is that you allocate them statically in 
> > > the constant address space.  It's likely that just implicitly making the 
> > > variable static in Sema, the same way you make it implicitly const, will 
> > > make IRGen and various other parts of the compiler just do the right 
> > > thing.
> > My patch does not change the current behaviour of Clang regarding 
> > function-scope variable in constant address space. Basically there is no 
> > issue if there is no address taken. However, if there is address taken, 
> > there will be assertion due to casting private pointer to constant address 
> > space. I think probably it is better to emit function-scope variable in 
> > constant address space as global variable in constant address space instead 
> > of alloca, as John suggested.
> > 
> I agree function-scope variable in constant address space should be emitted 
> as global variable in constant address space instead of alloca. However, in 
> OpenCL 1.2 secti

[PATCH] D32456: [ubsan] Make the alignment check work with some extern decls (PR32630)

2017-04-24 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D32456#736120, @efriedma wrote:

> > Note: it would still not be able to catch the following case --
>
> Do you know why?


As-written, the alignment check doesn't apply to loads and stores on 
non-pointer POD types. The reason why is probably that most of these 
loads/stores happen on the stack, where the data should be aligned.




Comment at: lib/CodeGen/CodeGenModule.cpp:2319
+  // The alignment sanitizer can catch more bugs if we don't attach
+  // alignment info to extern globals.
+} else {

efriedma wrote:
> If we don't explicitly set the alignment, is it 1?  Or is it picking up the 
> alignment from the type somehow?
If the alignment isn't explicitly set, it is initialized to 0. The LangRef 
states: 'Either global variable definitions or declarations may have an 
explicit section to be placed in and may have an optional explicit alignment 
specified'. It should be OK to not specify the alignment.


https://reviews.llvm.org/D32456



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


  1   2   >