[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 103163.
johannes added a comment.

- Add the option to not use compilation databases.
- Add a basic test.


https://reviews.llvm.org/D34329

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/ASTDiff/CMakeLists.txt
  lib/Tooling/CMakeLists.txt
  test/Tooling/clang-diff-basic.cpp
  tools/CMakeLists.txt
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- /dev/null
+++ tools/clang-diff/ClangDiff.cpp
@@ -0,0 +1,101 @@
+//===- ClangDiff.cpp - compare source files by AST nodes --*- C++ -*- -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements a tool for syntax tree based comparison using
+// Tooling/ASTDiff.
+//
+//===--===//
+
+#include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace tooling;
+
+static cl::OptionCategory ClangDiffCategory("clang-diff options");
+
+static cl::opt
+DumpAST("ast-dump",
+cl::desc("Print the internal representation of the AST as JSON."),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settigns from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt SourcePath(cl::Positional, cl::desc(""),
+   cl::Required,
+   cl::cat(ClangDiffCategory));
+
+static cl::opt DestinationPath(cl::Positional,
+cl::desc(""),
+cl::Optional,
+cl::cat(ClangDiffCategory));
+
+static std::unique_ptr getAST(const StringRef Filename) {
+  std::string ErrorMessage;
+  std::unique_ptr Compilations;
+  if (!NoCompilationDatabase)
+Compilations =
+CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+  if (!Compilations) {
+if (!NoCompilationDatabase)
+  llvm::errs()
+  << "Error while trying to load a compilation database, running "
+ "without flags.\n"
+  << ErrorMessage;
+Compilations.reset(
+new FixedCompilationDatabase(".", std::vector()));
+  }
+  std::array Files = {{Filename}};
+  ClangTool Tool(*Compilations, Files);
+  std::vector> ASTs;
+  Tool.buildASTs(ASTs);
+  if (ASTs.size() != Files.size())
+return nullptr;
+  return std::move(ASTs[0]);
+}
+
+int main(int argc, const char **argv) {
+  cl::HideUnrelatedOptions(ClangDiffCategory);
+  if (!cl::ParseCommandLineOptions(argc, argv)) {
+cl::PrintOptionValues();
+return 1;
+  }
+
+  if (DumpAST) {
+if (!DestinationPath.empty()) {
+  llvm::errs() << "Error: Please specify exactly one filename.\n";
+  return 1;
+}
+std::unique_ptr AST = getAST(SourcePath);
+if (!AST)
+  return 1;
+clang::diff::TreeRoot Tree(AST->getASTContext());
+Tree.printAsJson();
+return 0;
+  }
+
+  if (DestinationPath.empty()) {
+llvm::errs() << "Error: Exactly two paths are required.\n";
+return 1;
+  }
+
+  std::unique_ptr Src = getAST(SourcePath);
+  std::unique_ptr Dst = getAST(DestinationPath);
+  if (!Src || !Dst)
+return 1;
+
+  clang::diff::runDiff(Src->getASTContext(), Dst->getASTContext());
+
+  return 0;
+}
Index: tools/clang-diff/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-diff/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_executable(clang-diff
+  ClangDiff.cpp
+  )
+
+target_link_libraries(clang-diff
+  clangAST
+  clangBasic
+  clangFrontend
+  clangLex
+  clangTooling
+  clangToolingASTDiff
+  )
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
 add_clang_subdirectory(clang-format-vs)
 add_clang_subdirectory(clang-fuzzer)
Index: test/Tooling/clang-diff-basic.cpp
===
--- /dev/null
+++ test/Tooling/clang-diff-basic.cpp
@@ -0,0 +1,65 @@
+// RUN: awk '/^.. src/{f=1;next}/^.. end src/{f=0}f' %s > %T/src.cpp
+// RUN: awk '/^.. dst/{f=1;next}/^.. end dst/{f=0}f' %s > %T/dst.cpp
+// 

[PATCH] D34266: Static Analyzer - Localizability Checker: New Localizable APIs for macOS High Sierra & iOS 11

2017-06-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Hmm, should there be new tests that demonstrate that we cover the new APIs?


Repository:
  rL LLVM

https://reviews.llvm.org/D34266



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:123
+
+void runDiff(ASTContext &AST1, ASTContext &AST2);
+

This is the main exposed interface?

Generally, if all we want to do is printing, I wouldn't put that into a library 
in Tooling, but just implement a tools/ASTDiffer or somesuch.

If you want to make this a library, it should return the diff in some form 
that's nice to use (or print).



https://reviews.llvm.org/D34329



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


[PATCH] D34277: [analyzer] Bump default performance thresholds?

2017-06-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Gabor makes such a good point. Maybe we should commit the zombie symbols patch 
as well (:


https://reviews.llvm.org/D34277



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


[PATCH] D34304: Allow CompilerInvocations to generate .d files.

2017-06-20 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D34304#784496, @saugustine wrote:

> In https://reviews.llvm.org/D34304#783675, @klimek wrote:
>
> > I think a better way might be to generally leave dependency options alone, 
> > add a default argument adapter to filter out all deps related flags, and 
> > allow users to add their own argument adapters that don't do that.
>
>
> This argument adapter would have to be passed down in a similar way, no?
>
> buildASTFromCodeWithArgs, toolIinvocation::Run, and newInvocation are all 
> entry-points that would need this behavior, and all are called by themselves 
> in one place or another.


I think it's cleaner, because it uses a concept we already have (argument 
adapters).

> I'm happy to do that, as it is quite a bit more flexible, but it doesn't seem 
> any cleaner.




https://reviews.llvm.org/D34304



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


[PATCH] D34263: [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros

2017-06-20 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

oh, and lg from my side


https://reviews.llvm.org/D34263



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


[PATCH] D34263: [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros

2017-06-20 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D34263#784168, @akyrtzi wrote:

> In https://reviews.llvm.org/D34263#783694, @klimek wrote:
>
> > how many patches for single file mode are coming down the road, though? I'm 
> > somewhat concerned about the overall complexity it'll add to clang.
>
>
> There is no other patch for using this preprocessor option. Any related 
> improvements down the road will be about general improvements for error 
> recovery, for example things like this:
>
> - Introduce an `UnresolvedTypename` type instead of changing unresolved types 
> to `int`.
> - For `@interace A : B`, don't completely drop `B` from the super-class list 
> of `A` if it is unresolved. These kind of improvements are not conditional.


That's great! I was always hoping we'd get some diag improvements out of these 
:D


https://reviews.llvm.org/D34263



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

I do not see any test cases for this patch. Could you add them as well?

Are you sure that this representation is ok? 
How do you handle the following case?

  struct A {
A() {
  X x;
  x.virtualMethod(); // this virtual call is ok
}
  }
  int main() {
A a;
  }




Comment at: VirtualCallChecker.cpp:44
+  private:
+const unsigned Flag;
+bool Found;

The name of this flag is not descriptive enough. Please choose a name that 
refers to what are you using this value for.



Comment at: VirtualCallChecker.cpp:79
+  ProgramStateRef state = N->getState();
+  const unsigned ctorflag = state->get();
+  const unsigned dtorflag = state->get();

Variable names should start with uppercase letter.



Comment at: VirtualCallChecker.cpp:83
+  const CXXConstructorDecl *CD =
+dyn_cast(LCtx->getDecl());
+  const CXXDestructorDecl *DD =

Are you sure that the LCtx->getDecl can not return null? 



Comment at: VirtualCallChecker.cpp:114
+  CheckerContext &C) const {
+  const Decl *D = dyn_cast_or_null(Call.getDecl());
+  if (!D)

Do you need this cast here?



Comment at: VirtualCallChecker.cpp:119
+  ProgramStateRef state = C.getState();
+  const unsigned ctorflag = state->get();
+  const unsigned dtorflag = state->get();

Querying the state is not free, I think you should also query something from 
the state once you are sure that you will need that.



Comment at: VirtualCallChecker.cpp:158
+  // GDM of constructor and destructor. 
+  if (isVirtualCall(CE) && ctorflag > 0 && state->get() == 0) {
+if (!BT_CT) {

I don't think this is the right approach. Once you increased the ObjectFlag on 
a path, you will never report anything on that path anymore. I think it might 
be better to have a map from Symbols (representing this) to ctor/dtors or some 
other approach. 



Comment at: VirtualCallChecker.cpp:260
+  if (SFC->inTopFrame()) {
+  const FunctionDecl *FD = SFC->getDecl()->getAsFunction();
+if (!FD)

The formatting seems to be off here I recommend using clang format.


https://reviews.llvm.org/D34275



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


[PATCH] D34263: [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros

2017-06-20 Thread Vladimir Voskresensky via Phabricator via cfe-commits
voskresensky.vladimir added a comment.

> Here's an example to clarify the difference:

Thanks for the example. You are right, I missed this difference in patch.


https://reviews.llvm.org/D34263



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes marked 10 inline comments as done.
johannes added inline comments.



Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:123
+
+void runDiff(ASTContext &AST1, ASTContext &AST2);
+

klimek wrote:
> This is the main exposed interface?
> 
> Generally, if all we want to do is printing, I wouldn't put that into a 
> library in Tooling, but just implement a tools/ASTDiffer or somesuch.
> 
> If you want to make this a library, it should return the diff in some form 
> that's nice to use (or print).
> 
I started out by creating a self contained tool, that's why the interface does 
not really make sense.

I will change it to provide the mappings and the edit script in a nice way, 
this might be quite useful.


https://reviews.llvm.org/D34329



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


[PATCH] D34392: [index] Nested class declarations should be annotated with the "specializationOf" relation if they pseudo-override a type in the base template

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This fixes an issue where Xcode's renaming engine couldn't find the reference 
to the second occurrence of "InnerClass" in this example:

  template struct Ts { template struct InnerClass { }; 
};
  
  template<> struct Ts { template struct InnerClass; // This 
occurrence wasn't renamed
  };


Repository:
  rL LLVM

https://reviews.llvm.org/D34392

Files:
  lib/Index/IndexDecl.cpp
  test/Index/Core/index-source.cpp


Index: test/Index/Core/index-source.cpp
===
--- test/Index/Core/index-source.cpp
+++ test/Index/Core/index-source.cpp
@@ -134,6 +134,9 @@
 
   template struct InnerTemplate { };
   template struct InnerTemplate  { };
+
+  template
+  class InnerClass { };
 };
 
 template<>
@@ -195,8 +198,22 @@
 // CHECK-NEXT: RelChild
 // CHECK-NEXT: RelSpecialization | InnerTemplate | 
c:@ST>2#T#T@PseudoOverridesInSpecializations@ST>1#T@InnerTemplate
   template struct InnerTemplate  { };
+
+  template
+  class InnerClass;
+// CHECK: [[@LINE-1]]:9 | class(Gen)/C++ | InnerClass | 
c:@S@PseudoOverridesInSpecializations>#d#I@ST>1#T@InnerClass |  | 
Ref,RelCont,RelSpecialization | rel: 2
+// CHECK-NEXT: RelCont
+// CHECK-NEXT: RelSpecialization | InnerClass | 
c:@ST>2#T#T@PseudoOverridesInSpecializations@ST>1#T@InnerClass
 };
 
+template
+class PseudoOverridesInSpecializations::InnerClass {
+};
+// CHECK: [[@LINE-2]]:54 | class(Gen)/C++ | InnerClass | 
c:@S@PseudoOverridesInSpecializations>#d#I@ST>1#T@InnerClass |  | 
Def,RelChild | rel: 1
+// CHECK-NEXT: RelChild
+// CHECK: [[@LINE-4]]:7 | class(Gen)/C++ | PseudoOverridesInSpecializations | 
c:@ST>2#T#T@PseudoOverridesInSpecializations |  | Ref,RelCont | rel: 
1
+// CHECK-NEXT: RelCont
+
 template
 class PseudoOverridesInSpecializations {
   typedef float TypealiasOrRecord;
Index: lib/Index/IndexDecl.cpp
===
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -351,9 +351,11 @@
 IndexCtx.indexTagDecl(D, Relations);
   } else {
 auto *Parent = dyn_cast(D->getDeclContext());
+SmallVector Relations;
+gatherTemplatePseudoOverrides(D, Relations);
 return IndexCtx.handleReference(D, D->getLocation(), Parent,
 D->getLexicalDeclContext(),
-SymbolRoleSet());
+SymbolRoleSet(), Relations);
   }
 }
 return true;


Index: test/Index/Core/index-source.cpp
===
--- test/Index/Core/index-source.cpp
+++ test/Index/Core/index-source.cpp
@@ -134,6 +134,9 @@
 
   template struct InnerTemplate { };
   template struct InnerTemplate  { };
+
+  template
+  class InnerClass { };
 };
 
 template<>
@@ -195,8 +198,22 @@
 // CHECK-NEXT: RelChild
 // CHECK-NEXT: RelSpecialization | InnerTemplate | c:@ST>2#T#T@PseudoOverridesInSpecializations@ST>1#T@InnerTemplate
   template struct InnerTemplate  { };
+
+  template
+  class InnerClass;
+// CHECK: [[@LINE-1]]:9 | class(Gen)/C++ | InnerClass | c:@S@PseudoOverridesInSpecializations>#d#I@ST>1#T@InnerClass |  | Ref,RelCont,RelSpecialization | rel: 2
+// CHECK-NEXT: RelCont
+// CHECK-NEXT: RelSpecialization | InnerClass | c:@ST>2#T#T@PseudoOverridesInSpecializations@ST>1#T@InnerClass
 };
 
+template
+class PseudoOverridesInSpecializations::InnerClass {
+};
+// CHECK: [[@LINE-2]]:54 | class(Gen)/C++ | InnerClass | c:@S@PseudoOverridesInSpecializations>#d#I@ST>1#T@InnerClass |  | Def,RelChild | rel: 1
+// CHECK-NEXT: RelChild
+// CHECK: [[@LINE-4]]:7 | class(Gen)/C++ | PseudoOverridesInSpecializations | c:@ST>2#T#T@PseudoOverridesInSpecializations |  | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont
+
 template
 class PseudoOverridesInSpecializations {
   typedef float TypealiasOrRecord;
Index: lib/Index/IndexDecl.cpp
===
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -351,9 +351,11 @@
 IndexCtx.indexTagDecl(D, Relations);
   } else {
 auto *Parent = dyn_cast(D->getDeclContext());
+SmallVector Relations;
+gatherTemplatePseudoOverrides(D, Relations);
 return IndexCtx.handleReference(D, D->getLocation(), Parent,
 D->getLexicalDeclContext(),
-SymbolRoleSet());
+SymbolRoleSet(), Relations);
   }
 }
 return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34268: [clang] Fix format specifiers fixits for nested macros

2017-06-20 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.

LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D34268



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 103180.
wangxindsb added a comment.

Add test case for the patch


https://reviews.llvm.org/D34275

Files:
  virtualcall.cpp

Index: virtualcall.cpp
===
--- virtualcall.cpp
+++ virtualcall.cpp
@@ -1,79 +1,45 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
-
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
-
 class A {
 public:
   A();
   A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0; // from Sema: expected-note {{'foo' declared here}}
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
 A::A(int i) {
   foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +53,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -115,7 +75,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +84,65 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
-}
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
 
-#include "virtualcall.h"
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
 
-#define AS_SYSTEM
-#include "virtualcall.h"
-#undef AS_SYSTEM
+  H(int i) {
+G g;
+g.foo();
+g.bar();
+  // no warning
+f();
+  // expected-warning:Call to virtual function during construction
+H& h = *this;
+h.f();
+  // expected-warning:Call to virtual function during construction
+  }
+};
+
+class X {
+public:
+  X() {
+g();
+  // expected-warning:Call to virtual function during construction
+  }
+  X(int i) {
+if (i > 0) {
+  X x

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb added a comment.

> I do not see any test cases for this patch. Could you add them as well?

I add the test case just now.

> How do you handle the following case?
> 
>   struct A {
> A() {
>   X x;
>   x.virtualMethod(); // this virtual call is ok
> }
>   }
>   int main() {
> A a;
>   }

I use the checker to check the code above, the checker works as expect and 
doesn't throw the warning.


https://reviews.llvm.org/D34275



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Looking at the output of the tool, I have the following suggestion:

- We should avoid implicit expressions (We don't need to see things like 
`Insert ImplicitCastExpr(21) into BinaryOperator: *(22) at 0`). This can be 
done in a follow-up patch though.




Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:25
+
+using namespace llvm;
+using namespace clang;

There's no need to include the `using namespace` declarations in the header.



Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:35
+/// Sentinel value for invalid nodes.
+const NodeId NoNodeId = -1;
+

`InvalidNodeId` sounds better IMHO.



Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:123
+
+void runDiff(ASTContext &AST1, ASTContext &AST2);
+

johannes wrote:
> klimek wrote:
> > This is the main exposed interface?
> > 
> > Generally, if all we want to do is printing, I wouldn't put that into a 
> > library in Tooling, but just implement a tools/ASTDiffer or somesuch.
> > 
> > If you want to make this a library, it should return the diff in some form 
> > that's nice to use (or print).
> > 
> I started out by creating a self contained tool, that's why the interface 
> does not really make sense.
> 
> I will change it to provide the mappings and the edit script in a nice way, 
> this might be quite useful.
I agree with Manuel here. We should move `runDiff` to the tool and and expose 
the `ClandDiff` interface in the header.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:170
+
+std::string TreeRoot::getSourceString(SourceLocation SourceBegin,
+  SourceLocation SourceEnd) const {

Please use `Lexer::getSourceText` instead of this custom function.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:474
+for (SNodeId D1 = LMD1 + 1; D1 <= Id1; ++D1) {
+  double DeletionCost = 1.0;
+  ForestDist[D1][LMD2] = ForestDist[D1 - 1][LMD2] + DeletionCost;

Are the `DeletionCost` and `InsertionCost` constants or are you planning to 
modify them in the future?



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:591
+const Node &N2 = T2.getNode(Id2);
+for (size_t Id = 0; Id < N1.Children.size(); ++Id)
+  addIsomorphicSubTrees(M, N1.Children[Id], N2.Children[Id]);

The `for` loops in LLVM typically store the end value in a separate variable, 
e.g:

`for (size_t Id = 0, E = N1.Children.size(); Id < E; ++Id)`

Please update this and similar `for` loops in this patch.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:693
+  H2 = L2.pop();
+  for (NodeId Id1 : H1)
+for (NodeId Id2 : H2)

Please wrap these loops in braces.



Comment at: test/Tooling/clang-diff-basic.cpp:3
+// RUN: awk '/^.. dst/{f=1;next}/^.. end dst/{f=0}f' %s > %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck 
%s

I'd prefer it if we used something like `clang -E` and preprocessor to generate 
the two files.

E.g.:

```
RUN: %clang_cc1 -E %s > %T/src.cpp
RUN: %clang_cc1 -E %s -D DEST > %T/dst.cpp
#ifndef DEST
namespace src { };
#else
namespace dst { };
#endif
```



Comment at: test/Tooling/clang-diff-basic.cpp:4
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck 
%s
+

Why do you need two invocations of `clang-diff` with the same arguments?


https://reviews.llvm.org/D34329



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Note that when you update the differential revision you need to upload the 
whole diff. Your diff now only contains the tests but not the code.

In https://reviews.llvm.org/D34275#785189, @wangxindsb wrote:

> > How do you handle the following case?
> > 
> >   struct A {
> > A() {
> >   X x;
> >   x.virtualMethod(); // this virtual call is ok
> > }
> >   }
> >   int main() {
> > A a;
> >   }
>
> I use the checker to check the code above, the checker works as expect and 
> doesn't throw the warning.


What about:

  struct A {
A() {
  X x;
  x.virtualMethod(); // this virtual call is ok
  foo(); // should warn here
}
virtual foo();
  }
  int main() {
A a;
  }


Does the checker warn on the second call?




Comment at: virtualcall.cpp:1
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall 
-analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall 
-analyzer-store region -analyzer-config 
optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify 
-std=c++11 %s

Please add the appropriate run lines so you can run the tests using `make 
check`. 


https://reviews.llvm.org/D34275



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


[PATCH] D34395: clang-format: add options to merge empty record body

2017-06-20 Thread Francois Ferrand via Phabricator via cfe-commits
Typz created this revision.
Herald added a subscriber: klimek.

This patch introduces a few extra BraceWrapping options, similar to
`SplitEmptyFunction`, to allow merging empty 'record' bodies (e.g.
class, struct, union and namespace):

- SplitEmptyClass
- SplitEmptyStruct
- SplitEmptyUnion
- SplitEmptyNamespace

The `SplitEmptyFunction` option name has also been simplified/
shortened (from `SplitEmptyFunctionBody`).

These options are helpful when the correspond AfterXXX option is
enabled, to allow merging the empty record:

  class Foo
  {};

In addition, this fixes an unexpected merging of short records, when
the After options are used, which caused to be formatted like
this:

  class Foo
  { void Foo(); };

This is now properly formatted as:

  class Foo
  {
 void Foo();
  };


https://reviews.llvm.org/D34395

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6509,12 +6509,12 @@
MergeInlineOnly);
 }
 
-TEST_F(FormatTest, SplitEmptyFunctionBody) {
+TEST_F(FormatTest, SplitEmptyFunction) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterFunction = true;
-  Style.BraceWrapping.SplitEmptyFunctionBody = false;
+  Style.BraceWrapping.SplitEmptyFunction = false;
   Style.ColumnLimit = 40;
 
   verifyFormat("int f()\n"
@@ -6577,6 +6577,178 @@
Style);
 }
 
+TEST_F(FormatTest, SplitEmptyClass) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterClass = true;
+  Style.BraceWrapping.SplitEmptyClass = false;
+
+  verifyFormat("class Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ class Foo\n"
+   "{};",
+   Style);
+  verifyFormat("template  class Foo\n"
+   "{};",
+   Style);
+  verifyFormat("class Foo\n"
+   "{\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef class Foo\n"
+   "{\n"
+   "} Foo_t;",
+   Style);
+}
+
+TEST_F(FormatTest, SplitEmptyStruct) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterStruct = true;
+  Style.BraceWrapping.SplitEmptyStruct = false;
+
+  verifyFormat("struct Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ struct Foo\n"
+   "{};",
+   Style);
+  verifyFormat("template  struct Foo\n"
+   "{};",
+   Style);
+  verifyFormat("struct Foo\n"
+   "{\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef struct Foo\n"
+   "{\n"
+   "} Foo_t;",
+   Style);
+  //typedef struct Bar {} Bar_t;
+}
+
+TEST_F(FormatTest, SplitEmptyUnion) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterUnion = true;
+  Style.BraceWrapping.SplitEmptyUnion = false;
+
+  verifyFormat("union Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ union Foo\n"
+   "{};",
+   Style);
+  verifyFormat("union Foo\n"
+   "{\n"
+   "  A,\n"
+   "};",
+   Style);
+  verifyFormat("typedef union Foo\n"
+   "{\n"
+   "} Foo_t;",
+   Style);
+}
+
+TEST_F(FormatTest, SplitEmptyNamespace) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterNamespace = true;
+  Style.BraceWrapping.SplitEmptyNamespace = false;
+
+  verifyFormat("namespace Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ namespace Foo\n"
+   "{};",
+   Style);
+  verifyFormat("inline namespace Foo\n"
+   "{};",
+   Style);
+  verifyFormat("namespace Foo\n"
+   "{\n"
+   "void Bar();\n"
+   "};",
+   Style);
+}
+
+TEST_F(FormatTest, NeverMergeShortRecords) {
+  FormatStyle Style = getLLVMStyle();
+
+  verifyFormat("class Foo {\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef class Foo {\n"
+   "  Foo();\n"
+   "} Foo_t;",
+   Style);
+  verifyFormat("struct Foo {\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef struct Foo {\n"
+   "  Foo(

[PATCH] D33030: [libcxxabi] Align unwindHeader on a double-word boundary

2017-06-20 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

In LibreOffice we unfortunately have some dirty code that synthesizes exception 
throwing, calling `__cxa_allocate_exception`, `__cxa_throw` (passing in our own 
exception destructor function), and then, when the exception destructor 
function gets called, assumes we can map from the passed pointer to the 
`__cxa_exception` header preceding it (to get at its `exceptionType` member).  
That code was thus broken by this change.  I have a dirty hack around that 
(checking whether the `__cxa_exception` `exceptionDestructor` member has the 
expected value; if not, adjust: Hack to dynamically adapt to __cxa_exceptiom in 
LLVM 5.0 libcxxabi 
)
 and two questions:

- Is there any estimation when this change will show up in macOS's libcxxabi?  
That would give me an idea which LibreOffice versions I would need to backport 
my fix to.

- Does anybody happen to have a good idea how to do my hacky fix in a cleaner 
way?


Repository:
  rL LLVM

https://reviews.llvm.org/D33030



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


[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: lib/Frontend/ASTUnit.cpp:131-136
+/// \brief Get a source buffer for \p MainFilePath, handling all file-to-file
+/// and file-to-buffer remappings inside \p Invocation.
+static PossiblyOwnedBuffer
+getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation,
+  vfs::FileSystem *VFS,
+  StringRef FilePath) {

ilya-biryukov wrote:
> klimek wrote:
> > If this indeed needs to return a possibly owned buffer, explain when 
> > exactly it is owned and when it is unowned.
> Done. It's owned when read from disk and not owned when taken from 
> CompilerInvocation.PPOptions' file-to-buffer remappings.
After some in person discussion, the idea now is to just always copy and return 
a unique_ptr


https://reviews.llvm.org/D34287



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


[PATCH] D34399: clang-format: introduce InlineOnly short function style

2017-06-20 Thread Francois Ferrand via Phabricator via cfe-commits
Typz created this revision.
Herald added subscribers: rengolin, klimek.

This is the same as Inline, except it does not imply all empty
functions are merged: with this style, empty functions are merged only
if they also match the 'inline' criteria (i.e. defined in a class).

This is helpful to avoid inlining functions in implementations files.


https://reviews.llvm.org/D34399

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6509,6 +6509,49 @@
MergeInlineOnly);
 }
 
+TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) {
+  FormatStyle MergeInlineOnly = getLLVMStyle();
+  MergeInlineOnly.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_InlineOnly;
+  verifyFormat("class C {\n"
+   "  int f() { return 42; }\n"
+   "};",
+   MergeInlineOnly);
+  verifyFormat("int f() {\n"
+   "  return 42;\n"
+   "}",
+   MergeInlineOnly);
+
+  // SFS_InlineOnly does not imply SFS_Empty
+  verifyFormat("class C {\n"
+   "  int f() {}\n"
+   "};",
+   MergeInlineOnly);
+  verifyFormat("int f() {\n"
+   "}", MergeInlineOnly);
+
+  // Also verify behavior when BraceWrapping.AfterFunction = true
+  MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
+  MergeInlineOnly.BraceWrapping.AfterFunction = true;
+  verifyFormat("class C {\n"
+   "  int f() { return 42; }\n"
+   "};",
+   MergeInlineOnly);
+  verifyFormat("int f()\n"
+   "{\n"
+   "  return 42;\n"
+   "}",
+   MergeInlineOnly);
+
+  // SFS_InlineOnly does not imply SFS_Empty
+  verifyFormat("int f()\n"
+   "{\n"
+   "}", MergeInlineOnly);
+  verifyFormat("class C {\n"
+   "  int f() {}\n"
+   "};",
+   MergeInlineOnly);
+}
+
 TEST_F(FormatTest, SplitEmptyFunctionBody) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -224,9 +224,9 @@
 // If necessary, change to something smarter.
 bool MergeShortFunctions =
 Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All ||
-(Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
+(Style.allowEmptyFunctionsOnASingleLine() &&
  I[1]->First->is(tok::r_brace)) ||
-(Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline &&
+(Style.allowShortInlineFunctionsOnASingleLine() &&
  TheLine->Level != 0);
 
 if (Style.CompactNamespaces) {
@@ -282,7 +282,7 @@
 
   unsigned MergedLines = 0;
   if (MergeShortFunctions ||
-  (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
+  (Style.allowEmptyFunctionsOnASingleLine() &&
I[1]->First == I[1]->Last && I + 2 != E &&
I[2]->First->is(tok::r_brace))) {
 MergedLines = tryMergeSimpleBlock(I + 1, E, Limit);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,8 +2480,7 @@
   return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
  Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty ||
  (Left.NestingLevel == 0 && Line.Level == 0 &&
-  Style.AllowShortFunctionsOnASingleLine ==
-  FormatStyle::SFS_Inline);
+  Style.allowShortInlineFunctionsOnASingleLine());
   } else if (Style.Language == FormatStyle::LK_Java) {
 if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next &&
 Right.Next->is(tok::string_literal))
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -96,6 +96,7 @@
 IO.enumCase(Value, "All", FormatStyle::SFS_All);
 IO.enumCase(Value, "true", FormatStyle::SFS_All);
 IO.enumCase(Value, "Inline", FormatStyle::SFS_Inline);
+IO.enumCase(Value, "InlineOnly", FormatStyle::SFS_InlineOnly);
 IO.enumCase(Value, "Empty", FormatStyle::SFS_Empty);
   }
 };
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -184,9 +184,23 @@
   enum ShortFunctionStyle {
 /// \brief Never merge functions into a 

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb added a comment.

> What about:
> 
>   struct A {
> A() {
>   X x;
>   x.virtualMethod(); // this virtual call is ok
>   foo(); // should warn here
> }
> virtual foo();
>   }
>   int main() {
> A a;
>   }
> 
> 
> Does the checker warn on the second call?

Yes, the checker warn on the second call.


https://reviews.llvm.org/D34275



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


[PATCH] D32478: [clang-format] Fix AlignOperands when BreakBeforeBinaryOperators is set

2017-06-20 Thread Francois Ferrand via Phabricator via cfe-commits
Typz marked 7 inline comments as done.
Typz added a comment.

This style is used in the Skia  project.


https://reviews.llvm.org/D32478



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


[PATCH] D32478: [clang-format] Fix AlignOperands when BreakBeforeBinaryOperators is set

2017-06-20 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 103195.
Typz added a comment.

Rebase & fix indentation when newline is inserted after return or equal.


https://reviews.llvm.org/D32478

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -102,7 +102,7 @@
   verifyFormat("var x = a() in\n"
".aa.aa;");
   FormatStyle Style = getGoogleJSStyleWithColumns(80);
-  Style.AlignOperands = true;
+  Style.AlignOperands = FormatStyle::OAS_Align;
   verifyFormat("var x = a() in\n"
".aa.aa;",
Style);
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2702,6 +2702,9 @@
"  > c) {\n"
"}",
Style);
+  verifyFormat("return a\n"
+   "   && bbb;",
+   Style);
   verifyFormat("return (a)\n"
"   // comment\n"
"   + b;",
@@ -2730,11 +2733,103 @@
 
   Style.ColumnLimit = 60;
   verifyFormat("zz\n"
-   "= b\n"
+   "= \n"
"  >> (aa);",
Style);
 }
 
+TEST_F(FormatTest, ExpressionIndentationStrictAlign) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+  Style.AlignOperands = FormatStyle::OAS_StrictAlign;
+
+  verifyFormat("bool value = a\n"
+   "   + a\n"
+   "   + a\n"
+   "  == a\n"
+   " * b\n"
+   " + b\n"
+   "  && a\n"
+   " * a\n"
+   " > c;",
+   Style);
+  verifyFormat("if (a\n"
+   "* \n"
+   "+ aa\n"
+   "== bbb) {\n}",
+   Style);
+  verifyFormat("if (a\n"
+   "+ \n"
+   "  * aa\n"
+   "== bbb) {\n}",
+   Style);
+  verifyFormat("if (a\n"
+   "== \n"
+   "   * aa\n"
+   "   + bbb) {\n}",
+   Style);
+  verifyFormat("if () {\n"
+   "} else if (a\n"
+   "   && b // break\n"
+   "  > c) {\n"
+   "}",
+   Style);
+  verifyFormat("return a\n"
+   "&& bbb;",
+   Style);
+  verifyFormat("return (a)\n"
+   "   // comment\n"
+   " + b;",
+   Style);
+  verifyFormat(
+  "int aa = aa\n"
+  "   * bbb\n"
+  "   + cc;",
+  Style);
+
+  verifyFormat("a\n"
+   "=  + ;",
+   Style);
+
+  verifyFormat("return boost::fusion::at_c<0>().second\n"
+   "== boost::fusion::at_c<1>().second;",
+   Style);
+
+  Style.ColumnLimit = 60;
+  verifyFormat("z\n"
+   "= \n"
+   "   >> (a

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 103196.
wangxindsb added a comment.

Add test case for the virtual call checker.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,45 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
-
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
-
 class A {
 public:
   A();
   A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0; // from Sema: expected-note {{'foo' declared here}}
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
 A::A(int i) {
   foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +53,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -115,7 +75,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +84,65 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
-}
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
 
-#include "virtualcall.h"
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
 
-#define AS_SYSTEM
-#include "virtualcall.h"
-#undef AS_SYSTEM
+  H(int i) {
+G g;
+g.foo();
+g.bar();
+  // no warning
+f();
+  // expected-warning:Call to virtual function during construction
+H& h = *this;
+h.f();
+  // expected-warning:Call to virtual function during construction
+  }
+};
+
+class X {
+public:
+  X() {
+   

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 103199.
wangxindsb added a comment.

Add run line in the test case.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,49 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
 
 class A {
 public:
   A();
   A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0; // from Sema: expected-note {{'foo' declared here}}
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
 A::A(int i) {
   foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +57,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -115,7 +79,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +88,65 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
-}
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
+
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
 
-#include "virtualcall.h"
+  H(int i) {
+G g;
+g.foo();
+g.bar();
+  // no warning
+f();
+  // expected-warning:Call to virtual function during construction
+H& h = *this;
+h.f();
+  // expected-warning:Call to virtual function during construction
+  }
+};
+
+class X {
+public:
+  X() {
+g();
+  // expected-warning:Call to virtual function during constructio

[PATCH] D34395: clang-format: add options to merge empty record body

2017-06-20 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 103202.
Typz added a comment.

Enable merging records for Mozilla style


https://reviews.llvm.org/D34395

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6509,12 +6509,12 @@
MergeInlineOnly);
 }
 
-TEST_F(FormatTest, SplitEmptyFunctionBody) {
+TEST_F(FormatTest, SplitEmptyFunction) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
   Style.BreakBeforeBraces = FormatStyle::BS_Custom;
   Style.BraceWrapping.AfterFunction = true;
-  Style.BraceWrapping.SplitEmptyFunctionBody = false;
+  Style.BraceWrapping.SplitEmptyFunction = false;
   Style.ColumnLimit = 40;
 
   verifyFormat("int f()\n"
@@ -6577,6 +6577,178 @@
Style);
 }
 
+TEST_F(FormatTest, SplitEmptyClass) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterClass = true;
+  Style.BraceWrapping.SplitEmptyClass = false;
+
+  verifyFormat("class Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ class Foo\n"
+   "{};",
+   Style);
+  verifyFormat("template  class Foo\n"
+   "{};",
+   Style);
+  verifyFormat("class Foo\n"
+   "{\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef class Foo\n"
+   "{\n"
+   "} Foo_t;",
+   Style);
+}
+
+TEST_F(FormatTest, SplitEmptyStruct) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterStruct = true;
+  Style.BraceWrapping.SplitEmptyStruct = false;
+
+  verifyFormat("struct Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ struct Foo\n"
+   "{};",
+   Style);
+  verifyFormat("template  struct Foo\n"
+   "{};",
+   Style);
+  verifyFormat("struct Foo\n"
+   "{\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef struct Foo\n"
+   "{\n"
+   "} Foo_t;",
+   Style);
+  //typedef struct Bar {} Bar_t;
+}
+
+TEST_F(FormatTest, SplitEmptyUnion) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterUnion = true;
+  Style.BraceWrapping.SplitEmptyUnion = false;
+
+  verifyFormat("union Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ union Foo\n"
+   "{};",
+   Style);
+  verifyFormat("union Foo\n"
+   "{\n"
+   "  A,\n"
+   "};",
+   Style);
+  verifyFormat("typedef union Foo\n"
+   "{\n"
+   "} Foo_t;",
+   Style);
+}
+
+TEST_F(FormatTest, SplitEmptyNamespace) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterNamespace = true;
+  Style.BraceWrapping.SplitEmptyNamespace = false;
+
+  verifyFormat("namespace Foo\n"
+   "{};",
+   Style);
+  verifyFormat("/* something */ namespace Foo\n"
+   "{};",
+   Style);
+  verifyFormat("inline namespace Foo\n"
+   "{};",
+   Style);
+  verifyFormat("namespace Foo\n"
+   "{\n"
+   "void Bar();\n"
+   "};",
+   Style);
+}
+
+TEST_F(FormatTest, NeverMergeShortRecords) {
+  FormatStyle Style = getLLVMStyle();
+
+  verifyFormat("class Foo {\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef class Foo {\n"
+   "  Foo();\n"
+   "} Foo_t;",
+   Style);
+  verifyFormat("struct Foo {\n"
+   "  Foo();\n"
+   "};",
+   Style);
+  verifyFormat("typedef struct Foo {\n"
+   "  Foo();\n"
+   "} Foo_t;",
+   Style);
+  verifyFormat("union Foo {\n"
+   "  A,\n"
+   "};",
+   Style);
+  verifyFormat("typedef union Foo {\n"
+   "  A,\n"
+   "} Foo_t;",
+   Style);
+  verifyFormat("namespace Foo {\n"
+   "void Bar();\n"
+   "};",
+   Style);
+
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterClass = true;
+  Style.BraceWrapping.AfterStruct = true;
+  Style.BraceWrapping.AfterUnion = true;
+  Style.BraceWrapping.AfterNamespace = true;
+  verifyFormat("class Foo\n"
+   "{\n"
+   "  F

[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 103203.
ilya-biryukov added a comment.

Removed PossiblyOwnedBuffer, added an extra copy instead.
This makes the code much simpler.


https://reviews.llvm.org/D34287

Files:
  include/clang/Frontend/ASTUnit.h
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/CMakeLists.txt
  lib/Frontend/PrecompiledPreamble.cpp

Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- /dev/null
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -0,0 +1,573 @@
+//===--- PrecompiledPreamble.cpp - Build precompiled preambles --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Helper class to build precompiled preamble.
+//
+//===--===//
+
+#include "clang/Frontend/PrecompiledPreamble.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Serialization/ASTWriter.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/CrashRecoveryContext.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
+#include "llvm/Support/MutexGuard.h"
+
+using namespace clang;
+
+namespace {
+
+/// Keeps a track of files to be deleted in destructor.
+class TemporaryFiles {
+public:
+  // A static instance to be used by
+  static TemporaryFiles &getInstance();
+
+private:
+  // Disallow constructing the class directly.
+  TemporaryFiles() = default;
+  // Disallow copy.
+  TemporaryFiles(const TemporaryFiles &) = delete;
+
+public:
+  ~TemporaryFiles();
+
+  /// Adds \p File to a set of tracked files.
+  void addFile(StringRef File);
+
+  /// Remove \p File from disk and from the set of tracked files.
+  void removeFile(StringRef File);
+
+private:
+  llvm::sys::SmartMutex Mutex;
+  llvm::StringSet<> Files;
+};
+
+TemporaryFiles &TemporaryFiles::getInstance() {
+  static TemporaryFiles Instance;
+  return Instance;
+}
+
+TemporaryFiles::~TemporaryFiles() {
+  llvm::MutexGuard Guard(Mutex);
+  for (const auto &File : Files)
+llvm::sys::fs::remove(File.getKey());
+}
+
+void TemporaryFiles::addFile(StringRef File) {
+  llvm::MutexGuard Guard(Mutex);
+  auto IsInserted = Files.insert(File).second;
+  assert(IsInserted && "File has already been added");
+}
+
+void TemporaryFiles::removeFile(StringRef File) {
+  llvm::MutexGuard Guard(Mutex);
+  auto WasPresent = Files.erase(File);
+  assert(WasPresent && "File was not tracked");
+  llvm::sys::fs::remove(File);
+}
+
+class PreambleMacroCallbacks : public PPCallbacks {
+public:
+  PreambleMacroCallbacks(PreambleCallbacks &Callbacks) : Callbacks(Callbacks) {}
+
+  void MacroDefined(const Token &MacroNameTok,
+const MacroDirective *MD) override {
+Callbacks.HandleMacroDefined(MacroNameTok, MD);
+  }
+
+private:
+  PreambleCallbacks &Callbacks;
+};
+
+class PrecompilePreambleAction : public ASTFrontendAction {
+public:
+  PrecompilePreambleAction(PreambleCallbacks &Callbacks)
+  : Callbacks(Callbacks) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override;
+
+  bool hasEmittedPreamblePCH() const { return HasEmittedPreamblePCH; }
+
+  void setEmittedPreamblePCH(ASTWriter &Writer) {
+this->HasEmittedPreamblePCH = true;
+Callbacks.AfterPCHEmitted(Writer);
+  }
+
+  bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); }
+  bool hasCodeCompletionSupport() const override { return false; }
+  bool hasASTFileSupport() const override { return false; }
+  TranslationUnitKind getTranslationUnitKind() override { return TU_Prefix; }
+
+private:
+  friend class PrecompilePreambleConsumer;
+
+  bool HasEmittedPreamblePCH = false;
+  PreambleCallbacks &Callbacks;
+};
+
+class PrecompilePreambleConsumer : public PCHGenerator {
+public:
+  PrecompilePreambleConsumer(PrecompilePreambleAction &Action,
+ const Preprocessor &PP, StringRef isysroot,
+ std::unique_ptr Out)
+  : PCHGenerator(PP, "", isysroot, std::make_shared(),
+ ArrayRef>(),
+ /*AllowASTWithErrors=*/true),
+Action(Action), Out(std::move(Out)) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+Action.Callbacks.HandleTopLevelDecl(DG);
+return true;
+  }
+
+  void HandleTransla

[PATCH] D33719: Add _Float16 as a C/C++ source language type

2017-06-20 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 103201.
SjoerdMeijer edited the summary of this revision.
SjoerdMeijer added a comment.

I have added a fix for mixed __fp16 and _Float16 expressions: _Float16 type is 
converted to __fp16 type and then the operation is completed as if both 
operands were of __fp16 type. I've implemented this by adding _Float16 to the 
FloatingRank. By declaring Float16Rank to be smaller than HalfRank, we 
automatically get the promotions to __fp16 when required. I thought this 
approach is more elegant than adding more special cases in the floating point 
conversion functions.

I've added another test case ##test/Frontend/float16.cpp## that checks the AST 
(this is in addition to the codegen test that we already have). This test also 
checks mixed type expressions.


https://reviews.llvm.org/D33719

Files:
  include/clang-c/Index.h
  include/clang/AST/ASTContext.h
  include/clang/AST/BuiltinTypes.def
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  include/clang/Lex/LiteralSupport.h
  include/clang/Sema/DeclSpec.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/Analysis/PrintfFormatString.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Format/FormatToken.cpp
  lib/Index/USRGeneration.cpp
  lib/Lex/LiteralSupport.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/CodeGenCXX/float16-declarations.cpp
  test/Frontend/float16.cpp
  test/Lexer/half-literal.cpp
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -53,6 +53,7 @@
 BTCASE(Float);
 BTCASE(Double);
 BTCASE(LongDouble);
+BTCASE(Float16);
 BTCASE(Float128);
 BTCASE(NullPtr);
 BTCASE(Overload);
@@ -520,7 +521,7 @@
 TKIND(Char_U);
 TKIND(UChar);
 TKIND(Char16);
-TKIND(Char32);  
+TKIND(Char32);
 TKIND(UShort);
 TKIND(UInt);
 TKIND(ULong);
@@ -538,6 +539,7 @@
 TKIND(Float);
 TKIND(Double);
 TKIND(LongDouble);
+TKIND(Float16);
 TKIND(Float128);
 TKIND(NullPtr);
 TKIND(Overload);
Index: test/Lexer/half-literal.cpp
===
--- test/Lexer/half-literal.cpp
+++ test/Lexer/half-literal.cpp
@@ -1,3 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 float a = 1.0h; // expected-error{{invalid suffix 'h' on floating constant}}
 float b = 1.0H; // expected-error{{invalid suffix 'H' on floating constant}}
+
+_Float16 c = 1.f166; // expected-error{{invalid suffix 'f166' on floating constant}}
+_Float16 d = 1.f1;   // expected-error{{invalid suffix 'f1' on floating constant}}
Index: test/Frontend/float16.cpp
===
--- /dev/null
+++ test/Frontend/float16.cpp
@@ -0,0 +1,297 @@
+// RUN: %clang_cc1 -std=c++11 -ast-dump %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -ast-dump -fnative-half-type %s | FileCheck %s --check-prefix=CHECK-NATIVE
+
+/*  Various contexts where type _Float16 can appear. */
+
+/*  Namespace */
+namespace {
+  _Float16 f1n;
+  _Float16 f2n = 33.f16;
+  _Float16 arr1n[10];
+  _Float16 arr2n[] = { 1.2, 3.0, 3.e4 };
+  const volatile _Float16 func1n(const _Float16 &arg) {
+return arg + f2n + arr1n[4] - arr2n[1];
+  }
+}
+
+//CHECK: |-NamespaceDecl
+//CHECK: | |-VarDecl {{.*}} f1n '_Float16'
+//CHECK: | |-VarDecl {{.*}} f2n '_Float16' cinit
+//CHECK: | | `-FloatingLiteral {{.*}} '_Float16' 3.30e+01
+//CHECK: | |-VarDecl {{.*}} arr1n '_Float16 [10]'
+//CHECK: | |-VarDecl {{.*}} arr2n '_Float16 [3]' cinit
+//CHECK: | | `-InitListExpr {{.*}} '_Float16 [3]'
+//CHECK: | |   |-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | |   | `-FloatingLiteral {{.*}} 'double' 1.20e+00
+//CHECK: | |   |-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | |   | `-FloatingLiteral {{.*}} 'double' 3.00e+00
+//CHECK: | |   `-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | | `-FloatingLiteral {{.*}} 'double' 3.00e+04
+//CHECK: | `-FunctionDecl {{.*}} func1n 'const volatile _Float16 (const _Float16 &)'
+
+/* File */
+_Float16 f1f;
+_Float16 f2f = 32.4;
+_Float16 arr1f[10];
+_Float16 arr2f[] = { -1.2, -3.0, -3.e4 };
+_Float16 func1f(_Float16 arg);
+
+//CHECK: |-VarDecl {{.*}} f1f '_Float16'
+//CHECK: |-VarDecl {{.*}} f2f '_Float16' cinit
+//CHECK: | `-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: |   `-FloatingLiteral {{.*}} 'double' 3.

[PATCH] D34235: [OpenCL] Fix OpenCL and SPIR version metadata generation.

2017-06-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


https://reviews.llvm.org/D34235



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


r305796 - [OpenCL] Fix OpenCL and SPIR version metadata generation.

2017-06-20 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Jun 20 09:30:18 2017
New Revision: 305796

URL: http://llvm.org/viewvc/llvm-project?rev=305796&view=rev
Log:
[OpenCL] Fix OpenCL and SPIR version metadata generation.

Summary: OpenCL and SPIR version metadata must be generated once per module 
instead of once per mangled global value.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: ahatanak, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGenOpenCL/spir_version.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=305796&r1=305795&r2=305796&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jun 20 09:30:18 2017
@@ -506,6 +506,26 @@ void CodeGenModule::Release() {
   LangOpts.CUDADeviceFlushDenormalsToZero ? 1 : 0);
   }
 
+  // Emit OpenCL specific module metadata: OpenCL/SPIR version.
+  if (LangOpts.OpenCL) {
+EmitOpenCLMetadata();
+// Emit SPIR version.
+if (getTriple().getArch() == llvm::Triple::spir ||
+getTriple().getArch() == llvm::Triple::spir64) {
+  // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
+  // opencl.spir.version named metadata.
+  llvm::Metadata *SPIRVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (LangOpts.OpenCLVersion / 100 > 1) ? 0 : 2))};
+  llvm::NamedMDNode *SPIRVerMD =
+  TheModule.getOrInsertNamedMetadata("opencl.spir.version");
+  llvm::LLVMContext &Ctx = TheModule.getContext();
+  SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
+}
+  }
+
   if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
 assert(PLevel < 3 && "Invalid PIC Level");
 getModule().setPICLevel(static_cast(PLevel));
@@ -529,6 +549,20 @@ void CodeGenModule::Release() {
   EmitTargetMetadata();
 }
 
+void CodeGenModule::EmitOpenCLMetadata() {
+  // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
+  // opencl.ocl.version named metadata node.
+  llvm::Metadata *OCLVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (LangOpts.OpenCLVersion % 100) / 10))};
+  llvm::NamedMDNode *OCLVerMD =
+  TheModule.getOrInsertNamedMetadata("opencl.ocl.version");
+  llvm::LLVMContext &Ctx = TheModule.getContext();
+  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+}
+
 void CodeGenModule::UpdateCompletedType(const TagDecl *TD) {
   // Make sure that this type is translated.
   Types.UpdateCompletedType(TD);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=305796&r1=305795&r2=305796&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Jun 20 09:30:18 2017
@@ -1321,6 +1321,9 @@ private:
   /// Emits target specific Metadata for global declarations.
   void EmitTargetMetadata();
 
+  /// Emits OpenCL specific Metadata e.g. OpenCL version.
+  void EmitOpenCLMetadata();
+
   /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
   /// .gcda files in a way that persists in .bc files.
   void EmitCoverageFile();

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=305796&r1=305795&r2=305796&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue Jun 20 09:30:18 2017
@@ -7344,8 +7344,6 @@ public:
 };
 }
 
-static void appendOpenCLVersionMD (CodeGen::CodeGenModule &CGM);
-
 void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 const Decl *D,
 llvm::GlobalValue *GV,
@@ -7402,8 +7400,6 @@ void AMDGPUTargetCodeGenInfo::setTargetA
 if (NumVGPR != 0)
   F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR));
   }
-
-  appendOpenCLVersionMD(M);
 }
 
 unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
@@ -8074,8 +8070,6 @@ class SPIRTargetCodeGenInfo : public Tar
 public:
   SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
 : TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
-  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
-CodeGen::CodeGenModule &M) 

[PATCH] D34263: [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros

2017-06-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305797: [preprocessor] When preprocessor option 
'SingleFileParseMode' is enabled, parse… (authored by akirtzidis).

Changed prior to commit:
  https://reviews.llvm.org/D34263?vs=103067&id=103206#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34263

Files:
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/include/clang/Lex/PreprocessorOptions.h
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PPExpressions.cpp
  cfe/trunk/test/Index/singe-file-parse.m
  cfe/trunk/test/Index/single-file-parse.m

Index: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
===
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h
@@ -96,6 +96,10 @@
   std::string TokenCache;
 
   /// When enabled, preprocessor is in a mode for parsing a single file only.
+  ///
+  /// Disables #includes of other files and if there are unresolved identifiers
+  /// in preprocessor directive conditions it causes all blocks to be parsed so
+  /// that the client can get the maximum amount of information from the parser.
   bool SingleFileParseMode = false;
 
   /// When enabled, the preprocessor will construct editor placeholder tokens.
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -1835,11 +1835,20 @@
   /// \brief A fast PTH version of SkipExcludedConditionalBlock.
   void PTHSkipExcludedConditionalBlock();
 
+  /// Information about the result for evaluating an expression for a
+  /// preprocessor directive.
+  struct DirectiveEvalResult {
+/// Whether the expression was evaluated as true or not.
+bool Conditional;
+/// True if the expression contained identifiers that were undefined.
+bool IncludedUndefinedIds;
+  };
+
   /// \brief Evaluate an integer constant expression that may occur after a
-  /// \#if or \#elif directive and return it as a bool.
+  /// \#if or \#elif directive and return a \p DirectiveEvalResult object.
   ///
   /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
-  bool EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro);
+  DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro);
 
   /// \brief Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/system_header/dependency and \#pragma once.
Index: cfe/trunk/test/Index/single-file-parse.m
===
--- cfe/trunk/test/Index/single-file-parse.m
+++ cfe/trunk/test/Index/single-file-parse.m
@@ -0,0 +1,111 @@
+// RUN: c-index-test -single-file-parse %s | FileCheck %s
+
+#include 
+
+// CHECK-NOT: TypedefDecl=intptr_t
+
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=MyCls
+@interface MyCls
+// CHECK: [[@LINE+1]]:8: ObjCInstanceMethodDecl=some_meth
+-(void)some_meth;
+@end
+
+#if 1
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test1
+@interface Test1 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test2 @end
+#endif
+
+#if 0
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test3 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test4
+@interface Test4 @end
+#endif
+
+#if SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test5
+@interface Test5 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test6
+@interface Test6 @end
+#endif
+
+#define SOMETHING_DEFINED 1
+#if SOMETHING_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test7
+@interface Test7 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test8 @end
+#endif
+
+#if defined(SOMETHING_NOT_DEFINED)
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test9
+@interface Test9 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test10
+@interface Test10 @end
+#endif
+
+#if defined(SOMETHING_DEFINED)
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test11
+@interface Test11 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test12 @end
+#endif
+
+#if SOMETHING_NOT_DEFINED1
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test13
+@interface Test13 @end
+#elif SOMETHING_NOT_DEFINED2
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test14
+@interface Test14 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test15
+@interface Test15 @end
+#endif
+
+#ifdef SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test19
+@interface Test19 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test20
+@interface Test20 @end
+#endif
+
+#ifdef SOMETHING_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test21
+@interface Test21 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test22 @end
+#endif
+
+#ifndef SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test23
+@interface Test23 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfac

r305797 - [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros

2017-06-20 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Tue Jun 20 09:36:58 2017
New Revision: 305797

URL: http://llvm.org/viewvc/llvm-project?rev=305797&view=rev
Log:
[preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse 
all directive blocks if the condition uses undefined macros

This is useful for being able to parse the preprocessor directive blocks even 
if the header, that defined the macro that is checked, hasn't been included.

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

Added:
cfe/trunk/test/Index/single-file-parse.m
Removed:
cfe/trunk/test/Index/singe-file-parse.m
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Lex/PreprocessorOptions.h
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPExpressions.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=305797&r1=305796&r2=305797&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Jun 20 09:36:58 2017
@@ -1835,11 +1835,20 @@ private:
   /// \brief A fast PTH version of SkipExcludedConditionalBlock.
   void PTHSkipExcludedConditionalBlock();
 
+  /// Information about the result for evaluating an expression for a
+  /// preprocessor directive.
+  struct DirectiveEvalResult {
+/// Whether the expression was evaluated as true or not.
+bool Conditional;
+/// True if the expression contained identifiers that were undefined.
+bool IncludedUndefinedIds;
+  };
+
   /// \brief Evaluate an integer constant expression that may occur after a
-  /// \#if or \#elif directive and return it as a bool.
+  /// \#if or \#elif directive and return a \p DirectiveEvalResult object.
   ///
   /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
-  bool EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro);
+  DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo 
*&IfNDefMacro);
 
   /// \brief Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/system_header/dependency and \#pragma once.

Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=305797&r1=305796&r2=305797&view=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Tue Jun 20 09:36:58 2017
@@ -96,6 +96,10 @@ public:
   std::string TokenCache;
 
   /// When enabled, preprocessor is in a mode for parsing a single file only.
+  ///
+  /// Disables #includes of other files and if there are unresolved identifiers
+  /// in preprocessor directive conditions it causes all blocks to be parsed so
+  /// that the client can get the maximum amount of information from the 
parser.
   bool SingleFileParseMode = false;
 
   /// When enabled, the preprocessor will construct editor placeholder tokens.

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=305797&r1=305796&r2=305797&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Jun 20 09:36:58 2017
@@ -538,7 +538,7 @@ void Preprocessor::SkipExcludedCondition
   assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");
   CurPPLexer->LexingRawMode = false;
   IdentifierInfo *IfNDefMacro = nullptr;
-  const bool CondValue = EvaluateDirectiveExpression(IfNDefMacro);
+  const bool CondValue = 
EvaluateDirectiveExpression(IfNDefMacro).Conditional;
   CurPPLexer->LexingRawMode = true;
   if (Callbacks) {
 const SourceLocation CondEnd = CurPPLexer->getSourceLocation();
@@ -635,7 +635,7 @@ void Preprocessor::PTHSkipExcludedCondit
 // Evaluate the condition of the #elif.
 IdentifierInfo *IfNDefMacro = nullptr;
 CurPTHLexer->ParsingPreprocessorDirective = true;
-bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro);
+bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro).Conditional;
 CurPTHLexer->ParsingPreprocessorDirective = false;
 
 // If this condition is true, enter it!
@@ -2654,7 +2654,13 @@ void Preprocessor::HandleIfdefDirective(
   }
 
   // Should we include the stuff contained by this directive?
-  if (!MI == isIfndef) {
+  if (PPOpts->SingleFileParseMode && !MI) {
+// In 'single-file-parse mode' undefined identifiers trigger parsing of all
+// the directive blocks.
+CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
+ /*wasskip*/true, /*foundnonskip*/false,
+ 

[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:124
+/// CanReusePreamble + AddImplicitPreamble to make use of it.
+class PrecompiledPreamble {
+public:

ilya-biryukov wrote:
> klimek wrote:
> > If a user doesn't care about the things above this class, can we move those 
> > into an extra header?
> Do you have any suggestions of where to put it and how to call it?
> I didn't think it's a good idea to put something like 'PreambleFileHash.h' 
> and 'TempPCHFile.h' into 'include/clang/Frontend/'. (Given that they are 
> essential an implementation detail of PrecompiledPreamble, exposing them in 
> public include folders seems like a bad idea).
TempPCHFile looks like something we just want to put into the .cc file and 
store as a unique_ptr.
PreambleFileHash seems fine as an extra header.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:157-160
+  /// We don't expose PCHFile to avoid changing interface when we'll add an
+  /// in-memory PCH, so we declare this function as friend so that it has 
access
+  /// to PCHFile field.
+  friend void AddImplicitPreamble(CompilerInvocation &CI,

ilya-biryukov wrote:
> klimek wrote:
> > Why not make it a member instead?
> To keep BuildPreamble, CanReusePreamble and AddImplicitPreamble close to each 
> other.
> I.e. PrecompiledPreamble only stores data used by these functions.
> 
> We could make all of those members, of course. Do you think that would make 
> API better?
Generally, if these are closely coupled to implementation details of 
PrecompiledPreample, I think that coupling is strong enough to warrant making 
them members.
On the other hand, making some functions members, and others non-members, and 
putting them next to each other in the .cc file also would work.


https://reviews.llvm.org/D34287



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


r305798 - [OpenCL] Diagnose scoped address-space qualified variables

2017-06-20 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Jun 20 09:50:45 2017
New Revision: 305798

URL: http://llvm.org/viewvc/llvm-project?rev=305798&view=rev
Log:
[OpenCL] Diagnose scoped address-space qualified variables

Produce an error if variables qualified with a local or
a constant address space are not declared in the outermost
scope of a kernel.

Patch by Simon Perretta.

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/storageclass.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=305798&r1=305797&r2=305798&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 20 09:50:45 
2017
@@ -8311,6 +8311,9 @@ def err_opencl_ext_vector_component_inva
   "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in 
%1 address space">;
+def err_opencl_addrspace_scope : Error<
+  "variables in the %0 address space can only be declared in the outermost "
+  "scope of a kernel function">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=305798&r1=305797&r2=305798&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jun 20 09:50:45 2017
@@ -7260,11 +7260,11 @@ void Sema::CheckVariableDeclarationType(
 NewVD->setInvalidDecl();
 return;
   }
-  // OpenCL v1.1 s6.5.2 and s6.5.3 no local or constant variables
-  // in functions.
   if (T.getAddressSpace() == LangAS::opencl_constant ||
   T.getAddressSpace() == LangAS::opencl_local) {
 FunctionDecl *FD = getCurFunctionDecl();
+// OpenCL v1.1 s6.5.2 and s6.5.3: no local or constant variables
+// in functions.
 if (FD && !FD->hasAttr()) {
   if (T.getAddressSpace() == LangAS::opencl_constant)
 Diag(NewVD->getLocation(), diag::err_opencl_function_variable)
@@ -7275,6 +7275,20 @@ void Sema::CheckVariableDeclarationType(
   NewVD->setInvalidDecl();
   return;
 }
+// OpenCL v2.0 s6.5.2 and s6.5.3: local and constant variables must be
+// in the outermost scope of a kernel function.
+if (FD && FD->hasAttr()) {
+  if (!getCurScope()->isFunctionScope()) {
+if (T.getAddressSpace() == LangAS::opencl_constant)
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "constant";
+else
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "local";
+NewVD->setInvalidDecl();
+return;
+  }
+}
   } else if (T.getAddressSpace() != LangAS::Default) {
 // Do not allow other address spaces on automatic variable.
 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1;

Modified: cfe/trunk/test/SemaOpenCL/storageclass.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/storageclass.cl?rev=305798&r1=305797&r2=305798&view=diff
==
--- cfe/trunk/test/SemaOpenCL/storageclass.cl (original)
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl Tue Jun 20 09:50:45 2017
@@ -13,6 +13,11 @@ void kernel foo(int x) {
   constant int L1 = 0;
   local int L2;
 
+  if (true) {
+local int L1; // expected-error {{variables in the local address space can 
only be declared in the outermost scope of a kernel function}}
+constant int L1 = 42; // expected-error {{variables in the constant 
address space can only be declared in the outermost scope of a kernel function}}
+  }
+
   auto int L3 = 7;// expected-error{{OpenCL 
version 1.2 does not support the 'auto' storage class specifier}}
   global int L4;  // expected-error{{function 
scope variable cannot be declared in global address space}}
   __attribute__((address_space(100))) int L5; // expected-error{{automatic 
variable qualified with an invalid address space}}


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


[PATCH] D34024: [OpenCL] Diagnose scoped address-space qualified variables

2017-06-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305798: [OpenCL] Diagnose scoped address-space qualified 
variables (authored by stulova).

Changed prior to commit:
  https://reviews.llvm.org/D34024?vs=101872&id=103207#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34024

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/SemaOpenCL/storageclass.cl


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8311,6 +8311,9 @@
   "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in 
%1 address space">;
+def err_opencl_addrspace_scope : Error<
+  "variables in the %0 address space can only be declared in the outermost "
+  "scope of a kernel function">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<
Index: cfe/trunk/test/SemaOpenCL/storageclass.cl
===
--- cfe/trunk/test/SemaOpenCL/storageclass.cl
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl
@@ -13,6 +13,11 @@
   constant int L1 = 0;
   local int L2;
 
+  if (true) {
+local int L1; // expected-error {{variables in the local address space can 
only be declared in the outermost scope of a kernel function}}
+constant int L1 = 42; // expected-error {{variables in the constant 
address space can only be declared in the outermost scope of a kernel function}}
+  }
+
   auto int L3 = 7;// expected-error{{OpenCL 
version 1.2 does not support the 'auto' storage class specifier}}
   global int L4;  // expected-error{{function 
scope variable cannot be declared in global address space}}
   __attribute__((address_space(100))) int L5; // expected-error{{automatic 
variable qualified with an invalid address space}}
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -7260,11 +7260,11 @@
 NewVD->setInvalidDecl();
 return;
   }
-  // OpenCL v1.1 s6.5.2 and s6.5.3 no local or constant variables
-  // in functions.
   if (T.getAddressSpace() == LangAS::opencl_constant ||
   T.getAddressSpace() == LangAS::opencl_local) {
 FunctionDecl *FD = getCurFunctionDecl();
+// OpenCL v1.1 s6.5.2 and s6.5.3: no local or constant variables
+// in functions.
 if (FD && !FD->hasAttr()) {
   if (T.getAddressSpace() == LangAS::opencl_constant)
 Diag(NewVD->getLocation(), diag::err_opencl_function_variable)
@@ -7275,6 +7275,20 @@
   NewVD->setInvalidDecl();
   return;
 }
+// OpenCL v2.0 s6.5.2 and s6.5.3: local and constant variables must be
+// in the outermost scope of a kernel function.
+if (FD && FD->hasAttr()) {
+  if (!getCurScope()->isFunctionScope()) {
+if (T.getAddressSpace() == LangAS::opencl_constant)
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "constant";
+else
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "local";
+NewVD->setInvalidDecl();
+return;
+  }
+}
   } else if (T.getAddressSpace() != LangAS::Default) {
 // Do not allow other address spaces on automatic variable.
 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1;


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8311,6 +8311,9 @@
   "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in %1 address space">;
+def err_opencl_addrspace_scope : Error<
+  "variables in the %0 address space can only be declared in the outermost "
+  "scope of a kernel function">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<
Index: cfe/trunk/test/SemaOpenCL/storageclass.cl
===
--- cfe/trunk/test/SemaOpenCL/storageclass.cl
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl
@@ -13,6 +13,11 @@
   constant int L1 = 0;
   local int L2;
 
+  if

r305799 - D31187: Fix removal of out-of-line definitions.

2017-06-20 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Tue Jun 20 09:59:57 2017
New Revision: 305799

URL: http://llvm.org/viewvc/llvm-project?rev=305799&view=rev
Log:
D31187: Fix removal of out-of-line definitions.

Consider:

struct MyClass {
  void f() {}
}
MyClass::f(){} // expected error redefinition of f. #1

Some clients (eg. cling) need to call removeDecl for the redefined (#1) decl.

This patch enables us to remove the lookup entry is registered in the semantic
decl context and not in the primary decl context of the lexical decl context
where we currently are trying to remove it from.

It is not trivial to test this piece and writing a full-blown unit test seems
too much.

Modified:
cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=305799&r1=305798&r2=305799&view=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Jun 20 09:59:57 2017
@@ -1352,7 +1352,7 @@ void DeclContext::removeDecl(Decl *D) {
 // Remove only decls that have a name
 if (!ND->getDeclName()) return;
 
-auto *DC = this;
+auto *DC = D->getDeclContext();
 do {
   StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
   if (Map) {


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


[PATCH] D31187: Fix removal of out-of-line definitions.

2017-06-20 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev closed this revision.
v.g.vassilev added a comment.

Landed in r305799. I would like to test it and I think that should be possible 
as soon as I land some interpreter infrastructure which is on my TODO list.


https://reviews.llvm.org/D31187



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 103208.
johannes marked 7 inline comments as done.

https://reviews.llvm.org/D34329

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/ASTDiff/CMakeLists.txt
  lib/Tooling/CMakeLists.txt
  test/Tooling/clang-diff-basic.cpp
  tools/CMakeLists.txt
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- /dev/null
+++ tools/clang-diff/ClangDiff.cpp
@@ -0,0 +1,110 @@
+//===- ClangDiff.cpp - compare source files by AST nodes --*- C++ -*- -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements a tool for syntax tree based comparison using
+// Tooling/ASTDiff.
+//
+//===--===//
+
+#include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace tooling;
+
+static cl::OptionCategory ClangDiffCategory("clang-diff options");
+
+static cl::opt
+DumpAST("ast-dump",
+cl::desc("Print the internal representation of the AST as JSON."),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settigns from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt SourcePath(cl::Positional, cl::desc(""),
+   cl::Required,
+   cl::cat(ClangDiffCategory));
+
+static cl::opt DestinationPath(cl::Positional,
+cl::desc(""),
+cl::Optional,
+cl::cat(ClangDiffCategory));
+
+static std::unique_ptr getAST(const StringRef Filename) {
+  std::string ErrorMessage;
+  std::unique_ptr Compilations;
+  if (!NoCompilationDatabase)
+Compilations =
+CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+  if (!Compilations) {
+if (!NoCompilationDatabase)
+  llvm::errs()
+  << "Error while trying to load a compilation database, running "
+ "without flags.\n"
+  << ErrorMessage;
+Compilations.reset(
+new FixedCompilationDatabase(".", std::vector()));
+  }
+  std::array Files = {{Filename}};
+  ClangTool Tool(*Compilations, Files);
+  std::vector> ASTs;
+  Tool.buildASTs(ASTs);
+  if (ASTs.size() != Files.size())
+return nullptr;
+  return std::move(ASTs[0]);
+}
+
+int main(int argc, const char **argv) {
+  cl::HideUnrelatedOptions(ClangDiffCategory);
+  if (!cl::ParseCommandLineOptions(argc, argv)) {
+cl::PrintOptionValues();
+return 1;
+  }
+
+  if (DumpAST) {
+if (!DestinationPath.empty()) {
+  llvm::errs() << "Error: Please specify exactly one filename.\n";
+  return 1;
+}
+std::unique_ptr AST = getAST(SourcePath);
+if (!AST)
+  return 1;
+clang::diff::TreeRoot Tree(AST->getASTContext());
+Tree.printAsJson();
+return 0;
+  }
+
+  if (DestinationPath.empty()) {
+llvm::errs() << "Error: Exactly two paths are required.\n";
+return 1;
+  }
+
+  std::unique_ptr Src = getAST(SourcePath);
+  std::unique_ptr Dst = getAST(DestinationPath);
+  if (!Src || !Dst)
+return 1;
+
+  diff::TreeRoot T1(Src->getASTContext());
+  diff::TreeRoot T2(Dst->getASTContext());
+  diff::ASTDiff DiffTool(T1, T2);
+  diff::Mapping M = DiffTool.computeMapping();
+  M.printMapping();
+  auto Changes = DiffTool.computeChanges(M);
+  for (const auto &C : Changes)
+DiffTool.printChange(C);
+
+  return 0;
+}
Index: tools/clang-diff/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-diff/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_executable(clang-diff
+  ClangDiff.cpp
+  )
+
+target_link_libraries(clang-diff
+  clangFrontend
+  clangTooling
+  clangToolingASTDiff
+  )
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
 add_clang_subdirectory(clang-format-vs)
 add_clang_subdirectory(clang-fuzzer)
Index: test/Tooling/clang-diff-basic.cpp
===
--- /dev/null
+++ test/Tooli

[PATCH] D34342: [OpenCL] Fix code generation of function-scope constant samplers.

2017-06-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: test/CodeGenOpenCL/sampler.cl:62
+
+  const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
+  // CHECK: [[CONST_SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)

bader wrote:
> yaxunl wrote:
> > what if address of const_smp is taken and assigned to a pointer to 
> > sampler_t ? Do we have diagnosis in place?
> AFAIK, we have diagnostics for both:
> - declaration of a pointer to sampler
> - taking address of sampler variable
Btw, strangely I don't hit any unreachable and don't seem to have any static 
variable generated either. I was trying to compile this code on r305798:

  void fnc4smp(sampler_t s) {}
  kernel void foo(sampler_t smp_par) {
const sampler_t const_smp = 0;
fnc4smp(const_smp);
  }

This is the IR which is produced for me:

  %opencl.sampler_t = type opaque

  ; Function Attrs: noinline nounwind optnone
  define spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %s) #0 {
  entry:
%s.addr = alloca %opencl.sampler_t addrspace(2)*, align 4
store %opencl.sampler_t addrspace(2)* %s, %opencl.sampler_t addrspace(2)** 
%s.addr, align 4
ret void
  }

  ; Function Attrs: noinline nounwind optnone
  define spir_kernel void @foo(%opencl.sampler_t addrspace(2)* %smp_par) #0 
!kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 
!kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
  entry:
%smp_par.addr = alloca %opencl.sampler_t addrspace(2)*, align 4
%const_smp = alloca %opencl.sampler_t addrspace(2)*, align 4
store %opencl.sampler_t addrspace(2)* %smp_par, %opencl.sampler_t 
addrspace(2)** %smp_par.addr, align 4
%0 = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 0)
store %opencl.sampler_t addrspace(2)* %0, %opencl.sampler_t addrspace(2)** 
%const_smp, align 4
%1 = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** 
%const_smp, align 4
call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %1)
ret void
  }

  declare %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32)


https://reviews.llvm.org/D34342



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


[PATCH] D34279: Fix release_40 build with MSVC (VS 2015)

2017-06-20 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

I still don't understand why this is breaking your build.

Assuming this is the line the first error refers to:

  for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR, G_SHL}) {

I don't see how converting G_ADD, even if it is an int, to unsigned would be a 
narrowing conversion.

I did a fresh checkout of LLVM and built with VS 19.00.2415.1 for x64:

  > svn export http://llvm.org/svn/llvm-project/llvm/trunk llvmtest
  > mkdir llvmtest\build
  > cd llvmtest\build
  > cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
  -- The C compiler identification is MSVC 19.0.24215.1
  -- The CXX compiler identification is MSVC 19.0.24215.1
  -- The ASM compiler identification is MSVC
  ...
  > ninja
  ...

And everything built fine.

There must be something different with your configuration.


https://reviews.llvm.org/D34279



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes marked an inline comment as done.
johannes added a comment.

In https://reviews.llvm.org/D34329#785190, @arphaman wrote:

> Looking at the output of the tool, I have the following suggestion:
>
> - We should avoid implicit expressions (We don't need to see things like 
> `Insert ImplicitCastExpr(21) into BinaryOperator: *(22) at 0`). This can be 
> done in a follow-up patch though.


Ok, I will include that and other features in future patches.




Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:474
+for (SNodeId D1 = LMD1 + 1; D1 <= Id1; ++D1) {
+  double DeletionCost = 1.0;
+  ForestDist[D1][LMD2] = ForestDist[D1 - 1][LMD2] + DeletionCost;

arphaman wrote:
> Are the `DeletionCost` and `InsertionCost` constants or are you planning to 
> modify them in the future?
I think they could be modified for minor improvements of the matching, but I am 
probably not going to do so anytime soon. Maybe it is better to store them at 
class scope as static const / constexpr?



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:693
+  H2 = L2.pop();
+  for (NodeId Id1 : H1)
+for (NodeId Id2 : H2)

arphaman wrote:
> Please wrap these loops in braces.
Not sure if I got this right.



Comment at: test/Tooling/clang-diff-basic.cpp:3
+// RUN: awk '/^.. dst/{f=1;next}/^.. end dst/{f=0}f' %s > %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck 
%s

arphaman wrote:
> I'd prefer it if we used something like `clang -E` and preprocessor to 
> generate the two files.
> 
> E.g.:
> 
> ```
> RUN: %clang_cc1 -E %s > %T/src.cpp
> RUN: %clang_cc1 -E %s -D DEST > %T/dst.cpp
> #ifndef DEST
> namespace src { };
> #else
> namespace dst { };
> #endif
> ```
Yes, much better!



Comment at: test/Tooling/clang-diff-basic.cpp:4
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck 
%s
+

arphaman wrote:
> Why do you need two invocations of `clang-diff` with the same arguments?
That was unintentional, I removed it.


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:474
+for (SNodeId D1 = LMD1 + 1; D1 <= Id1; ++D1) {
+  double DeletionCost = 1.0;
+  ForestDist[D1][LMD2] = ForestDist[D1 - 1][LMD2] + DeletionCost;

johannes wrote:
> arphaman wrote:
> > Are the `DeletionCost` and `InsertionCost` constants or are you planning to 
> > modify them in the future?
> I think they could be modified for minor improvements of the matching, but I 
> am probably not going to do so anytime soon. Maybe it is better to store them 
> at class scope as static const / constexpr?
Yeah, I suppose for now they should be declared as constants (the static const 
/ constexpr doesn't matter). They should probably be documented as well.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:693
+  H2 = L2.pop();
+  for (NodeId Id1 : H1)
+for (NodeId Id2 : H2)

johannes wrote:
> arphaman wrote:
> > Please wrap these loops in braces.
> Not sure if I got this right.
It looks better, thanks. Generally we prefer to use braces for `if`/`for`/etc. 
if they have more than one statement.


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:303
+/// Identifies a node in this subtree by its postorder offset.
+using SNodeId = int;
+

What's the difference between `SNodeId` and `NodeId`?


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:171
+
+std::string TreeRoot::label(NodeId Id) const {
+  const Node &N = getNode(Id);

I believe that this method that you call `label` actually represents the 
`value` attribute that's described in the paper for the gumtree algorithm. Is 
that right? If so, then this method name should be updated to reflect that.


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:303
+/// Identifies a node in this subtree by its postorder offset.
+using SNodeId = int;
+

arphaman wrote:
> What's the difference between `SNodeId` and `NodeId`?
NodeId is the preorder offset inside the root tree, starting at 0.
SNodeId is the postorder offset within a subtree, starting at 1.
Not sure if this irregularity can be improved upon easily, but I guess I can 
mention it in the comments. 


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:303
+/// Identifies a node in this subtree by its postorder offset.
+using SNodeId = int;
+

johannes wrote:
> arphaman wrote:
> > What's the difference between `SNodeId` and `NodeId`?
> NodeId is the preorder offset inside the root tree, starting at 0.
> SNodeId is the postorder offset within a subtree, starting at 1.
> Not sure if this irregularity can be improved upon easily, but I guess I can 
> mention it in the comments. 
Ok. It's fine to have two different types for them, but to avoid confusions I 
think that the code should be constructed in such a way that prohibits passing 
in `NodeId` to a function that expects `SNodeId` and vice-versa. You can wrap 
SNodeId in a typedef with an explicit constructor to achieve that goal, e.g.:

```
struct SNodeId {
  int Id;

  explicit SNodeId(int Id) : Id(Id) { };
}; 
```


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:171
+
+std::string TreeRoot::label(NodeId Id) const {
+  const Node &N = getNode(Id);

arphaman wrote:
> I believe that this method that you call `label` actually represents the 
> `value` attribute that's described in the paper for the gumtree algorithm. Is 
> that right? If so, then this method name should be updated to reflect that.
Yes, good catch. Strangely, the gumtree implementation uses `label`. I think we 
should use `type` for node kinds and `value` for their actual value, in order 
to avoid confusion about what a label is.


https://reviews.llvm.org/D34329



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


Re: r305719 - [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods

2017-06-20 Thread Duncan P. N. Exon Smith via cfe-commits

> On Jun 19, 2017, at 10:53, Alex Lorenz via cfe-commits 
>  wrote:
> 
> Author: arphaman
> Date: Mon Jun 19 12:53:21 2017
> New Revision: 305719
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=305719&view=rev
> Log:
> [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods
> 
> This change avoid a crash that occurred when skipping to EOF while parsing an
> ObjC interface/implementation.
> 
> rdar://31963299
> 
> Differential Revision: https://reviews.llvm.org/D34185
> 
> Added:
>cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
>cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> Modified:
>cfe/trunk/lib/Parse/ParseObjc.cpp
> 
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=305719&r1=305718&r2=305719&view=diff
> ==
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jun 19 12:53:21 2017
> @@ -3627,6 +3627,14 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   SourceLocation OrigLoc = Tok.getLocation();
> 
>   assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
> +  // Store an artificial EOF token to ensure that we don't run off the end of
> +  // the method's body when we come to parse it.
> +  Token Eof;
> +  Eof.startToken();
> +  Eof.setKind(tok::eof);
> +  Eof.setEofData(MCDecl);
> +  Eof.setLocation(OrigLoc);
> +  LM.Toks.push_back(Eof);
>   // Append the current token at the end of the new token stream so that it
>   // doesn't get lost.
>   LM.Toks.push_back(Tok);
> @@ -3658,7 +3666,7 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   Actions.ActOnDefaultCtorInitializers(MCDecl);
> ParseFunctionStatementBody(MCDecl, BodyScope);
>   }
> -  
> +
>   if (Tok.getLocation() != OrigLoc) {
> // Due to parsing error, we either went over the cached tokens or
> // there are still cached tokens left. If it's the latter case skip the
> @@ -3670,4 +3678,6 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
> ConsumeAnyToken();
>   }
> +  // Clean up the remaining EOF token.
> +  ConsumeAnyToken();
> }
> 
> Added: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305719&view=auto
> ==
> --- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Mon Jun 19 
> 12:53:21 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@implementation ClassC // expected-error {{missing '@end'}} // 
> expected-error {{expected '}'}} // expected-warning {{cannot find interface 
> declaration for 'ClassC'}}

I believe you can split these expectations over multiple lines.  Something like 
this seems more readable:

@implementation ClassC \
  // expected-error {{missing '@end'}} \
  // expected-error {{expected '}'}}   \
  // expected-warning {{cannot find interface declaration for 'ClassC'}}

> +
> +@end
> 
> Added: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305719&view=auto
> ==
> --- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Mon Jun 19 12:53:21 
> 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@interface ClassC // expected-error {{missing '@end'}} // expected-error 
> {{expected '}'}}

Same recommendation as above.

> +
> +@end
> 
> 
> ___
> 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] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb marked 5 inline comments as done.
wangxindsb added inline comments.



Comment at: VirtualCallChecker.cpp:260
+  if (SFC->inTopFrame()) {
+  const FunctionDecl *FD = SFC->getDecl()->getAsFunction();
+if (!FD)

xazax.hun wrote:
> The formatting seems to be off here I recommend using clang format.
Sorry, can you explain what this means?


https://reviews.llvm.org/D34275



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


[PATCH] D34342: [OpenCL] Fix code generation of function-scope constant samplers.

2017-06-20 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

Wow...
Nice catch.
For some reason I can't reproduce the problem neither.
I will drop source code change, but I'd like to modify the test anyway.
https://reviews.llvm.org/rL277024 added test/CodeGenOpenCL/sampler.cl and 
modified test/SemaOpenCL/sampler_t.cl.
I want to move the parts of the test/SemaOpenCL/sampler_t.cl, which are 
supposed to pass semantic analysis to test/CodeGenOpenCL/sampler.cl and 
validate the LLVM IR after code generation.
Are you OK with this?


https://reviews.llvm.org/D34342



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


[PATCH] D34198: Fix __has_trivial_destructor crash when the type is incomplete with unknown array bounds.

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:4128
+return true;
+}
+

I don't understand the difference you're creating between traits here.  Three 
specific traits about destructibility allow incomplete array types regardless 
of whether the base type is incomplete, but the rest do not?

Anyway, I think what you want here is basically just:

  if (auto ArrayTy = S.Context.getAsIncompleteArrayType(ArgTy)) {
ArgTy = ArrayTy->getElementType();
  }


https://reviews.llvm.org/D34198



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


RE: r284060 - Implement MS _BitScan intrinsics

2017-06-20 Thread Erik Schwiebert via cfe-commits
LGTM, assuming "howLong" == 0 means 32-bit int. 😊

-Original Message-
From: Bruno Cardoso Lopes [mailto:bruno.card...@gmail.com] 
Sent: Monday, June 19, 2017 6:45 PM
To: Duncan P. N. Exon Smith 
Cc: Reid Kleckner ; Erik Schwiebert ; 
Brian Kelley ; Tomasz Kukielka ; 
cfe-commits 
Subject: Re: r284060 - Implement MS _BitScan intrinsics

On Fri, Jun 16, 2017 at 5:08 PM, Duncan P. N. Exon Smith
 wrote:
>
> On Jun 16, 2017, at 11:02, Reid Kleckner  wrote:
>
> We should fix it.
>
>
> Agreed.
>
> We just need a new character code in the builtin function prototype
> encoding. Currently there is no encoding for a portable int32_t that
> magically becomes "long" on 32-bit Windows. The closest thing we have is
> 'W', which is used by Neon intrinsics to select between "long" and "long
> long". It was added in r202004.
>
>
> Yup, I saw the 'W' as well.  That's the same approach I was using in a patch
> yesterday morning (I picked lowercase L ('l'), but there may be a better
> choice).  Likely Bruno will follow up with a working patch soon (I hit some
> problems with tests and then got tied up).

Right, here it is: 
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.llvm.org%2FD34377&data=02%7C01%7Ceriksc%40microsoft.com%7C622ea4cd65f846cd1be708d4b77dfaa1%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636335199097092827&sdata=abfnUWviZ01v%2B%2B43Q6vLvZoBk2QbawkzKNpayIgMJwY%3D&reserved=0

Let me know what you guys think!

>
> On Fri, Jun 16, 2017 at 10:28 AM, Erik Schwiebert 
> wrote:
>>
>> We (Office developers for Apple platforms at Microsoft) would prefer to
>> have the intrinsics work properly for LP64, as that will generate the most
>> optimal and efficient code. That said, we understand that this may be odd to
>> implement from the compiler's perspective and can work around it if the
>> intrinsics are not supported for ms-extensions+LP64. At the end of the day
>> we need the compiler to clearly adopt one of those two options, and not sit
>> somewhere in the middle as it currently does. We don't turn on any flags
>> other than -fms-extensions; we don’t attempt to define MSC_VER and we do
>> conditionalize code based on __clang__ so the code is aware it is being
>> compiled by clang vs MSVC.
>>
>> So I think we'd prefer what Duncan and Apple are offering to do, but if
>> the larger clang community thinks that is a bad idea and wants to explicitly
>> disable the intrinsics, we could live with that.
>>
>> Thanks,
>> Schwieb
>>
>> -Original Message-
>> From: Erik Schwiebert
>> Sent: Friday, June 16, 2017 8:49 AM
>> To: 'Bruno Cardoso Lopes' ; Brian Kelley
>> ; Tomasz Kukielka 
>> Cc: dexonsm...@apple.com; Reid Kleckner ; cfe-commits
>> 
>> Subject: RE: r284060 - Implement MS _BitScan intrinsics
>>
>> Adding Brian and Tomasz. I'm pretty sure we have the Windows SDK
>> intrinsics headers. I'm not sure which method we'd prefer, so I'll walk down
>> the hall and ask them. Tomasz is our header maestro (because we play crazy
>> #include_next games so we can use both Windows and macOS SDKs!)
>>
>> We'll get back to you ASAP.
>>
>> Schwieb
>>
>> -Original Message-
>> From: Bruno Cardoso Lopes [mailto:bruno.card...@gmail.com]
>> Sent: Thursday, June 15, 2017 4:41 PM
>> To: Erik Schwiebert 
>> Cc: dexonsm...@apple.com; Reid Kleckner ; cfe-commits
>> 
>> Subject: Re: r284060 - Implement MS _BitScan intrinsics
>>
>> On Tue, Jun 13, 2017 at 8:13 PM, Bruno Cardoso Lopes
>>  wrote:
>> > On Mon, Jun 12, 2017 at 2:01 PM, Erik Schwiebert via cfe-commits
>> >  wrote:
>> >> SGTM too. Regarding Duncan's last question -- I can't think of any such
>> >> customer. :) If you all think the right thing for clang to do is to infer
>> >> LLP64 behavior on LP64 (Darwin) + ms_extensions, then that is fine with 
>> >> me!
>>
>> Thinking more about this; what if we mark such builtins as unsupported
>> for "LP64 (Darwin) + ms_extensions" and then you provide the
>> definitions via intrin.h (we can generate a compiler macro for this
>> scenario and conditionalize the include_next as we do for _MSC_VER)?
>> Do you use this header at all? Are there any other MS related flags
>> that get passed to the compiler?
>>
>> > SGTM as well!
>> >
>> >>
>> >> Thanks all!
>> >> Schwieb
>> >>
>> >> -Original Message-
>> >> From: dexonsm...@apple.com [mailto:dexonsm...@apple.com]
>> >> Sent: Monday, June 12, 2017 1:55 PM
>> >> To: Reid Kleckner 
>> >> Cc: Saleem Abdulrasool ; Albert Gutowski
>> >> ; David Majnemer ;
>> >> cfe-commits ; Erik Schwiebert
>> >> 
>> >> Subject: Re: r284060 - Implement MS _BitScan intrinsics
>> >>
>> >>
>> >>> On Jun 12, 2017, at 12:44, Reid Kleckner  wrote:
>> >>>
>>  On Wed, Jun 7, 2017 at 7:31 PM, Saleem Abdulrasool
>>   wrote:
>>  I'm worried about changing this signature all the time.  I suspect
>>  that it will cause the following to be emitted for valid code:
>> 
>>  warning: incompatible pointer types passing 'unsigned long *' to
>>  parameter of type 'un

[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 103216.
ilya-biryukov added a comment.

- Made TempPCHFile an inner class of PrecompiledPreamble.
- Made PreambleFileHash an inner class of PrecompiledPreamble.
- Changed stanalone functions to members.
- Removed some member accessors that were no longer used.


https://reviews.llvm.org/D34287

Files:
  include/clang/Frontend/ASTUnit.h
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/CMakeLists.txt
  lib/Frontend/PrecompiledPreamble.cpp

Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- /dev/null
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -0,0 +1,561 @@
+//===--- PrecompiledPreamble.cpp - Build precompiled preambles --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Helper class to build precompiled preamble.
+//
+//===--===//
+
+#include "clang/Frontend/PrecompiledPreamble.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Serialization/ASTWriter.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/CrashRecoveryContext.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
+#include "llvm/Support/MutexGuard.h"
+
+using namespace clang;
+
+namespace {
+
+/// Keeps a track of files to be deleted in destructor.
+class TemporaryFiles {
+public:
+  // A static instance to be used by
+  static TemporaryFiles &getInstance();
+
+private:
+  // Disallow constructing the class directly.
+  TemporaryFiles() = default;
+  // Disallow copy.
+  TemporaryFiles(const TemporaryFiles &) = delete;
+
+public:
+  ~TemporaryFiles();
+
+  /// Adds \p File to a set of tracked files.
+  void addFile(StringRef File);
+
+  /// Remove \p File from disk and from the set of tracked files.
+  void removeFile(StringRef File);
+
+private:
+  llvm::sys::SmartMutex Mutex;
+  llvm::StringSet<> Files;
+};
+
+TemporaryFiles &TemporaryFiles::getInstance() {
+  static TemporaryFiles Instance;
+  return Instance;
+}
+
+TemporaryFiles::~TemporaryFiles() {
+  llvm::MutexGuard Guard(Mutex);
+  for (const auto &File : Files)
+llvm::sys::fs::remove(File.getKey());
+}
+
+void TemporaryFiles::addFile(StringRef File) {
+  llvm::MutexGuard Guard(Mutex);
+  auto IsInserted = Files.insert(File).second;
+  assert(IsInserted && "File has already been added");
+}
+
+void TemporaryFiles::removeFile(StringRef File) {
+  llvm::MutexGuard Guard(Mutex);
+  auto WasPresent = Files.erase(File);
+  assert(WasPresent && "File was not tracked");
+  llvm::sys::fs::remove(File);
+}
+
+class PreambleMacroCallbacks : public PPCallbacks {
+public:
+  PreambleMacroCallbacks(PreambleCallbacks &Callbacks) : Callbacks(Callbacks) {}
+
+  void MacroDefined(const Token &MacroNameTok,
+const MacroDirective *MD) override {
+Callbacks.HandleMacroDefined(MacroNameTok, MD);
+  }
+
+private:
+  PreambleCallbacks &Callbacks;
+};
+
+class PrecompilePreambleAction : public ASTFrontendAction {
+public:
+  PrecompilePreambleAction(PreambleCallbacks &Callbacks)
+  : Callbacks(Callbacks) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override;
+
+  bool hasEmittedPreamblePCH() const { return HasEmittedPreamblePCH; }
+
+  void setEmittedPreamblePCH(ASTWriter &Writer) {
+this->HasEmittedPreamblePCH = true;
+Callbacks.AfterPCHEmitted(Writer);
+  }
+
+  bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); }
+  bool hasCodeCompletionSupport() const override { return false; }
+  bool hasASTFileSupport() const override { return false; }
+  TranslationUnitKind getTranslationUnitKind() override { return TU_Prefix; }
+
+private:
+  friend class PrecompilePreambleConsumer;
+
+  bool HasEmittedPreamblePCH = false;
+  PreambleCallbacks &Callbacks;
+};
+
+class PrecompilePreambleConsumer : public PCHGenerator {
+public:
+  PrecompilePreambleConsumer(PrecompilePreambleAction &Action,
+ const Preprocessor &PP, StringRef isysroot,
+ std::unique_ptr Out)
+  : PCHGenerator(PP, "", isysroot, std::make_shared(),
+ ArrayRef>(),
+ /*AllowASTWithErrors=*/true),
+Action(Action), Out(std::move(Out)) {}
+
+  bool HandleTopL

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 103214.
wangxindsb added a comment.

Correct some error in VirtualCallChecker.cpp.
Complete the test case.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,49 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
   A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo(); // from Sema: expected-note {{'foo' declared here}}
+  virtual void bar();
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
 A::A(int i) {
   foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +57,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -115,7 +79,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +88,68 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
-}
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
 
-#include "virtualcall.h"
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
 
-#define AS_SYSTEM
-#include "virtualcall.h"
-#undef AS_SYSTEM
+  H(int i) {
+G g;
+g.foo();
+g.bar();
+  // no warning
+f();
+ 

[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1605
+  ? CGM.getDataLayout().getAllocaAddrSpace()
+  : getContext().getTargetAddressSpace(LangAS::Default));
   break;

Everything about your reasoning seems to apply to normal indirect arguments, 
too.


https://reviews.llvm.org/D34367



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


[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:124
+/// CanReusePreamble + AddImplicitPreamble to make use of it.
+class PrecompiledPreamble {
+public:

klimek wrote:
> ilya-biryukov wrote:
> > klimek wrote:
> > > If a user doesn't care about the things above this class, can we move 
> > > those into an extra header?
> > Do you have any suggestions of where to put it and how to call it?
> > I didn't think it's a good idea to put something like 'PreambleFileHash.h' 
> > and 'TempPCHFile.h' into 'include/clang/Frontend/'. (Given that they are 
> > essential an implementation detail of PrecompiledPreamble, exposing them in 
> > public include folders seems like a bad idea).
> TempPCHFile looks like something we just want to put into the .cc file and 
> store as a unique_ptr.
> PreambleFileHash seems fine as an extra header.
Made both inner classes of PrecompiledPreamble instead.
The only thing we have outside PrecompiledPreamble now is PreambleBounds. But 
it doesn't look like a big distraction.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:157-160
+  /// We don't expose PCHFile to avoid changing interface when we'll add an
+  /// in-memory PCH, so we declare this function as friend so that it has 
access
+  /// to PCHFile field.
+  friend void AddImplicitPreamble(CompilerInvocation &CI,

klimek wrote:
> ilya-biryukov wrote:
> > klimek wrote:
> > > Why not make it a member instead?
> > To keep BuildPreamble, CanReusePreamble and AddImplicitPreamble close to 
> > each other.
> > I.e. PrecompiledPreamble only stores data used by these functions.
> > 
> > We could make all of those members, of course. Do you think that would make 
> > API better?
> Generally, if these are closely coupled to implementation details of 
> PrecompiledPreample, I think that coupling is strong enough to warrant making 
> them members.
> On the other hand, making some functions members, and others non-members, and 
> putting them next to each other in the .cc file also would work.
Made all three useful functions members(BuildPreamble is now a static member, 
too, called PrecompiledPreamble::Build).

Also removed some accessors that weren't used outside those functions.
And made a PrecompiledPreamble constructor private, so Build is the only 
function in the interface that creates a preamble. 


https://reviews.llvm.org/D34287



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


r305803 - Split the expectations in tests from r305719 over multiple lines to

2017-06-20 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 20 11:12:26 2017
New Revision: 305803

URL: http://llvm.org/viewvc/llvm-project?rev=305803&view=rev
Log:
Split the expectations in tests from r305719 over multiple lines to
enhance readability

As suggested by Duncan Exon Smith!

Modified:
cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
cfe/trunk/test/Parser/objc-at-interface-eof-crash.m

Modified: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305803&r1=305802&r2=305803&view=diff
==
--- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Tue Jun 20 
11:12:26 2017
@@ -16,6 +16,9 @@
   mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
-@implementation ClassC // expected-error {{missing '@end'}} // expected-error 
{{expected '}'}} // expected-warning {{cannot find interface declaration for 
'ClassC'}}
+@implementation ClassC //  \
+  // expected-error {{missing '@end'}} \
+  // expected-error {{expected '}'}}   \
+  // expected-warning {{cannot find interface declaration for 'ClassC'}}
 
 @end

Modified: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305803&r1=305802&r2=305803&view=diff
==
--- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Tue Jun 20 11:12:26 2017
@@ -16,6 +16,8 @@
   mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
-@interface ClassC // expected-error {{missing '@end'}} // expected-error 
{{expected '}'}}
+@interface ClassC //   \
+  // expected-error {{missing '@end'}} \
+  // expected-error {{expected '}'}}
 
 @end


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


Re: r305719 - [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods

2017-06-20 Thread Alex L via cfe-commits
On 20 June 2017 at 16:53, Duncan P. N. Exon Smith 
wrote:

>
> On Jun 19, 2017, at 10:53, Alex Lorenz via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: arphaman
> Date: Mon Jun 19 12:53:21 2017
> New Revision: 305719
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305719&view=rev
> Log:
> [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods
>
> This change avoid a crash that occurred when skipping to EOF while parsing
> an
> ObjC interface/implementation.
>
> rdar://31963299
>
> Differential Revision: https://reviews.llvm.org/D34185
>
> Added:
>cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
>cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> Modified:
>cfe/trunk/lib/Parse/ParseObjc.cpp
>
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/
> ParseObjc.cpp?rev=305719&r1=305718&r2=305719&view=diff
> 
> ==
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jun 19 12:53:21 2017
> @@ -3627,6 +3627,14 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   SourceLocation OrigLoc = Tok.getLocation();
>
>   assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
> +  // Store an artificial EOF token to ensure that we don't run off the
> end of
> +  // the method's body when we come to parse it.
> +  Token Eof;
> +  Eof.startToken();
> +  Eof.setKind(tok::eof);
> +  Eof.setEofData(MCDecl);
> +  Eof.setLocation(OrigLoc);
> +  LM.Toks.push_back(Eof);
>   // Append the current token at the end of the new token stream so that it
>   // doesn't get lost.
>   LM.Toks.push_back(Tok);
> @@ -3658,7 +3666,7 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   Actions.ActOnDefaultCtorInitializers(MCDecl);
> ParseFunctionStatementBody(MCDecl, BodyScope);
>   }
> -
> +
>   if (Tok.getLocation() != OrigLoc) {
> // Due to parsing error, we either went over the cached tokens or
> // there are still cached tokens left. If it's the latter case skip the
> @@ -3670,4 +3678,6 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
> ConsumeAnyToken();
>   }
> +  // Clean up the remaining EOF token.
> +  ConsumeAnyToken();
> }
>
> Added: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/
> objc-at-implementation-eof-crash.m?rev=305719&view=auto
> 
> ==
> --- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Mon Jun 19
> 12:53:21 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@implementation ClassC // expected-error {{missing '@end'}} //
> expected-error {{expected '}'}} // expected-warning {{cannot find interface
> declaration for 'ClassC'}}
>
>
> I believe you can split these expectations over multiple lines.  Something
> like this seems more readable:
>
> @implementation ClassC \
>   // expected-error {{missing '@end'}} \
>   // expected-error {{expected '}'}}   \
>   // expected-warning {{cannot find interface declaration for 'ClassC'}}
>
>
Thanks, addressed in r305803!


>
> +
> +@end
>
> Added: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/
> objc-at-interface-eof-crash.m?rev=305719&view=auto
> 
> ==
> --- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Mon Jun 19
> 12:53:21 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@interface ClassC // expected-error {{missing '@end'}} // expected-error
> {{expected '}'}}
>
>
> Same recommendation as above.
>
> +
> +@end
>
>
> ___
> 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.ll

r305804 - Add a missing '[' to the tests from r305719

2017-06-20 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 20 11:16:11 2017
New Revision: 305804

URL: http://llvm.org/viewvc/llvm-project?rev=305804&view=rev
Log:
Add a missing '[' to the tests from r305719

This clarifies the tests as the missing ']' is important, and not the '['.

Modified:
cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
cfe/trunk/test/Parser/objc-at-interface-eof-crash.m

Modified: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305804&r1=305803&r2=305804&view=diff
==
--- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Tue Jun 20 
11:16:11 2017
@@ -13,7 +13,7 @@
 @implementation ClassB // expected-note {{implementation started here}}
 
 - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
-  mgr fileExistsAtPath:0
+  [mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
 @implementation ClassC //  \

Modified: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305804&r1=305803&r2=305804&view=diff
==
--- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Tue Jun 20 11:16:11 2017
@@ -13,7 +13,7 @@
 @implementation ClassB // expected-note {{implementation started here}}
 
 - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
-  mgr fileExistsAtPath:0
+  [mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
 @interface ClassC //   \


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


[PATCH] D34277: [analyzer] Bump default performance thresholds?

2017-06-20 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

> In particular, there are patches to generate more symbolic expressions, that 
> could also degrade the performance (but fix some fixmes along the way).

The patch you are talking about might be promising, but needs much more 
investigation and tuning for performance vs issues found. I do not think we 
should block this patch until the investigation is done.


https://reviews.llvm.org/D34277



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


[PATCH] D33842: [AMDGPU] Fix address space of global variable

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Basic/TargetInfo.h:959
+  /// \brief Return the target address space which is read only and can be
+  /// casted to the generic address space.
+  virtual llvm::Optional getTargetConstantAddressSpace() const {

"Return an AST address space which can be used opportunistically for constant 
global memory.  It must be possible to convert pointers into this address space 
to LangAS::Default.  If no such address space exists, this may return None, and 
such optimizations will be disabled."



Comment at: lib/CodeGen/CGExpr.cpp:357
+unsigned AddrSpace =
+CGF.getTarget().getTargetConstantAddressSpace().getValueOr(0);
 auto *GV = new llvm::GlobalVariable(

This isn't the right logic.  Part of what I was saying before is that this 
optimization isn't obviously supportable on all targets.  You should call 
getTargetConstantAddressSpace() and then only try to do this optimization if it 
doesn't return None.

For parity, the default implementation should return 0.



Comment at: lib/CodeGen/CGExpr.cpp:449
+ Var, ConvertTypeForMem(E->getType())->getPointerTo()),
  Object.getAlignment());
 // If the temporary is a global and has a constant initializer or is a

Every time you're tempted to use getPointerCast, you should instead be using 
the target hook to lift the pointer into the right address space.


https://reviews.llvm.org/D33842



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


[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 103224.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Hi @rsmith 
Thanks for the quick response!  I spent a while going over it, and think I have 
what you were looking for.  I Also added the operator auto * tests.


https://reviews.llvm.org/D34370

Files:
  lib/Sema/SemaLookup.cpp
  test/SemaCXX/cxx1y-deduced-return-type.cpp


Index: test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 
'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 
'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from 
returned value of type 'int'}}
 }
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -862,6 +862,19 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()
+  .getCXXNameType()
+  ->getContainedDeducedType()
+  ->isUndeducedType()) {
+return Found;
+  }
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);


Index: test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from returned value of type 'int'}}
 }
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -862,6 +862,19 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()
+  .getCXXNameType()
+  ->getContainedDeducedType()
+  ->isUndeducedType()) {
+return Found;
+  }
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

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

Looks good, thanks!




Comment at: lib/Sema/SemaLookup.cpp:870
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()

Maybe only call this once?


https://reviews.llvm.org/D34370



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


r305805 - [GSoC] Flag value completion for clang

2017-06-20 Thread Yuka Takahashi via cfe-commits
Author: yamaguchi
Date: Tue Jun 20 11:31:31 2017
New Revision: 305805

URL: http://llvm.org/viewvc/llvm-project?rev=305805&view=rev
Log:
[GSoC] Flag value completion for clang

This is patch for GSoC project, bash-completion for clang.

To use this on bash, please run `source clang/utils/bash-autocomplete.sh`.
bash-autocomplete.sh is code for bash-completion.

In this patch, Options.td was mainly changed in order to add value class
in Options.inc.

Modified:
cfe/trunk/include/clang/Driver/Options.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/DriverOptions.cpp
cfe/trunk/test/Driver/autocomplete.c
cfe/trunk/utils/bash-autocomplete.sh

Modified: cfe/trunk/include/clang/Driver/Options.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.h?rev=305805&r1=305804&r2=305805&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.h (original)
+++ cfe/trunk/include/clang/Driver/Options.h Tue Jun 20 11:31:31 2017
@@ -39,8 +39,9 @@ enum ClangFlags {
 
 enum ID {
 OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\
+   HELPTEXT, METAVAR, VALUES)  
\
+  OPT_##ID,
 #include "clang/Driver/Options.inc"
 LastOption
 #undef OPTION

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=305805&r1=305804&r2=305805&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Jun 20 11:31:31 2017
@@ -493,7 +493,7 @@ def cl_mad_enable : Flag<["-"], "cl-mad-
 def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow use of less precise no signed zeros 
computations in the generated binary.">;
 def cl_std_EQ : Joined<["-"], "cl-std=">, Group, 
Flags<[CC1Option]>,
-  HelpText<"OpenCL language standard to compile for.">;
+  HelpText<"OpenCL language standard to compile for.">, 
Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0">;
 def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
 def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], 
"cl-fp32-correctly-rounded-divide-sqrt">, Group, 
Flags<[CC1Option]>,
@@ -804,7 +804,7 @@ def fno_sanitize_coverage
 : CommaJoined<["-"], "fno-sanitize-coverage=">,
   Group, Flags<[CoreOption, DriverOption]>,
   HelpText<"Disable specified features of coverage instrumentation for "
-   "Sanitizers">;
+   "Sanitizers">, 
Values<"func,bb,edge,indirect-calls,trace-bb,trace-cmp,trace-div,trace-gep,8bit-counters,trace-pc,trace-pc-guard,no-prune,inline-8bit-counters">;
 def fsanitize_memory_track_origins_EQ : Joined<["-"], 
"fsanitize-memory-track-origins=">,
 Group,
 HelpText<"Enable origins tracking in 
MemorySanitizer">;
@@ -923,7 +923,7 @@ def ftrapping_math : Flag<["-"], "ftrapp
 def fno_trapping_math : Flag<["-"], "fno-trapping-math">, Group, 
Flags<[CC1Option]>;
 def ffp_contract : Joined<["-"], "ffp-contract=">, Group,
   Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs): fast 
(everywhere)"
-  " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">;
+  " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">, 
Values<"fast,on,off">;
 
 def ffor_scope : Flag<["-"], "ffor-scope">, Group;
 def fno_for_scope : Flag<["-"], "fno-for-scope">, Group;
@@ -1000,7 +1000,7 @@ def flat__namespace : Flag<["-"], "flat_
 def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, 
Group;
 def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, 
Group;
 def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, 
Group,
-  HelpText<"Set LTO mode to either 'full' or 'thin'">;
+  HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">;
 def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Enable LTO in 'full' mode">;
 def fno_lto : Flag<["-"], "fno-lto">, Group,
@@ -1158,7 +1158,7 @@ def fno_experimental_new_pass_manager :
   Group, Flags<[CC1Option]>,
   HelpText<"Disables an experimental new pass manager in LLVM.">;
 def fveclib : Joined<["-"], "fveclib=">, Group, Flags<[CC1Option]>,
-HelpText<"Use the given vector functions library">;
+HelpText<"Use the given vector functions library">, 
Values<"Accelerate,SVML,none">;
 def fno_lax_vector_conversions : Flag<["-"],

[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/Sema/SemaLookup.cpp:870
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()

rsmith wrote:
> Maybe only call this once?
Sure, I'll extract this into a variable above the if statement before 
committing.


https://reviews.llvm.org/D34370



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


[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-20 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi closed this revision.
yamaguchi added a comment.

Landed in https://reviews.llvm.org/rL305805.


https://reviews.llvm.org/D33383



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


[PATCH] D28691: Add OpenCL 2.0 atomic builtin functions as Clang builtin

2017-06-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: include/clang/Basic/Builtins.def:713
+ATOMIC_BUILTIN(__opencl_atomic_fetch_or, "v.", "t")
+ATOMIC_BUILTIN(__opencl_atomic_fetch_xor, "v.", "t")
+

What about min/max? I believe they will need to have the scope too. 



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6956
+  "synchronization scope argument to atomic operation is invalid">;
+def err_atomic_op_has_non_constant_synch_scope : Error<
+  "non-constant synchronization scope argument to atomic operation is not 
supported">;

Btw, is this disallowed by the spec? Can't find anything relevant.



Comment at: lib/CodeGen/CGAtomic.cpp:678
 RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
+  bool IsOpenCL = E->isOpenCL();
   QualType AtomicTy = E->getPtr()->getType()->getPointeeType();

Seems short enough to introduce an extra variable here. :)



Comment at: lib/CodeGen/CGAtomic.cpp:707
 
-  switch (E->getOp()) {
+  auto Op = E->getOp();
+  switch (Op) {

The same here... not sure adding an extra variable is helping here. :)



Comment at: lib/CodeGen/CGAtomic.cpp:889
+return V;
+  auto OrigLangAS = E->getType()
+.getTypePtr()

Formatting seems to be a bit odd here...



Comment at: lib/CodeGen/CGAtomic.cpp:1117
+  "Non-constant synchronization scope not supported");
+  auto sco = (llvm::SynchronizationScope)(
+  cast(Scope)->getZExtValue());

Variable name doesn't follow the style.



Comment at: lib/CodeGen/CGAtomic.cpp:1117
+  "Non-constant synchronization scope not supported");
+  auto sco = (llvm::SynchronizationScope)(
+  cast(Scope)->getZExtValue());

Anastasia wrote:
> Variable name doesn't follow the style.
could we avoid using C style cast?



Comment at: lib/Sema/SemaChecking.cpp:3146
+Op == AtomicExpr::AO__opencl_atomic_load)
+? 0
+: 1);

formatting seems odd.



Comment at: test/CodeGenOpenCL/atomic-ops-libcall.cl:1
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple spir64 
-emit-llvm | FileCheck -check-prefix=GEN4 %s
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple 
armv5e-none-linux-gnueabi -emit-llvm | FileCheck -check-prefix=GEN0 %s

GEN4 -> SPIR



Comment at: test/CodeGenOpenCL/atomic-ops-libcall.cl:2
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple spir64 
-emit-llvm | FileCheck -check-prefix=GEN4 %s
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple 
armv5e-none-linux-gnueabi -emit-llvm | FileCheck -check-prefix=GEN0 %s
+

GEN0 -> AMDGPU



Comment at: test/CodeGenOpenCL/atomic-ops-libcall.cl:4
+
+void f(atomic_int *i, int cmp) {
+  int x;

Could we use different scopes?



Comment at: test/CodeGenOpenCL/atomic-ops.cl:7
+
+#ifndef ALREADY_INCLUDED
+#define ALREADY_INCLUDED

why do we need this?



Comment at: test/CodeGenOpenCL/atomic-ops.cl:15
+  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} 
singlethread seq_cst
+  int x = __opencl_atomic_load(i, memory_order_seq_cst, 
memory_scope_work_item);
+}

I think we could use different scope types all over...



Comment at: test/CodeGenOpenCL/atomic-ops.cl:32
+  // CHECK-LABEL: @fi4(
+  // CHECK: [[PAIR:%[.0-9A-Z_a-z]+]] = cmpxchg i32 addrspace(4)* 
[[PTR:%[.0-9A-Z_a-z]+]], i32 [[EXPECTED:%[.0-9A-Z_a-z]+]], i32 
[[DESIRED:%[.0-9A-Z_a-z]+]] singlethread acquire acquire
+  // CHECK: [[OLD:%[.0-9A-Z_a-z]+]] = extractvalue { i32, i1 } [[PAIR]], 0

do we have an addrspacecast before?



Comment at: test/SemaOpenCL/atomic-ops.cl:22
+   intptr_t *P, float *D, struct S *s1, struct S *s2) {
+  __opencl_atomic_init(I, 5); // expected-error {{pointer to _Atomic}}
+  __opencl_atomic_init(ci, 5); // expected-error {{address argument to atomic 
operation must be a pointer to non-const _Atomic type ('const __generic 
atomic_int *' (aka 'const __generic _Atomic(int) *') invalid)}}

could we have the full error for consistency?



Comment at: test/SemaOpenCL/atomic-ops.cl:30
+  __opencl_atomic_store(i, 0, memory_order_relaxed, memory_scope_work_item);
+  __opencl_atomic_store(ci, 0, memory_order_relaxed, memory_scope_work_item); 
// expected-error {{address argument to atomic operation must be a pointer to 
non-const _Atomic type ('const __generic atomic_int *' (aka 'const __generic 
_Atomic(int) *') invalid)}}
+

could we also test with constant AS? Also I would generally improve testing wrt 
address spaces...


https://reviews.llvm.o

[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: include/clang/Basic/Builtins.def:55
 //  W   -> int64_t
+//  l   -> 'int' if builtin is a MS extensions and the target is Darwin/LP64.
+// Defaults to 'L' otherwise.

majnemer wrote:
> Why not just LP64? Seems arbitrary to make this Darwin sensitive.
Every existing prefix is upper case. Do you think it makes it more readable to 
follow the pattern? Maybe it isn't worth it.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

compnerd wrote:
> I agree with @majnemer.  Why not base this on the Int64Type?
I'd suggest this code:
  IsSpecialLong = true;
  // Use "long" if is 32 bits. This prefix is used by intrinsics that need 
32-bit types on LP64 platforms, but need to use "long" in the prototype on 
LLP64 platforms like Win64.
  if (Context.getTargetInfo().getLongWidth() == 32)
HowLong = 1;
  break;


https://reviews.llvm.org/D34377



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


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2017-06-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1605
+  ? CGM.getDataLayout().getAllocaAddrSpace()
+  : getContext().getTargetAddressSpace(LangAS::Default));
   break;

rjmccall wrote:
> Everything about your reasoning seems to apply to normal indirect arguments, 
> too.
non-byval indirect argument is normally in default address space instead of 
alloca address space. For example,


```
struct A { int a;};
void f(A &x);
```
`x` is an indirect argument but should not be in alloca addr space, since the 
caller may pass a reference to a global variable.


https://reviews.llvm.org/D34367



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


r305812 - Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Tue Jun 20 12:38:07 2017
New Revision: 305812

URL: http://llvm.org/viewvc/llvm-project?rev=305812&view=rev
Log:
Fix for Bug 33471: Preventing operator auto from resolving to a template 
operator.

As the bug report says,
struct A
{

  template operator T();

};

void foo()
{

  A().operator auto();

}

causes: "undeduced type in IR-generation
UNREACHABLE executed at llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:208!"

The problem is that in this case, "T" is being deduced as "auto", 
which I believe is incorrect.

The 'operator auto' implementation in Clang is standards compliant, however 
there is a defect report against core (1670).

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

Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=305812&r1=305811&r2=305812&view=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Jun 20 12:38:07 2017
@@ -862,6 +862,16 @@ static bool LookupDirect(Sema &S, Lookup
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  auto *ContainedDeducedType =
+  R.getLookupName().getCXXNameType()->getContainedDeducedType();
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  ContainedDeducedType && ContainedDeducedType->isUndeducedType())
+return Found;
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);

Modified: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp?rev=305812&r1=305811&r2=305812&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp Tue Jun 20 12:38:07 
2017
@@ -55,6 +55,25 @@ auto b(bool k) {
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 
'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 
'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from 
returned value of type 'int'}}
 }


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


[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305812: Fix for Bug 33471: Preventing operator auto from 
resolving to a template… (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D34370?vs=103224&id=103235#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34370

Files:
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp


Index: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 
'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 
'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from 
returned value of type 'int'}}
 }
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -862,6 +862,16 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  auto *ContainedDeducedType =
+  R.getLookupName().getCXXNameType()->getContainedDeducedType();
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  ContainedDeducedType && ContainedDeducedType->isUndeducedType())
+return Found;
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);


Index: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from returned value of type 'int'}}
 }
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -862,6 +862,16 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  auto *ContainedDeducedType =
+  R.getLookupName().getCXXNameType()->getContainedDeducedType();
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  ContainedDeducedType && ContainedDeducedType->isUndeducedType())
+return Found;
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-06-20 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

> Can we drop computing these for some expressions that we know the 
> RangeConstraintManager will not utilize?

It's possible, though I'm not sure what the actual limitations of the 
RangeConstraintManager are, since there are a lot of intermediate steps that 
attempt to transform unsupported expressions into supported ones.

> We could implement the TODO described below and possibly also lower the 
> MaxComp value. This means that instead of keeping a complex expression and 
> constraints on every symbol used in that expression, we would conjure a new 
> symbol and associate a new constrain derived from the expression with it. 
> (Would this strategy also work for the Z3 case?)

I think it's feasible, but would probably require some more to code to handle 
`SymbolConjured` (right now all `SymbolData` are treated as variables).

> Would it help to decrease 100 to 10 here?

Yes, changing it to 10 eliminates the excessive recursion; combined runtime 
drops to 282 sec on the testcases (~8 sec for Range only, ~271 sec for Z3 only; 
doesn't sum due to separate executions). This appears to be the most 
straightforward solution.

> (2) With RangeConstraintManager, simplification is not entirely idempotent: 
> we may simplify a symbol further when one of its sub-symbols gets constrained 
> to a constant in a new state. However, apart from that, we might be able to 
> avoid re-simplifying the same symbol by caching results based on the (symbol, 
> state's constraint data) pair. Probably it may work with Z3 as well.

Yeah, that would also fix this issue. In general, I think there's plenty of 
room for improvements from caching, especially for queries to e.g. 
`getSymVal()`.


https://reviews.llvm.org/D28953



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


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-06-20 Thread Dominic Chen via Phabricator via cfe-commits
ddcc updated this revision to Diff 103239.
ddcc added a comment.

Rebase, decrease simplification complexity


https://reviews.llvm.org/D28953

Files:
  include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  lib/StaticAnalyzer/Core/SValBuilder.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
  test/Analysis/bitwise-ops.c
  test/Analysis/bool-assignment.c
  test/Analysis/conditional-path-notes.c
  test/Analysis/explain-svals.cpp
  test/Analysis/plist-macros.cpp
  test/Analysis/range_casts.c
  test/Analysis/std-c-library-functions.c

Index: test/Analysis/std-c-library-functions.c
===
--- test/Analysis/std-c-library-functions.c
+++ test/Analysis/std-c-library-functions.c
@@ -57,8 +57,7 @@
   size_t y = fread(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(y <= 10); // expected-warning{{TRUE}}
   size_t z = fwrite(buf, sizeof(int), y, fp);
-  // FIXME: should be TRUE once symbol-symbol constraint support is improved.
-  clang_analyzer_eval(z <= y); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(z <= y); // expected-warning{{TRUE}}
 }
 
 ssize_t getline(char **, size_t *, FILE *);
Index: test/Analysis/range_casts.c
===
--- test/Analysis/range_casts.c
+++ test/Analysis/range_casts.c
@@ -67,8 +67,8 @@
 {
   unsigned index = -1;
   if (index < foo) index = foo;
-  if (index - 1 == 0) // Was not reached prior fix.
-clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (index - 1 == 0)
+clang_analyzer_warnIfReached(); // no-warning
   else
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
@@ -87,8 +87,8 @@
 {
   unsigned index = -1;
   if (index < foo) index = foo;
-  if (index - 1L == 0L) // Was not reached prior fix.
-clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (index - 1L == 0L)
+clang_analyzer_warnIfReached(); // no-warning
   else
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
@@ -117,8 +117,8 @@
 {
   unsigned index = -1;
   if (index < foo) index = foo;
-  if (index - 1UL == 0L) // Was not reached prior fix.
-clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (index - 1UL == 0L)
+clang_analyzer_warnIfReached(); // no-warning
   else
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
Index: test/Analysis/plist-macros.cpp
===
--- test/Analysis/plist-macros.cpp
+++ test/Analysis/plist-macros.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-eagerly-assume -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-eagerly-assume -analyzer-output=plist-multi-file -analyzer-config path-diagnostics-alternate=ture %s -o %t.plist
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-eagerly-assume -analyzer-output=plist-multi-file -analyzer-config path-diagnostics-alternate=true %s -o %t.plist
 // RUN: FileCheck --input-file=%t.plist %s
 
 
@@ -85,6 +85,7 @@
 void test2(int *p) {
   CALL_FN(p);
 }
+
 // CHECK:  diagnostics
 // CHECK-NEXT:  
 // CHECK-NEXT:   
@@ -636,6 +637,69 @@
 // CHECK-NEXT: end
 // CHECK-NEXT:  
 // CHECK-NEXT:   
+// CHECK-NEXT:line36
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line36
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindevent
+// CHECK-NEXT:  location
+// CHECK-NEXT:  
+// CHECK-NEXT:   line36
+// CHECK-NEXT:   col7
+// CHECK-NEXT:   file0
+// CHECK-NEXT:  
+// CHECK-NEXT:  ranges
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  line36
+// CHECK-NEXT:  col7
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  line36
+// CHECK-NEXT:  col25
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT:
+// CHECK-NEXT:  
+// CHECK-NEXT:  depth0
+// CHECK-NEXT:  extended_message
+// CHECK-NEXT:  Assuming the condition is true
+// CHECK-NEXT:  message
+// CHECK-NEXT:  Assuming the condition is true
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line36
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line36
+// CHECK-N

[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-06-20 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

I forgot to mention that the only remaining test failure is on 
`plist-macros.cpp`; there is a `Assuming condition is true` path note that only 
appears with the RangeConstraintManager but not with Z3ConstraintManager, and I 
can't `#ifdef` it because the annotations are checked by `FileCheck`.


https://reviews.llvm.org/D28953



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


[PATCH] D33842: [AMDGPU] Fix address space of global variable

2017-06-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: include/clang/Basic/TargetInfo.h:959
+  /// \brief Return the target address space which is read only and can be
+  /// casted to the generic address space.
+  virtual llvm::Optional getTargetConstantAddressSpace() const {

rjmccall wrote:
> "Return an AST address space which can be used opportunistically for constant 
> global memory.  It must be possible to convert pointers into this address 
> space to LangAS::Default.  If no such address space exists, this may return 
> None, and such optimizations will be disabled."
I will change it. Also I think getConstantAddressSpace may be a better name 
since we will return AST addr space.



Comment at: lib/CodeGen/CGExpr.cpp:449
+ Var, ConvertTypeForMem(E->getType())->getPointerTo()),
  Object.getAlignment());
 // If the temporary is a global and has a constant initializer or is a

rjmccall wrote:
> Every time you're tempted to use getPointerCast, you should instead be using 
> the target hook to lift the pointer into the right address space.
I am going to fix it. However this seems not the right place to do the addr 
space cast. I am going to do it in createReferenceTemporary instead.


https://reviews.llvm.org/D33842



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


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1605
+  ? CGM.getDataLayout().getAllocaAddrSpace()
+  : getContext().getTargetAddressSpace(LangAS::Default));
   break;

yaxunl wrote:
> rjmccall wrote:
> > Everything about your reasoning seems to apply to normal indirect 
> > arguments, too.
> non-byval indirect argument is normally in default address space instead of 
> alloca address space. For example,
> 
> 
> ```
> struct A { int a;};
> void f(A &x);
> ```
> `x` is an indirect argument but should not be in alloca addr space, since the 
> caller may pass a reference to a global variable.
'x' is not an indirect argument in this context.  It is a direct argument that 
happens to be of reference type.

A normal Indirect argument is when the ABI says an argument should implicitly 
be passed as a pointer to a temporary.  IndirectByVal is when the ABI says that 
something should be passed directly in the arguments area of the stack.  Some 
targets never use indirect arguments for normal C cases, but they're still used 
for direct non-POD arguments in C++.


https://reviews.llvm.org/D34367



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


[PATCH] D33953: [libcxx] [test] Add more tests to tuple_size_structured_bindings.pass.cpp and make it friendlier to C1XX.

2017-06-20 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT added a comment.

Ping?


https://reviews.llvm.org/D33953



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


[PATCH] D34210: Add __has_feature(leak_sanitizer)

2017-06-20 Thread Francis Ricci via Phabricator via cfe-commits
fjricci reclaimed this revision.
fjricci added a comment.

As I've looked into this further, I do think we need 
`has_feature(leak_sanitizer)` after all. For example, if a user program calls 
`pthread_create()` with a custom stack size, leak sanitizer will intercept the 
call to `pthread_create()`, and may modify the stack size set by the user 
(lsan's interceptor for `pthread_create` calls `AdjustStackSize` in 
sanitizer_common). Without `has_feature(leak_sanitizer)`, there's no good way 
for the user program to account for these sorts of modifications. There are 
most likely other interceptors which will cause similar issues, this is just 
the first example I ran into.


https://reviews.llvm.org/D34210



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


[libcxx] r305829 - Creating release candidate final from release_401 branch

2017-06-20 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Jun 20 14:29:48 2017
New Revision: 305829

URL: http://llvm.org/viewvc/llvm-project?rev=305829&view=rev
Log:
Creating release candidate final from release_401 branch

Added:
libcxx/tags/RELEASE_401/final/   (props changed)
  - copied from r305828, libcxx/branches/release_40/

Propchange: libcxx/tags/RELEASE_401/final/
--
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Jun 20 14:29:48 2017
@@ -0,0 +1,2 @@
+/libcxx/branches/apple:136569-137939
+/libcxx/trunk:292013,292091,292607,292990,293154,293197,293581,294133,294142,294431


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


[libcxxabi] r305830 - Creating release candidate final from release_401 branch

2017-06-20 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Jun 20 14:29:53 2017
New Revision: 305830

URL: http://llvm.org/viewvc/llvm-project?rev=305830&view=rev
Log:
Creating release candidate final from release_401 branch

Added:
libcxxabi/tags/RELEASE_401/final/   (props changed)
  - copied from r305829, libcxxabi/branches/release_40/

Propchange: libcxxabi/tags/RELEASE_401/final/
--
svn:mergeinfo = /libcxxabi/trunk:292135,292418,292638


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


[libunwind] r305836 - Creating release candidate final from release_401 branch

2017-06-20 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Jun 20 14:30:24 2017
New Revision: 305836

URL: http://llvm.org/viewvc/llvm-project?rev=305836&view=rev
Log:
Creating release candidate final from release_401 branch

Added:
libunwind/tags/RELEASE_401/final/   (props changed)
  - copied from r305835, libunwind/branches/release_40/

Propchange: libunwind/tags/RELEASE_401/final/
--
svn:mergeinfo = /libunwind/trunk:292723,296358-296359


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


[PATCH] D34210: Add __has_feature(leak_sanitizer)

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

If LSan is a runtime thing, why not use weak hooks or something to detect LSan 
at runtime instead of using a macro?


https://reviews.llvm.org/D34210



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


[PATCH] D34294: Rework libcxx strerror_r handling.

2017-06-20 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

EricWF, wdyt?


https://reviews.llvm.org/D34294



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


[PATCH] D34266: Static Analyzer - Localizability Checker: New Localizable APIs for macOS High Sierra & iOS 11

2017-06-20 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

> Hmm, should there be new tests that demonstrate that we cover the new APIs?

Unless we use a new registration mechanism for some of these APIs, I'd be fine 
without adding a test for every API that has localization constraints.


Repository:
  rL LLVM

https://reviews.llvm.org/D34266



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


[libcxx] r305841 - Fix discovery of cxxabi.h in the monorepo layout

2017-06-20 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jun 20 15:34:13 2017
New Revision: 305841

URL: http://llvm.org/viewvc/llvm-project?rev=305841&view=rev
Log:
Fix discovery of cxxabi.h in the monorepo layout

Modified:
libcxx/trunk/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=305841&r1=305840&r2=305841&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Tue Jun 20 15:34:13 2017
@@ -118,6 +118,7 @@ if (LIBCXX_CXX_ABI STREQUAL "default")
 cxxabi.h
 PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include
   ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include
+  ${LLVM_MAIN_SRC_DIR}/../libcxxabi/include
 NO_DEFAULT_PATH
   )
   if (LIBCXX_TARGETING_MSVC)


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


[libcxx] r305843 - [libcxx] [test] Add more tests to tuple_size_structured_bindings.pass.cpp and make it friendlier to C1XX.

2017-06-20 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Tue Jun 20 15:34:50 2017
New Revision: 305843

URL: http://llvm.org/viewvc/llvm-project?rev=305843&view=rev
Log:
[libcxx] [test] Add more tests to tuple_size_structured_bindings.pass.cpp and 
make it friendlier to C1XX.

Style/paranoia: 42.1 doesn't have an exact binary representation. Although this 
doesn't
cause failures, it makes me uncomfortable, so I'm changing it to 42.5.

C1XX rightly warns about unreferenced variables. Adding tests for their values
makes C1XX happy and improves test coverage.

C1XX (somewhat obnoxiously) warns about seeing a struct specialized as a class.
Although the Standard doesn't care, saying struct consistently is better.
(The Standard itself is still inconsistent about whether to depict tuple_element
and tuple_size as structs or classes.)

Fixes D33953.

Modified:

libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp?rev=305843&r1=305842&r2=305843&view=diff
==
--- 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 Tue Jun 20 15:34:50 2017
@@ -64,18 +64,22 @@ void test_decomp_tuple() {
 void test_decomp_pair() {
   typedef std::pair T;
   {
-T s{99, 42.1};
+T s{99, 42.5};
 auto [m1, m2] = s;
 auto& [r1, r2] = s;
 assert(m1 == 99);
+assert(m2 == 42.5);
 assert(&r1 == &std::get<0>(s));
+assert(&r2 == &std::get<1>(s));
   }
   {
-T const s{99, 42.1};
+T const s{99, 42.5};
 auto [m1, m2] = s;
 auto& [r1, r2] = s;
 assert(m1 == 99);
+assert(m2 == 42.5);
 assert(&r1 == &std::get<0>(s));
+assert(&r2 == &std::get<1>(s));
   }
 }
 
@@ -86,14 +90,22 @@ void test_decomp_array() {
 auto [m1, m2, m3] = s;
 auto& [r1, r2, r3] = s;
 assert(m1 == 99);
+assert(m2 == 42);
+assert(m3 == -1);
 assert(&r1 == &std::get<0>(s));
+assert(&r2 == &std::get<1>(s));
+assert(&r3 == &std::get<2>(s));
   }
   {
 T const s{{99, 42, -1}};
 auto [m1, m2, m3] = s;
 auto& [r1, r2, r3] = s;
 assert(m1 == 99);
+assert(m2 == 42);
+assert(m3 == -1);
 assert(&r1 == &std::get<0>(s));
+assert(&r2 == &std::get<1>(s));
+assert(&r3 == &std::get<2>(s));
   }
 }
 
@@ -105,8 +117,7 @@ template 
 int get(Test const&) { static_assert(N == 0, ""); return -1; }
 
 template <>
-class std::tuple_element<0, Test> {
-public:
+struct std::tuple_element<0, Test> {
   typedef int type;
 };
 
@@ -117,8 +128,7 @@ void test_before_tuple_size_specializati
 }
 
 template <>
-class std::tuple_size {
-public:
+struct std::tuple_size {
   static const size_t value = 1;
 };
 


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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: include/clang/Basic/Builtins.def:55
 //  W   -> int64_t
+//  l   -> 'int' if builtin is a MS extensions and the target is Darwin/LP64.
+// Defaults to 'L' otherwise.

rnk wrote:
> majnemer wrote:
> > Why not just LP64? Seems arbitrary to make this Darwin sensitive.
> Every existing prefix is upper case. Do you think it makes it more readable 
> to follow the pattern? Maybe it isn't worth it.
At first attempt I tried to make it more generic, but there seems to be 
different expected behavior in other platforms: for instance, there are 
Linux/LP64 tests that expect 'long' here to be 64-bits, see 
CodeGen/ms-intrinsics-rotations.c.



Comment at: include/clang/Basic/Builtins.def:55
 //  W   -> int64_t
+//  l   -> 'int' if builtin is a MS extensions and the target is Darwin/LP64.
+// Defaults to 'L' otherwise.

bruno wrote:
> rnk wrote:
> > majnemer wrote:
> > > Why not just LP64? Seems arbitrary to make this Darwin sensitive.
> > Every existing prefix is upper case. Do you think it makes it more readable 
> > to follow the pattern? Maybe it isn't worth it.
> At first attempt I tried to make it more generic, but there seems to be 
> different expected behavior in other platforms: for instance, there are 
> Linux/LP64 tests that expect 'long' here to be 64-bits, see 
> CodeGen/ms-intrinsics-rotations.c.
It might be better indeed, but seems like all "good letters" are taken, what 
about 'N'? As for "Narrow" long (Duncan's suggestion)?



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

rnk wrote:
> compnerd wrote:
> > I agree with @majnemer.  Why not base this on the Int64Type?
> I'd suggest this code:
>   IsSpecialLong = true;
>   // Use "long" if is 32 bits. This prefix is used by intrinsics that need 
> 32-bit types on LP64 platforms, but need to use "long" in the prototype on 
> LLP64 platforms like Win64.
>   if (Context.getTargetInfo().getLongWidth() == 32)
> HowLong = 1;
>   break;
See below.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

bruno wrote:
> rnk wrote:
> > compnerd wrote:
> > > I agree with @majnemer.  Why not base this on the Int64Type?
> > I'd suggest this code:
> >   IsSpecialLong = true;
> >   // Use "long" if is 32 bits. This prefix is used by intrinsics that need 
> > 32-bit types on LP64 platforms, but need to use "long" in the prototype on 
> > LLP64 platforms like Win64.
> >   if (Context.getTargetInfo().getLongWidth() == 32)
> > HowLong = 1;
> >   break;
> See below.
I tried something similar before, but I get two tests failing 
CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion hits 
the same failing tests. Both fails because of the Linux issue mentioned above: 
i32 codegen where i64 is expected. Of course I could improve the condition to 
handle Linux, but at that point I just thing it's better to use Darwin, which 
is what the fix is towards anyway. Additional ideas?


https://reviews.llvm.org/D34377



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


r305845 - [clang] Fix format specifiers fixits for nested macros

2017-06-20 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Tue Jun 20 15:46:58 2017
New Revision: 305845

URL: http://llvm.org/viewvc/llvm-project?rev=305845&view=rev
Log:
[clang] Fix format specifiers fixits for nested macros

ExpansionLoc was previously calculated incorrectly in the case of 
nested macros expansions. In this diff we build the stack of expansions 
where the last one is the actual expansion which should be used 
for grouping together the edits. 
The definition of MacroArgUse is adjusted accordingly.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D34268

Modified:
cfe/trunk/include/clang/Edit/EditedSource.h
cfe/trunk/lib/Edit/EditedSource.cpp
cfe/trunk/test/FixIt/fixit-format-darwin.m

Modified: cfe/trunk/include/clang/Edit/EditedSource.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Edit/EditedSource.h?rev=305845&r1=305844&r2=305845&view=diff
==
--- cfe/trunk/include/clang/Edit/EditedSource.h (original)
+++ cfe/trunk/include/clang/Edit/EditedSource.h Tue Jun 20 15:46:58 2017
@@ -17,6 +17,7 @@
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
 #include 
+#include 
 
 namespace clang {
   class LangOptions;
@@ -41,10 +42,20 @@ class EditedSource {
   typedef std::map FileEditsTy;
   FileEditsTy FileEdits;
 
-  // Location of argument use inside the macro body 
-  typedef std::pair MacroArgUse;
-  llvm::DenseMap>
-ExpansionToArgMap;
+  struct MacroArgUse {
+IdentifierInfo *Identifier;
+SourceLocation ImmediateExpansionLoc;
+// Location of argument use inside the top-level macro
+SourceLocation UseLoc;
+
+bool operator==(const MacroArgUse &Other) const {
+  return std::tie(Identifier, ImmediateExpansionLoc, UseLoc) ==
+ std::tie(Other.Identifier, Other.ImmediateExpansionLoc,
+  Other.UseLoc);
+}
+  };
+
+  llvm::DenseMap> ExpansionToArgMap;
   SmallVector, 2>
 CurrCommitMacroArgExps;
 

Modified: cfe/trunk/lib/Edit/EditedSource.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/EditedSource.cpp?rev=305845&r1=305844&r2=305845&view=diff
==
--- cfe/trunk/lib/Edit/EditedSource.cpp (original)
+++ cfe/trunk/lib/Edit/EditedSource.cpp Tue Jun 20 15:46:58 2017
@@ -28,13 +28,18 @@ void EditedSource::deconstructMacroArgLo
   MacroArgUse &ArgUse) {
   assert(SourceMgr.isMacroArgExpansion(Loc));
   SourceLocation DefArgLoc = SourceMgr.getImmediateExpansionRange(Loc).first;
-  ExpansionLoc = SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  SourceLocation ImmediateExpansionLoc =
+  SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  ExpansionLoc = ImmediateExpansionLoc;
+  while (SourceMgr.isMacroBodyExpansion(ExpansionLoc))
+ExpansionLoc = SourceMgr.getImmediateExpansionRange(ExpansionLoc).first;
   SmallString<20> Buf;
   StringRef ArgName = Lexer::getSpelling(SourceMgr.getSpellingLoc(DefArgLoc),
  Buf, SourceMgr, LangOpts);
-  ArgUse = {nullptr, SourceLocation()};
+  ArgUse = MacroArgUse{nullptr, SourceLocation(), SourceLocation()};
   if (!ArgName.empty())
-ArgUse = {&IdentTable.get(ArgName), SourceMgr.getSpellingLoc(DefArgLoc)};
+ArgUse = {&IdentTable.get(ArgName), ImmediateExpansionLoc,
+  SourceMgr.getSpellingLoc(DefArgLoc)};
 }
 
 void EditedSource::startingCommit() {}
@@ -69,10 +74,11 @@ bool EditedSource::canInsertInOffset(Sou
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
 auto I = ExpansionToArgMap.find(ExpLoc.getRawEncoding());
 if (I != ExpansionToArgMap.end() &&
-std::find_if(
-I->second.begin(), I->second.end(), [&](const MacroArgUse &U) {
-  return ArgUse.first == U.first && ArgUse.second != U.second;
-}) != I->second.end()) {
+find_if(I->second, [&](const MacroArgUse &U) {
+  return ArgUse.Identifier == U.Identifier &&
+ std::tie(ArgUse.ImmediateExpansionLoc, ArgUse.UseLoc) !=
+ std::tie(U.ImmediateExpansionLoc, U.UseLoc);
+}) != I->second.end()) {
   // Trying to write in a macro argument input that has already been
   // written by a previous commit for another expansion of the same macro
   // argument name. For example:
@@ -89,7 +95,6 @@ bool EditedSource::canInsertInOffset(Sou
   return false;
 }
   }
-
   return true;
 }
 
@@ -102,13 +107,13 @@ bool EditedSource::commitInsert(SourceLo
 return true;
 
   if (SourceMgr.isMacroArgExpansion(OrigLoc)) {
-SourceLocation ExpLoc;
 MacroArgUse ArgUse;
+SourceLocation ExpLoc;
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
-if (ArgUse.first)
+if (ArgUse.Identifier)
   CurrCommitMacroArgExps.emplace_back(ExpLoc, ArgUse);
   }
-  
+
   FileEdit &FA = FileEdits[Offs];
   if (FA.T

[PATCH] D34268: [clang] Fix format specifiers fixits for nested macros

2017-06-20 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305845: [clang] Fix format specifiers fixits for nested 
macros (authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D34268?vs=103093&id=103262#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34268

Files:
  cfe/trunk/include/clang/Edit/EditedSource.h
  cfe/trunk/lib/Edit/EditedSource.cpp
  cfe/trunk/test/FixIt/fixit-format-darwin.m

Index: cfe/trunk/include/clang/Edit/EditedSource.h
===
--- cfe/trunk/include/clang/Edit/EditedSource.h
+++ cfe/trunk/include/clang/Edit/EditedSource.h
@@ -17,6 +17,7 @@
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
 #include 
+#include 
 
 namespace clang {
   class LangOptions;
@@ -41,10 +42,20 @@
   typedef std::map FileEditsTy;
   FileEditsTy FileEdits;
 
-  // Location of argument use inside the macro body 
-  typedef std::pair MacroArgUse;
-  llvm::DenseMap>
-ExpansionToArgMap;
+  struct MacroArgUse {
+IdentifierInfo *Identifier;
+SourceLocation ImmediateExpansionLoc;
+// Location of argument use inside the top-level macro
+SourceLocation UseLoc;
+
+bool operator==(const MacroArgUse &Other) const {
+  return std::tie(Identifier, ImmediateExpansionLoc, UseLoc) ==
+ std::tie(Other.Identifier, Other.ImmediateExpansionLoc,
+  Other.UseLoc);
+}
+  };
+
+  llvm::DenseMap> ExpansionToArgMap;
   SmallVector, 2>
 CurrCommitMacroArgExps;
 
Index: cfe/trunk/test/FixIt/fixit-format-darwin.m
===
--- cfe/trunk/test/FixIt/fixit-format-darwin.m
+++ cfe/trunk/test/FixIt/fixit-format-darwin.m
@@ -57,3 +57,20 @@
   Log3("test 7: %s", getNSInteger(), getNSUInteger());
   // CHECK: Log3("test 7: %ld", (long)getNSInteger(), (unsigned long)getNSUInteger());
 }
+
+#define Outer1(...) \
+do { \
+  printf(__VA_ARGS__); \
+} while (0)
+
+#define Outer2(...) \
+do { \
+  Outer1(__VA_ARGS__); Outer1(__VA_ARGS__); \
+} while (0)
+
+void bug33447() {
+  Outer2("test 8: %s", getNSInteger());  
+  // CHECK: Outer2("test 8: %ld", (long)getNSInteger());
+  Outer2("test 9: %s %s", getNSInteger(), getNSInteger());
+  // CHECK: Outer2("test 9: %ld %ld", (long)getNSInteger(), (long)getNSInteger());
+}
Index: cfe/trunk/lib/Edit/EditedSource.cpp
===
--- cfe/trunk/lib/Edit/EditedSource.cpp
+++ cfe/trunk/lib/Edit/EditedSource.cpp
@@ -28,13 +28,18 @@
   MacroArgUse &ArgUse) {
   assert(SourceMgr.isMacroArgExpansion(Loc));
   SourceLocation DefArgLoc = SourceMgr.getImmediateExpansionRange(Loc).first;
-  ExpansionLoc = SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  SourceLocation ImmediateExpansionLoc =
+  SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  ExpansionLoc = ImmediateExpansionLoc;
+  while (SourceMgr.isMacroBodyExpansion(ExpansionLoc))
+ExpansionLoc = SourceMgr.getImmediateExpansionRange(ExpansionLoc).first;
   SmallString<20> Buf;
   StringRef ArgName = Lexer::getSpelling(SourceMgr.getSpellingLoc(DefArgLoc),
  Buf, SourceMgr, LangOpts);
-  ArgUse = {nullptr, SourceLocation()};
+  ArgUse = MacroArgUse{nullptr, SourceLocation(), SourceLocation()};
   if (!ArgName.empty())
-ArgUse = {&IdentTable.get(ArgName), SourceMgr.getSpellingLoc(DefArgLoc)};
+ArgUse = {&IdentTable.get(ArgName), ImmediateExpansionLoc,
+  SourceMgr.getSpellingLoc(DefArgLoc)};
 }
 
 void EditedSource::startingCommit() {}
@@ -69,10 +74,11 @@
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
 auto I = ExpansionToArgMap.find(ExpLoc.getRawEncoding());
 if (I != ExpansionToArgMap.end() &&
-std::find_if(
-I->second.begin(), I->second.end(), [&](const MacroArgUse &U) {
-  return ArgUse.first == U.first && ArgUse.second != U.second;
-}) != I->second.end()) {
+find_if(I->second, [&](const MacroArgUse &U) {
+  return ArgUse.Identifier == U.Identifier &&
+ std::tie(ArgUse.ImmediateExpansionLoc, ArgUse.UseLoc) !=
+ std::tie(U.ImmediateExpansionLoc, U.UseLoc);
+}) != I->second.end()) {
   // Trying to write in a macro argument input that has already been
   // written by a previous commit for another expansion of the same macro
   // argument name. For example:
@@ -89,7 +95,6 @@
   return false;
 }
   }
-
   return true;
 }
 
@@ -102,13 +107,13 @@
 return true;
 
   if (SourceMgr.isMacroArgExpansion(OrigLoc)) {
-SourceLocation ExpLoc;
 MacroArgUse ArgUse;
+SourceLocation ExpLoc;
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
-if (ArgUse.first)
+if (ArgUse.Identifier)
   CurrCommitMacroArgExps.emplace_back(ExpLoc, ArgUse);
   }
-  
+
   FileEdit &FA = FileE

[PATCH] D34417: Switch TestVisitor to Lang_C via -x c

2017-06-20 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg created this revision.

...instead of -std=c99, as the latter lead to

  error: invalid argument '-std=c99' not allowed with 'C++'

complaints in test logs


https://reviews.llvm.org/D34417

Files:
  unittests/Tooling/TestVisitor.h


Index: unittests/Tooling/TestVisitor.h
===
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -53,7 +53,10 @@
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;


Index: unittests/Tooling/TestVisitor.h
===
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -53,7 +53,10 @@
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r305848 - [libcxx] [test] Strip trailing whitespace. NFC.

2017-06-20 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Tue Jun 20 16:00:02 2017
New Revision: 305848

URL: http://llvm.org/viewvc/llvm-project?rev=305848&view=rev
Log:
[libcxx] [test] Strip trailing whitespace. NFC.

Modified:

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp

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

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

libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
libcxx/trunk/test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp

libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/dtor.pass.cpp

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp?rev=305848&r1=305847&r2=305848&view=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -36,15 +36,15 @@ int main()
 auto f = for_each_test(0);
 Iter it = std::for_each_n(Iter(ia), 0, std::ref(f));
 assert(it == Iter(ia));
-assert(f.count == 0);
+assert(f.count == 0);
 }
 
 {
 auto f = for_each_test(0);
 Iter it = std::for_each_n(Iter(ia), s, std::ref(f));
-
+
 assert(it == Iter(ia+s));
-assert(f.count == s);
+assert(f.count == s);
 for (unsigned i = 0; i < s; ++i)
 assert(ia[i] == static_cast(i+1));
 }
@@ -52,9 +52,9 @@ int main()
 {
 auto f = for_each_test(0);
 Iter it = std::for_each_n(Iter(ia), 1, std::ref(f));
-
+
 assert(it == Iter(ia+1));
-assert(f.count == 1);
+assert(f.count == 1);
 for (unsigned i = 0; i < 1; ++i)
 assert(ia[i] == static_cast(i+2));
 }

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp?rev=305848&r1=305847&r2=305848&view=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -35,7 +35,7 @@ test(It i, typename std::iterator_traits
 
 #if TEST_STD_VER > 14
 template 
-constexpr bool 
+constexpr bool
 constepxr_test(It i, typename std::iterator_traits::difference_type n, It 
x)
 {
 std::advance(i, n);

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp?rev=305848&r1=305847&r2=305848&view=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -71,5 +71,5 @@ int main()
 static_assert( constexpr_test(s+1, s), "" );
 }
 #endif
-
+
 }

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp?rev=305848&r1=305847&r2=305848&view=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -13,7 +13,7 @@
 // template
 // OutputIterator exclusive_sca

r305850 - Preserve CXX method overrides in ASTImporter

2017-06-20 Thread Lang Hames via cfe-commits
Author: lhames
Date: Tue Jun 20 16:06:00 2017
New Revision: 305850

URL: http://llvm.org/viewvc/llvm-project?rev=305850&view=rev
Log:
Preserve CXX method overrides in ASTImporter

Summary:
The ASTImporter should import CXX method overrides from the source context
when it imports a method decl.

Reviewers: spyffe, rsmith, doug.gregor

Reviewed By: spyffe

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

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=305850&r1=305849&r2=305850&view=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:06:00 2017
@@ -1184,6 +1184,28 @@ void ASTDumper::VisitFunctionDecl(const
  I != E; ++I)
   dumpCXXCtorInitializer(*I);
 
+  if (const CXXMethodDecl *MD = dyn_cast(D))
+if (MD->size_overridden_methods() != 0) {
+  auto dumpOverride =
+[=](const CXXMethodDecl *D) {
+  SplitQualType T_split = D->getType().split();
+  OS << D << " " << D->getParent()->getName() << "::"
+ << D->getName() << " '"
+ << QualType::getAsString(T_split) << "'";
+};
+
+  dumpChild([=] {
+auto FirstOverrideItr = MD->begin_overridden_methods();
+OS << "Overrides: [ ";
+dumpOverride(*FirstOverrideItr);
+for (const auto *Override :
+   llvm::make_range(FirstOverrideItr + 1,
+MD->end_overridden_methods()))
+  dumpOverride(Override);
+OS << " ]";
+  });
+}
+
   if (D->doesThisDeclarationHaveABody())
 dumpStmt(D->getBody());
 }

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=305850&r1=305849&r2=305850&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jun 20 16:06:00 2017
@@ -319,6 +319,9 @@ namespace clang {
 bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
   return ImportArrayChecked(InContainer.begin(), InContainer.end(), 
Obegin);
 }
+
+// Importing overrides.
+void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
   };
 }
 
@@ -2025,6 +2028,9 @@ Decl *ASTNodeImporter::VisitFunctionDecl
   // Add this function to the lexical context.
   LexicalDC->addDeclInternal(ToFunction);
 
+  if (auto *FromCXXMethod = dyn_cast(D))
+ImportOverrides(cast(ToFunction), FromCXXMethod);
+
   return ToFunction;
 }
 
@@ -5499,6 +5505,14 @@ Expr *ASTNodeImporter::VisitSubstNonType
 Replacement);
 }
 
+void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
+  CXXMethodDecl *FromMethod) {
+  for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
+ToMethod->addOverriddenMethod(
+  cast(Importer.Import(const_cast(
+FromOverriddenMethod;
+}
+
 ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
  ASTContext &FromContext, FileManager &FromFileManager,
  bool MinimalImport)

Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/clang-import-test.cpp?rev=305850&r1=305849&r2=305850&view=diff
==
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
+++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Tue Jun 20 16:06:00 
2017
@@ -17,7 +17,9 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/ASTConsumers.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/MultiplexConsumer.h"
 #include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Preprocessor.h"
@@ -51,6 +53,10 @@ static llvm::cl::list
   llvm::cl::desc("Argument to pass to the CompilerInvocation"),
   llvm::cl::CommaSeparated);
 
+static llvm::cl::opt
+DumpAST("dump-ast", llvm::cl::init(false),
+llvm::cl::desc("Dump combined AST"));
+
 namespace init_convenience {
 class TestDiagnosticConsumer : public DiagnosticConsumer {
 private:
@@ -233,7 +239,7 @@ std::unique_ptr BuildI
 }
 
 llvm::Error ParseSource(const std::string &Path, CompilerInstance &CI,
-CodeGenerator &CG) {
+ASTConsumer &Consumer) {
   SourceManager &SM = CI.getSourceManager();
   const FileEntry *FE = CI.getFile

[PATCH] D34419: Make sure TraverseInitListExpr visits InitListExpr exactly twice

2017-06-20 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg created this revision.

... once each for the syntactic and semantic form. Without this fix, behavior 
of the newly added tests would have been

InitListExprIsPreOrderVisitedTwice:
 syntactic: 1
 semantic:  2

InitListExprIsPostOrderVisitedTwice:
 syntactic: 0
 semantic:  1

InitListExprIsPreOrderNoQueueVisitedTwice:
 syntactic: 1
 semantic:  2

InitListExprIsPostOrderNoQueueVisitedTwice:
 syntactic: 0
 semantic:  2


https://reviews.llvm.org/D34419

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/Tooling/RecursiveASTVisitorTest.cpp

Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -158,4 +158,90 @@
   "static int k = f();\n"));
 }
 
+// Check to ensure that InitListExpr is visited twice, once each for the
+// syntactic and semantic form.
+class InitListExprPreOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPreOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, InitListExprIsPreOrderVisitedTwice) {
+  InitListExprPreOrderVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPreOrderVisitor::Lang_C));
+}
+
+TEST(RecursiveASTVisitor, InitListExprIsPostOrderVisitedTwice) {
+  InitListExprPostOrderVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPostOrderVisitor::Lang_C));
+}
+
+TEST(RecursiveASTVisitor, InitListExprIsPreOrderNoQueueVisitedTwice) {
+  InitListExprPreOrderNoQueueVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPreOrderNoQueueVisitor::Lang_C));
+}
+
+TEST(RecursiveASTVisitor, InitListExprIsPostOrderNoQueueVisitedTwice) {
+  InitListExprPostOrderNoQueueVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPostOrderNoQueueVisitor::Lang_C));
+}
+
 } // end anonymous namespace
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -593,6 +593,16 @@
 #define STMT(CLASS, PARENT)\
   case Stmt::CLASS##Class: \
 TRY_TO(WalkUpFrom##CLASS(static_cast(S))); break;
+#define INITLISTEXPR(CLASS, PARENT)\
+  case Stmt::CLASS##Class: \
+{  \
+  auto ILE = static_cast(S);  \
+  if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE)\
+TRY_TO(WalkUpFrom##CLASS(Syn));\
+  if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \
+TRY_TO(WalkUpFrom##CLASS(Sem));  

[libcxx] r305854 - [libcxx] [test] Fix -Wmismatched-tags in tuple_size_structured_bindings.pass.cpp.

2017-06-20 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Tue Jun 20 16:10:53 2017
New Revision: 305854

URL: http://llvm.org/viewvc/llvm-project?rev=305854&view=rev
Log:
[libcxx] [test] Fix -Wmismatched-tags in 
tuple_size_structured_bindings.pass.cpp.

Clang and C1XX both complain about mismatched class/struct, but libc++ and 
MSVC's STL
differ on what they use for tuple_element/tuple_size, so there's no way to win 
here.

I'm reverting this part of my previous change. In the future, I'll have to 
suppress
the warning for one compiler or the other.

Modified:

libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp?rev=305854&r1=305853&r2=305854&view=diff
==
--- 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 Tue Jun 20 16:10:53 2017
@@ -117,7 +117,8 @@ template 
 int get(Test const&) { static_assert(N == 0, ""); return -1; }
 
 template <>
-struct std::tuple_element<0, Test> {
+class std::tuple_element<0, Test> {
+public:
   typedef int type;
 };
 
@@ -128,7 +129,8 @@ void test_before_tuple_size_specializati
 }
 
 template <>
-struct std::tuple_size {
+class std::tuple_size {
+public:
   static const size_t value = 1;
 };
 


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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

bruno wrote:
> bruno wrote:
> > rnk wrote:
> > > compnerd wrote:
> > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > I'd suggest this code:
> > >   IsSpecialLong = true;
> > >   // Use "long" if is 32 bits. This prefix is used by intrinsics that 
> > > need 32-bit types on LP64 platforms, but need to use "long" in the 
> > > prototype on LLP64 platforms like Win64.
> > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > HowLong = 1;
> > >   break;
> > See below.
> I tried something similar before, but I get two tests failing 
> CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion hits 
> the same failing tests. Both fails because of the Linux issue mentioned 
> above: i32 codegen where i64 is expected. Of course I could improve the 
> condition to handle Linux, but at that point I just thing it's better to use 
> Darwin, which is what the fix is towards anyway. Additional ideas?
I don't think we should sweep this under the rug just because there are some 
test failures. There is probably some latent bug worth investigating.


https://reviews.llvm.org/D34377



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


Re: r305850 - Preserve CXX method overrides in ASTImporter

2017-06-20 Thread Lang Hames via cfe-commits
Oops - this broke Sema/ms_class_layout.cpp. Looking in to it now...

- Lang.

On Tue, Jun 20, 2017 at 2:06 PM, Lang Hames via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: lhames
> Date: Tue Jun 20 16:06:00 2017
> New Revision: 305850
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305850&view=rev
> Log:
> Preserve CXX method overrides in ASTImporter
>
> Summary:
> The ASTImporter should import CXX method overrides from the source context
> when it imports a method decl.
>
> Reviewers: spyffe, rsmith, doug.gregor
>
> Reviewed By: spyffe
>
> Differential Revision: https://reviews.llvm.org/D34371
>
> Modified:
> cfe/trunk/lib/AST/ASTDumper.cpp
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/tools/clang-import-test/clang-import-test.cpp
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ASTDumper.cpp?rev=305850&r1=305849&r2=305850&view=diff
> 
> ==
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:06:00 2017
> @@ -1184,6 +1184,28 @@ void ASTDumper::VisitFunctionDecl(const
>   I != E; ++I)
>dumpCXXCtorInitializer(*I);
>
> +  if (const CXXMethodDecl *MD = dyn_cast(D))
> +if (MD->size_overridden_methods() != 0) {
> +  auto dumpOverride =
> +[=](const CXXMethodDecl *D) {
> +  SplitQualType T_split = D->getType().split();
> +  OS << D << " " << D->getParent()->getName() << "::"
> + << D->getName() << " '"
> + << QualType::getAsString(T_split) << "'";
> +};
> +
> +  dumpChild([=] {
> +auto FirstOverrideItr = MD->begin_overridden_methods();
> +OS << "Overrides: [ ";
> +dumpOverride(*FirstOverrideItr);
> +for (const auto *Override :
> +   llvm::make_range(FirstOverrideItr + 1,
> +MD->end_overridden_methods()))
> +  dumpOverride(Override);
> +OS << " ]";
> +  });
> +}
> +
>if (D->doesThisDeclarationHaveABody())
>  dumpStmt(D->getBody());
>  }
>
> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ASTImporter.cpp?rev=305850&r1=305849&r2=305850&view=diff
> 
> ==
> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> +++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jun 20 16:06:00 2017
> @@ -319,6 +319,9 @@ namespace clang {
>  bool ImportArrayChecked(const InContainerTy &InContainer, OIter
> Obegin) {
>return ImportArrayChecked(InContainer.begin(), InContainer.end(),
> Obegin);
>  }
> +
> +// Importing overrides.
> +void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl
> *FromMethod);
>};
>  }
>
> @@ -2025,6 +2028,9 @@ Decl *ASTNodeImporter::VisitFunctionDecl
>// Add this function to the lexical context.
>LexicalDC->addDeclInternal(ToFunction);
>
> +  if (auto *FromCXXMethod = dyn_cast(D))
> +ImportOverrides(cast(ToFunction), FromCXXMethod);
> +
>return ToFunction;
>  }
>
> @@ -5499,6 +5505,14 @@ Expr *ASTNodeImporter::VisitSubstNonType
>  Replacement);
>  }
>
> +void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
> +  CXXMethodDecl *FromMethod) {
> +  for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
> +ToMethod->addOverriddenMethod(
> +  cast(Importer.Import(const_cast(
> +FromOverriddenMethod;
> +}
> +
>  ASTImporter::ASTImporter(ASTContext &ToContext, FileManager
> &ToFileManager,
>   ASTContext &FromContext, FileManager
> &FromFileManager,
>   bool MinimalImport)
>
> Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-
> import-test/clang-import-test.cpp?rev=305850&r1=305849&r2=305850&view=diff
> 
> ==
> --- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
> +++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Tue Jun 20
> 16:06:00 2017
> @@ -17,7 +17,9 @@
>  #include "clang/Basic/TargetInfo.h"
>  #include "clang/Basic/TargetOptions.h"
>  #include "clang/CodeGen/ModuleBuilder.h"
> +#include "clang/Frontend/ASTConsumers.h"
>  #include "clang/Frontend/CompilerInstance.h"
> +#include "clang/Frontend/MultiplexConsumer.h"
>  #include "clang/Frontend/TextDiagnosticBuffer.h"
>  #include "clang/Lex/Lexer.h"
>  #include "clang/Lex/Preprocessor.h"
> @@ -51,6 +53,10 @@ static llvm::cl::list
>llvm::cl::desc("Argument to pass to the
> CompilerInvocation"),
>llvm::cl::CommaSeparated);
>
> +static llvm::cl::opt
> +DumpAST("dump-ast", llvm::cl::init(false),
> +llvm::cl::des

[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

majnemer wrote:
> bruno wrote:
> > bruno wrote:
> > > rnk wrote:
> > > > compnerd wrote:
> > > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > > I'd suggest this code:
> > > >   IsSpecialLong = true;
> > > >   // Use "long" if is 32 bits. This prefix is used by intrinsics that 
> > > > need 32-bit types on LP64 platforms, but need to use "long" in the 
> > > > prototype on LLP64 platforms like Win64.
> > > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > > HowLong = 1;
> > > >   break;
> > > See below.
> > I tried something similar before, but I get two tests failing 
> > CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion 
> > hits the same failing tests. Both fails because of the Linux issue 
> > mentioned above: i32 codegen where i64 is expected. Of course I could 
> > improve the condition to handle Linux, but at that point I just thing it's 
> > better to use Darwin, which is what the fix is towards anyway. Additional 
> > ideas?
> I don't think we should sweep this under the rug just because there are some 
> test failures. There is probably some latent bug worth investigating.
Well, there's specific testing for this behavior under Linux, so I assume 
someone needs this? I don't see how this is sweeping stuff under the rug.


https://reviews.llvm.org/D34377



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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

majnemer wrote:
> bruno wrote:
> > bruno wrote:
> > > rnk wrote:
> > > > compnerd wrote:
> > > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > > I'd suggest this code:
> > > >   IsSpecialLong = true;
> > > >   // Use "long" if is 32 bits. This prefix is used by intrinsics that 
> > > > need 32-bit types on LP64 platforms, but need to use "long" in the 
> > > > prototype on LLP64 platforms like Win64.
> > > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > > HowLong = 1;
> > > >   break;
> > > See below.
> > I tried something similar before, but I get two tests failing 
> > CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion 
> > hits the same failing tests. Both fails because of the Linux issue 
> > mentioned above: i32 codegen where i64 is expected. Of course I could 
> > improve the condition to handle Linux, but at that point I just thing it's 
> > better to use Darwin, which is what the fix is towards anyway. Additional 
> > ideas?
> I don't think we should sweep this under the rug just because there are some 
> test failures. There is probably some latent bug worth investigating.
I think I remember answer a question for Albert during his internship, and I 
said something like "they should stay longs", so he added those tests. Thinking 
about it now, those test should be changed to expect 32-bit ints.


https://reviews.llvm.org/D34377



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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

bruno wrote:
> rnk wrote:
> > majnemer wrote:
> > > bruno wrote:
> > > > bruno wrote:
> > > > > rnk wrote:
> > > > > > compnerd wrote:
> > > > > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > > > > I'd suggest this code:
> > > > > >   IsSpecialLong = true;
> > > > > >   // Use "long" if is 32 bits. This prefix is used by intrinsics 
> > > > > > that need 32-bit types on LP64 platforms, but need to use "long" in 
> > > > > > the prototype on LLP64 platforms like Win64.
> > > > > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > > > > HowLong = 1;
> > > > > >   break;
> > > > > See below.
> > > > I tried something similar before, but I get two tests failing 
> > > > CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your 
> > > > suggestion hits the same failing tests. Both fails because of the Linux 
> > > > issue mentioned above: i32 codegen where i64 is expected. Of course I 
> > > > could improve the condition to handle Linux, but at that point I just 
> > > > thing it's better to use Darwin, which is what the fix is towards 
> > > > anyway. Additional ideas?
> > > I don't think we should sweep this under the rug just because there are 
> > > some test failures. There is probably some latent bug worth investigating.
> > I think I remember answer a question for Albert during his internship, and 
> > I said something like "they should stay longs", so he added those tests. 
> > Thinking about it now, those test should be changed to expect 32-bit ints.
> Well, there's specific testing for this behavior under Linux, so I assume 
> someone needs this? I don't see how this is sweeping stuff under the rug.
---
Oh, I see. Gonna rework those then!


https://reviews.llvm.org/D34377



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


r305860 - Special-case handling of destructors in override lists when dumping ASTs.

2017-06-20 Thread Lang Hames via cfe-commits
Author: lhames
Date: Tue Jun 20 16:30:43 2017
New Revision: 305860

URL: http://llvm.org/viewvc/llvm-project?rev=305860&view=rev
Log:
Special-case handling of destructors in override lists when dumping ASTs.

Fixes a bug in r305850: CXXDestructors don't have names, so we need to handle
printing of them separately.


Modified:
cfe/trunk/lib/AST/ASTDumper.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=305860&r1=305859&r2=305860&view=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:30:43 2017
@@ -1189,9 +1189,12 @@ void ASTDumper::VisitFunctionDecl(const
   auto dumpOverride =
 [=](const CXXMethodDecl *D) {
   SplitQualType T_split = D->getType().split();
-  OS << D << " " << D->getParent()->getName() << "::"
- << D->getName() << " '"
- << QualType::getAsString(T_split) << "'";
+  OS << D << " " << D->getParent()->getName() << "::";
+  if (isa(D))
+OS << "~" << D->getParent()->getName();
+  else
+OS << D->getName();
+  OS << " '" << QualType::getAsString(T_split) << "'";
 };
 
   dumpChild([=] {


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


  1   2   >