Re: r334935 - [analyzer] Checker for uninitialized C++ objects

2018-06-18 Thread Mikael Holmén via cfe-commits

Hi Kristof,

Building without asserts (-DNDEBUG) I get the following warning/error 
with this commit:


[3082/3387] Building CXX object 
tools/clang/lib/StaticAnalyzer/Checkers...eFiles/clangStaticAnalyzerCheckers.dir/UninitializedObjectChecker.cpp.
FAILED: 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/clangStaticAnalyzerCheckers.dir/UninitializedObjectChecker.cpp.o 

/repo/app/clang/3.6/bin/clang++  -march=corei7  -DGTEST_HAS_RTTI=0 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -Itools/clang/lib/StaticAnalyzer/Checkers 
-I../tools/clang/lib/StaticAnalyzer/Checkers -I../tools/clang/include 
-Itools/clang/include -I/usr/include/libxml2 -Iinclude -I../include 
-I/repo/app/valgrind/3.11.0/include  -fPIC -fvisibility-inlines-hidden 
-Werror -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG-fno-exceptions -fno-rtti -MMD 
-MT 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/clangStaticAnalyzerCheckers.dir/UninitializedObjectChecker.cpp.o 
-MF 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/clangStaticAnalyzerCheckers.dir/UninitializedObjectChecker.cpp.o.d 
-o 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/clangStaticAnalyzerCheckers.dir/UninitializedObjectChecker.cpp.o 
-c ../tools/clang/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
../tools/clang/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:215:6: 
error: unused function 'isPrimitiveType' [-Werror,-Wunused-function]

bool isPrimitiveType(const QualType &T) {
 ^
1 error generated.

Regards,
Mikael

On 06/18/2018 01:50 PM, Kristof Umann via cfe-commits wrote:

Author: szelethus
Date: Mon Jun 18 04:50:17 2018
New Revision: 334935

URL: http://llvm.org/viewvc/llvm-project?rev=334935&view=rev
Log:
[analyzer] Checker for uninitialized C++ objects

This checker analyzes C++ constructor calls, and reports uninitialized fields.

Due to the nature of this problem (uninitialized fields after an object
construction), this checker doesn't search for bugs, but rather is a tool to
enforce a specific programming model where every field needs to be initialized.

This checker lands in alpha for now, and a number of followup patches will be
made to reduce false negatives and to make it easier for the user to understand
what rules the checker relies on, eg. whether a derived class' constructor is
responsible for initializing inherited data members or whether it should be
handled in the base class' constructor.

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

Added:
 cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
 
cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-cxx-uninitialized-object.h
 cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp
 cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
 cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp
Modified:
 cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
 cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=334935&r1=334934&r2=334935&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Mon Jun 18 
04:50:17 2018
@@ -319,6 +319,10 @@ def MisusedMovedObjectChecker: Checker<"
"object will be reported">,
   DescFile<"MisusedMovedObjectChecker.cpp">;
  
+def UninitializedObjectChecker: Checker<"UninitializedObject">,

+ HelpText<"Reports uninitialized fields after object construction">,
+ DescFile<"UninitializedObjectChecker.cpp">;
+
  } // end: "alpha.cplusplus"
  
  


Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=334935&r1=334934&r2=334935&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Mon Jun 18 04:50:17 
2018
@@ -92,6 +92,7 @@ add_clang_library(clangStaticAnalyzerChe
UndefResultChecker.cpp
UndefinedArraySubscriptChecker.cpp
UndefinedAssignmentChecker.cpp
+  UninitializedObjectChecker.cpp
UnixAPIChecker.cpp
UnreachableCodeChecker.cpp
VforkChecker.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/ll

r335022 - Revert r335019 "Update NRVO logic to support early return (Attempt 2)"

2018-06-18 Thread Taiju Tsuiki via cfe-commits
Author: tzik
Date: Mon Jun 18 22:35:30 2018
New Revision: 335022

URL: http://llvm.org/viewvc/llvm-project?rev=335022&view=rev
Log:
Revert r335019 "Update NRVO logic to support early return (Attempt 2)"

Removed:
cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp
cfe/trunk/test/SemaCXX/nrvo-ast.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Sema/Scope.h
cfe/trunk/lib/Sema/Scope.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenCXX/nrvo.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=335022&r1=335021&r2=335022&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Jun 18 22:35:30 2018
@@ -879,12 +879,6 @@ protected:
 DAK_Normal
   };
 
-  enum NRVOMode {
-NRVO_Candidate,
-NRVO_Disabled,
-NRVO_Enabled,
-  };
-
   class ParmVarDeclBitfields {
 friend class ASTDeclReader;
 friend class ParmVarDecl;
@@ -937,7 +931,7 @@ protected:
 /// Whether this local variable could be allocated in the return
 /// slot of its function, enabling the named return value optimization
 /// (NRVO).
-unsigned NRVOMode : 2;
+unsigned NRVOVariable : 1;
 
 /// Whether this variable is the for-range-declaration in a C++0x
 /// for-range statement.
@@ -1325,20 +1319,12 @@ public:
   /// return slot when returning from the function. Within the function body,
   /// each return that returns the NRVO object will have this variable as its
   /// NRVO candidate.
-  NRVOMode getNRVOMode() const {
-if (isa(this))
-  return NRVO_Disabled;
-return static_cast(NonParmVarDeclBits.NRVOMode);
-  }
-  bool isNRVOCandidate() const {
-return isa(this) ? false : NonParmVarDeclBits.NRVOMode == 
NRVO_Candidate;
-  }
   bool isNRVOVariable() const {
-return isa(this) ? false : NonParmVarDeclBits.NRVOMode == 
NRVO_Enabled;
+return isa(this) ? false : NonParmVarDeclBits.NRVOVariable;
   }
   void setNRVOVariable(bool NRVO) {
 assert(!isa(this));
-NonParmVarDeclBits.NRVOMode = NRVO ? NRVO_Enabled : NRVO_Disabled;
+NonParmVarDeclBits.NRVOVariable = NRVO;
   }
 
   /// Determine whether this variable is the for-range-declaration in

Modified: cfe/trunk/include/clang/Sema/Scope.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=335022&r1=335021&r2=335022&view=diff
==
--- cfe/trunk/include/clang/Sema/Scope.h (original)
+++ cfe/trunk/include/clang/Sema/Scope.h Mon Jun 18 22:35:30 2018
@@ -201,6 +201,10 @@ private:
   /// Used to determine if errors occurred in this scope.
   DiagnosticErrorTrap ErrorTrap;
 
+  /// A lattice consisting of undefined, a single NRVO candidate variable in
+  /// this scope, or over-defined. The bit is true when over-defined.
+  llvm::PointerIntPair NRVO;
+
   void setFlags(Scope *Parent, unsigned F);
 
 public:
@@ -462,7 +466,23 @@ public:
   UsingDirectives.end());
   }
 
-  void setNRVOCandidate(VarDecl *Candidate);
+  void addNRVOCandidate(VarDecl *VD) {
+if (NRVO.getInt())
+  return;
+if (NRVO.getPointer() == nullptr) {
+  NRVO.setPointer(VD);
+  return;
+}
+if (NRVO.getPointer() != VD)
+  setNoNRVO();
+  }
+
+  void setNoNRVO() {
+NRVO.setInt(true);
+NRVO.setPointer(nullptr);
+  }
+
+  void mergeNRVOIntoParent();
 
   /// Init - This is used by the parser to implement scope caching.
   void Init(Scope *parent, unsigned flags);

Modified: cfe/trunk/lib/Sema/Scope.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Scope.cpp?rev=335022&r1=335021&r2=335022&view=diff
==
--- cfe/trunk/lib/Sema/Scope.cpp (original)
+++ cfe/trunk/lib/Sema/Scope.cpp Mon Jun 18 22:35:30 2018
@@ -92,6 +92,7 @@ void Scope::Init(Scope *parent, unsigned
   UsingDirectives.clear();
   Entity = nullptr;
   ErrorTrap.reset();
+  NRVO.setPointerAndInt(nullptr, 0);
 }
 
 bool Scope::containedInPrototypeScope() const {
@@ -118,15 +119,19 @@ void Scope::AddFlags(unsigned FlagsToSet
   Flags |= FlagsToSet;
 }
 
-void Scope::setNRVOCandidate(VarDecl *Candidate) {
-  for (Decl *D : DeclsInScope) {
-VarDecl *VD = dyn_cast(D);
-if (VD && VD != Candidate && VD->isNRVOCandidate())
-  VD->setNRVOVariable(false);
+void Scope::mergeNRVOIntoParent() {
+  if (VarDecl *Candidate = NRVO.getPointer()) {
+if (isDeclScope(Candidate))
+  Candidate->setNRVOVariable(true);
   }
 
-  if (Scope *parent = getParent())
-parent->setNRVOC

r335021 - [Sema] Produce diagnostics for attribute 'trivial_abi' that appears

2018-06-18 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Jun 18 22:04:44 2018
New Revision: 335021

URL: http://llvm.org/viewvc/llvm-project?rev=335021&view=rev
Log:
[Sema] Produce diagnostics for attribute 'trivial_abi' that appears
after the closing brace of a class declaration.

Merge the two call sites of checkIllFormedTrivialABIStruct and sink it
into CheckCompletedCXXClass so that it is called after the attribute has
been attached to the CXXRecordDecl.

rdar://problem/40873297

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=335021&r1=335020&r2=335021&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jun 18 22:04:44 2018
@@ -6018,6 +6018,10 @@ void Sema::CheckCompletedCXXClass(CXXRec
 }
   }
 
+  // See if trivial_abi has to be dropped.
+  if (Record->hasAttr())
+checkIllFormedTrivialABIStruct(*Record);
+
   // Set HasTrivialSpecialMemberForCall if the record has attribute
   // "trivial_abi".
   bool HasTrivialABI = Record->hasAttr();
@@ -7810,17 +7814,12 @@ void Sema::ActOnFinishCXXMemberSpecifica
   l->getName();
   }
 
-  // See if trivial_abi has to be dropped.
-  auto *RD = dyn_cast(TagDecl);
-  if (RD && RD->hasAttr())
-checkIllFormedTrivialABIStruct(*RD);
-
   ActOnFields(S, RLoc, TagDecl, llvm::makeArrayRef(
   // strict aliasing violation!
   reinterpret_cast(FieldCollector->getCurFields()),
   FieldCollector->getCurNumFields()), LBrac, RBrac, AttrList);
 
-  CheckCompletedCXXClass(RD);
+  CheckCompletedCXXClass(dyn_cast_or_null(TagDecl));
 }
 
 /// AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=335021&r1=335020&r2=335021&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Jun 18 22:04:44 2018
@@ -2123,10 +2123,6 @@ Sema::InstantiateClass(SourceLocation Po
 }
   }
 
-  // See if trivial_abi has to be dropped.
-  if (Instantiation && Instantiation->hasAttr())
-checkIllFormedTrivialABIStruct(*Instantiation);
-
   // Finish checking fields.
   ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields,
   SourceLocation(), SourceLocation(), nullptr);

Modified: cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm?rev=335021&r1=335020&r2=335021&view=diff
==
--- cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm (original)
+++ cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm Mon Jun 18 22:04:44 2018
@@ -18,6 +18,10 @@ struct __attribute__((trivial_abi)) S3 {
   virtual void m();
 };
 
+struct S3_2 {
+  virtual void m();
+} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be 
applied to 'S3_2'}}
+
 struct S4 {
   int a;
 };


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


r335019 - Update NRVO logic to support early return (Attempt 2)

2018-06-18 Thread Taiju Tsuiki via cfe-commits
Author: tzik
Date: Mon Jun 18 21:39:07 2018
New Revision: 335019

URL: http://llvm.org/viewvc/llvm-project?rev=335019&view=rev
Log:
Update NRVO logic to support early return (Attempt 2)

Summary:
This is the second attempt of r333500 (Update NRVO logic to support early 
return).
The previous one was reverted for a miscompilation for an incorrect NRVO set up 
on templates such as:
```
struct Foo {};

template 
T bar() {
  T t;
  if (false)
return T();
  return t;
}
```

Where, `t` is marked as non-NRVO variable before its instantiation. However, 
while its instantiation, it's left an NRVO candidate, turned into an NRVO 
variable later.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeGenCXX/nrvo-noopt.cpp
cfe/trunk/test/SemaCXX/nrvo-ast.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Sema/Scope.h
cfe/trunk/lib/Sema/Scope.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenCXX/nrvo.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=335019&r1=335018&r2=335019&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Jun 18 21:39:07 2018
@@ -879,6 +879,12 @@ protected:
 DAK_Normal
   };
 
+  enum NRVOMode {
+NRVO_Candidate,
+NRVO_Disabled,
+NRVO_Enabled,
+  };
+
   class ParmVarDeclBitfields {
 friend class ASTDeclReader;
 friend class ParmVarDecl;
@@ -931,7 +937,7 @@ protected:
 /// Whether this local variable could be allocated in the return
 /// slot of its function, enabling the named return value optimization
 /// (NRVO).
-unsigned NRVOVariable : 1;
+unsigned NRVOMode : 2;
 
 /// Whether this variable is the for-range-declaration in a C++0x
 /// for-range statement.
@@ -1319,12 +1325,20 @@ public:
   /// return slot when returning from the function. Within the function body,
   /// each return that returns the NRVO object will have this variable as its
   /// NRVO candidate.
+  NRVOMode getNRVOMode() const {
+if (isa(this))
+  return NRVO_Disabled;
+return static_cast(NonParmVarDeclBits.NRVOMode);
+  }
+  bool isNRVOCandidate() const {
+return isa(this) ? false : NonParmVarDeclBits.NRVOMode == 
NRVO_Candidate;
+  }
   bool isNRVOVariable() const {
-return isa(this) ? false : NonParmVarDeclBits.NRVOVariable;
+return isa(this) ? false : NonParmVarDeclBits.NRVOMode == 
NRVO_Enabled;
   }
   void setNRVOVariable(bool NRVO) {
 assert(!isa(this));
-NonParmVarDeclBits.NRVOVariable = NRVO;
+NonParmVarDeclBits.NRVOMode = NRVO ? NRVO_Enabled : NRVO_Disabled;
   }
 
   /// Determine whether this variable is the for-range-declaration in

Modified: cfe/trunk/include/clang/Sema/Scope.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=335019&r1=335018&r2=335019&view=diff
==
--- cfe/trunk/include/clang/Sema/Scope.h (original)
+++ cfe/trunk/include/clang/Sema/Scope.h Mon Jun 18 21:39:07 2018
@@ -201,10 +201,6 @@ private:
   /// Used to determine if errors occurred in this scope.
   DiagnosticErrorTrap ErrorTrap;
 
-  /// A lattice consisting of undefined, a single NRVO candidate variable in
-  /// this scope, or over-defined. The bit is true when over-defined.
-  llvm::PointerIntPair NRVO;
-
   void setFlags(Scope *Parent, unsigned F);
 
 public:
@@ -466,23 +462,7 @@ public:
   UsingDirectives.end());
   }
 
-  void addNRVOCandidate(VarDecl *VD) {
-if (NRVO.getInt())
-  return;
-if (NRVO.getPointer() == nullptr) {
-  NRVO.setPointer(VD);
-  return;
-}
-if (NRVO.getPointer() != VD)
-  setNoNRVO();
-  }
-
-  void setNoNRVO() {
-NRVO.setInt(true);
-NRVO.setPointer(nullptr);
-  }
-
-  void mergeNRVOIntoParent();
+  void setNRVOCandidate(VarDecl *Candidate);
 
   /// Init - This is used by the parser to implement scope caching.
   void Init(Scope *parent, unsigned flags);

Modified: cfe/trunk/lib/Sema/Scope.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Scope.cpp?rev=335019&r1=335018&r2=335019&view=diff
==
--- cfe/trunk/lib/Sema/Scope.cpp (original)
+++ cfe/trunk/lib/Sema/Scope.cpp Mon Jun 18 21:39:07 2018
@@ -92,7 +92,6 @@ void Scope::Init(Scope *parent, unsigned
   UsingDirectives.clear();
   Entity = nullptr;
   ErrorTrap.reset();
-  NRVO.setPointerAndInt(nullptr, 0);
 }
 
 bool Scope

[PATCH] D47586: Update NRVO logic to support early return (Attempt 2)

2018-06-18 Thread Taiju Tsuiki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC335019: Update NRVO logic to support early return (Attempt 
2) (authored by tzik, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47586?vs=151847&id=151848#toc

Repository:
  rC Clang

https://reviews.llvm.org/D47586

Files:
  include/clang/AST/Decl.h
  include/clang/Sema/Scope.h
  lib/Sema/Scope.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/nrvo-noopt.cpp
  test/CodeGenCXX/nrvo.cpp
  test/SemaCXX/nrvo-ast.cpp

Index: include/clang/AST/Decl.h
===
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -879,6 +879,12 @@
 DAK_Normal
   };
 
+  enum NRVOMode {
+NRVO_Candidate,
+NRVO_Disabled,
+NRVO_Enabled,
+  };
+
   class ParmVarDeclBitfields {
 friend class ASTDeclReader;
 friend class ParmVarDecl;
@@ -931,7 +937,7 @@
 /// Whether this local variable could be allocated in the return
 /// slot of its function, enabling the named return value optimization
 /// (NRVO).
-unsigned NRVOVariable : 1;
+unsigned NRVOMode : 2;
 
 /// Whether this variable is the for-range-declaration in a C++0x
 /// for-range statement.
@@ -1319,12 +1325,20 @@
   /// return slot when returning from the function. Within the function body,
   /// each return that returns the NRVO object will have this variable as its
   /// NRVO candidate.
+  NRVOMode getNRVOMode() const {
+if (isa(this))
+  return NRVO_Disabled;
+return static_cast(NonParmVarDeclBits.NRVOMode);
+  }
+  bool isNRVOCandidate() const {
+return isa(this) ? false : NonParmVarDeclBits.NRVOMode == NRVO_Candidate;
+  }
   bool isNRVOVariable() const {
-return isa(this) ? false : NonParmVarDeclBits.NRVOVariable;
+return isa(this) ? false : NonParmVarDeclBits.NRVOMode == NRVO_Enabled;
   }
   void setNRVOVariable(bool NRVO) {
 assert(!isa(this));
-NonParmVarDeclBits.NRVOVariable = NRVO;
+NonParmVarDeclBits.NRVOMode = NRVO ? NRVO_Enabled : NRVO_Disabled;
   }
 
   /// Determine whether this variable is the for-range-declaration in
Index: include/clang/Sema/Scope.h
===
--- include/clang/Sema/Scope.h
+++ include/clang/Sema/Scope.h
@@ -201,10 +201,6 @@
   /// Used to determine if errors occurred in this scope.
   DiagnosticErrorTrap ErrorTrap;
 
-  /// A lattice consisting of undefined, a single NRVO candidate variable in
-  /// this scope, or over-defined. The bit is true when over-defined.
-  llvm::PointerIntPair NRVO;
-
   void setFlags(Scope *Parent, unsigned F);
 
 public:
@@ -466,23 +462,7 @@
   UsingDirectives.end());
   }
 
-  void addNRVOCandidate(VarDecl *VD) {
-if (NRVO.getInt())
-  return;
-if (NRVO.getPointer() == nullptr) {
-  NRVO.setPointer(VD);
-  return;
-}
-if (NRVO.getPointer() != VD)
-  setNoNRVO();
-  }
-
-  void setNoNRVO() {
-NRVO.setInt(true);
-NRVO.setPointer(nullptr);
-  }
-
-  void mergeNRVOIntoParent();
+  void setNRVOCandidate(VarDecl *Candidate);
 
   /// Init - This is used by the parser to implement scope caching.
   void Init(Scope *parent, unsigned flags);
Index: test/SemaCXX/nrvo-ast.cpp
===
--- test/SemaCXX/nrvo-ast.cpp
+++ test/SemaCXX/nrvo-ast.cpp
@@ -0,0 +1,153 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -ast-dump -o - %s | FileCheck %s
+
+struct X {
+  X();
+  X(const X&);
+  X(X&&);
+};
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_00
+X test_00() {
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_01
+X test_01(bool b) {
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  if (b)
+return x;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_02
+X test_02(bool b) {
+  // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  // CHECK-NOT: VarDecl {{.*}} y {{.*}} nrvo
+  X y;
+  if (b)
+return y;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_03
+X test_03(bool b) {
+  if (b) {
+// CHECK: VarDecl {{.*}} y {{.*}} nrvo
+X y;
+return y;
+  }
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  return x;
+}
+
+extern "C" _Noreturn void exit(int) throw();
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_04
+X test_04(bool b) {
+  {
+// CHECK: VarDecl {{.*}} x {{.*}} nrvo
+X x;
+if (b)
+  return x;
+  }
+  exit(1);
+}
+
+void may_throw();
+// CHECK-LABEL: FunctionDecl {{.*}} test_05
+X test_05() {
+  try {
+may_throw();
+return X();
+  } catch (X x) {
+// CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+return x;
+  }
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_06
+X test_06() {
+  // CHECK-NOT

[PATCH] D47586: Update NRVO logic to support early return (Attempt 2)

2018-06-18 Thread Taiju Tsuiki via Phabricator via cfe-commits
tzik added inline comments.



Comment at: test/CodeGenCXX/nrvo-noopt.cpp:1
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+

rsmith wrote:
> You don't need the `-O0` here; that's the default.
Thanks! Done.


Repository:
  rC Clang

https://reviews.llvm.org/D47586



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


[PATCH] D47586: Update NRVO logic to support early return (Attempt 2)

2018-06-18 Thread Taiju Tsuiki via Phabricator via cfe-commits
tzik updated this revision to Diff 151847.
tzik marked an inline comment as done.
tzik added a comment.

drop an unneeded -O0


Repository:
  rC Clang

https://reviews.llvm.org/D47586

Files:
  include/clang/AST/Decl.h
  include/clang/Sema/Scope.h
  lib/Sema/Scope.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/nrvo-noopt.cpp
  test/CodeGenCXX/nrvo.cpp
  test/SemaCXX/nrvo-ast.cpp

Index: test/SemaCXX/nrvo-ast.cpp
===
--- /dev/null
+++ test/SemaCXX/nrvo-ast.cpp
@@ -0,0 +1,153 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -ast-dump -o - %s | FileCheck %s
+
+struct X {
+  X();
+  X(const X&);
+  X(X&&);
+};
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_00
+X test_00() {
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_01
+X test_01(bool b) {
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  if (b)
+return x;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_02
+X test_02(bool b) {
+  // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  // CHECK-NOT: VarDecl {{.*}} y {{.*}} nrvo
+  X y;
+  if (b)
+return y;
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_03
+X test_03(bool b) {
+  if (b) {
+// CHECK: VarDecl {{.*}} y {{.*}} nrvo
+X y;
+return y;
+  }
+  // CHECK: VarDecl {{.*}} x {{.*}} nrvo
+  X x;
+  return x;
+}
+
+extern "C" _Noreturn void exit(int) throw();
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_04
+X test_04(bool b) {
+  {
+// CHECK: VarDecl {{.*}} x {{.*}} nrvo
+X x;
+if (b)
+  return x;
+  }
+  exit(1);
+}
+
+void may_throw();
+// CHECK-LABEL: FunctionDecl {{.*}} test_05
+X test_05() {
+  try {
+may_throw();
+return X();
+  } catch (X x) {
+// CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+return x;
+  }
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_06
+X test_06() {
+  // CHECK-NOT: VarDecl {{.*}} x {{.*}} nrvo
+  X x __attribute__((aligned(8)));
+  return x;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_07
+X test_07(bool b) {
+  if (b) {
+// CHECK: VarDecl {{.*}} x {{.*}} nrvo
+X x;
+return x;
+  }
+  return X();
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_08
+X test_08(bool b) {
+  if (b) {
+// CHECK: VarDecl {{.*}} x {{.*}} nrvo
+X x;
+return x;
+  } else {
+// CHECK: VarDecl {{.*}} y {{.*}} nrvo
+X y;
+return y;
+  }
+}
+
+template 
+struct Y {
+  Y();
+  // CHECK-LABEL: CXXMethodDecl {{.*}} test_09 'Y ()'
+  // CHECK: VarDecl {{.*}} y 'Y' nrvo
+
+  // CHECK-LABEL: CXXMethodDecl {{.*}} test_09 'Y ()'
+  // CHECK: VarDecl {{.*}} y 'Y' nrvo
+  static Y test_09() {
+Y y;
+return y;
+  }
+};
+
+struct Z {
+  Z(const X&);
+};
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_10 'A ()'
+// CHECK: VarDecl {{.*}} b 'B' nrvo
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_10 'X ()'
+// CHECK: VarDecl {{.*}} b {{.*}} nrvo
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_10 'Z ()'
+// CHECK-NOT: VarDecl {{.*}} b {{.*}} nrvo
+template 
+A test_10() {
+  B b;
+  return b;
+}
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_11 'A (bool)'
+// CHECK-NOT: VarDecl {{.*}} a {{.*}} nrvo
+
+// CHECK-LABEL: FunctionDecl {{.*}} test_11 'X (bool)'
+// CHECK-NOT: VarDecl {{.*}} a {{.*}} nrvo
+template 
+A test_11(bool b) {
+  A a;
+  if (b)
+return A();
+  return a;
+}
+
+void instantiate() {
+  Y::test_09();
+  test_10();
+  test_10();
+  test_11(true);
+}
Index: test/CodeGenCXX/nrvo.cpp
===
--- test/CodeGenCXX/nrvo.cpp
+++ test/CodeGenCXX/nrvo.cpp
@@ -130,17 +130,13 @@
 }
 
 // CHECK-LABEL: define void @_Z5test3b
-X test3(bool B) {
+X test3(bool B, X x) {
   // CHECK: tail call {{.*}} @_ZN1XC1Ev
-  // CHECK-NOT: call {{.*}} @_ZN1XC1ERKS_
-  // CHECK: call {{.*}} @_ZN1XC1Ev
-  // CHECK: call {{.*}} @_ZN1XC1ERKS_
   if (B) {
 X y;
 return y;
   }
-  // FIXME: we should NRVO this variable too.
-  X x;
+  // CHECK: tail call {{.*}} @_ZN1XC1ERKS_
   return x;
 }
 
@@ -191,21 +187,29 @@
 }
 
 // CHECK-LABEL: define void @_Z5test7b
+// CHECK-EH-LABEL: define void @_Z5test7b
 X test7(bool b) {
   // CHECK: tail call {{.*}} @_ZN1XC1Ev
   // CHECK-NEXT: ret
+
+  // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev
+  // CHECK-EH-NEXT: ret
   if (b) {
 X x;
 return x;
   }
   return X();
 }
 
 // CHECK-LABEL: define void @_Z5test8b
+// CHECK-EH-LABEL: define void @_Z5test8b
 X test8(bool b) {
   // CHECK: tail call {{.*}} @_ZN1XC1Ev
   // CHECK-NEXT: ret
-  if (b) {
+
+  // CHECK-EH: tail call {{.*}} @_ZN1XC1Ev
+  // CHECK-EH-NEXT: ret
+if (b) {
 X x;
 return x;
   } else {
@@ -221,4 +225,37 @@
 // CHECK-LABEL: define linkonce_odr void @_ZN1YIiE1fEv
 // CHECK: tail call {{.*}} @_ZN1YIiEC1Ev
 
+// CHECK-LABEL: define void @_Z6test10b
+X test10(bool B, X x) {

[PATCH] D48296: clang-cl: Emit normal narrowing diagnostics for initializer lists if -fmsc-version is at least 1900 (i.e. MSVC2015).

2018-06-18 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 151844.
thakis marked 2 inline comments as done.
thakis added a comment.

comments


https://reviews.llvm.org/D48296

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/ms-initlist-narrowing.cpp


Index: clang/test/SemaCXX/ms-initlist-narrowing.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-initlist-narrowing.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions 
-fms-compatibility-version=19.0 -std=c++11
+
+int ai[] = { 1, 2.0 };  // expected-error {{type 'double' cannot be narrowed 
to 'int' in initializer list}} expected-note {{silence}}
+
+template
+struct Agg {
+  T t;
+};
+
+void f(int i) {
+  // Constant expression.
+  Agg f8 = {1E50};  // expected-error {{constant expression evaluates 
to 1.00e+50 which cannot be narrowed to type 'float'}} expected-note 
{{silence}}
+
+  // Non-constant expression.
+  double d = 1.0;
+  Agg f2 = {d};  // expected-error {{non-constant-expression cannot be 
narrowed from type 'double' to 'float'}} expected-note {{silence}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8331,6 +8331,11 @@
   dump(llvm::errs());
 }
 
+static bool NarrowingErrs(const LangOptions &L) {
+  return L.CPlusPlus11 &&
+ (!L.MicrosoftExt || L.isCompatibleWithMSVC(LangOptions::MSVC2015));
+}
+
 static void DiagnoseNarrowingInInitList(Sema &S,
 const ImplicitConversionSequence &ICS,
 QualType PreNarrowingType,
@@ -8364,35 +8369,34 @@
 // This was a floating-to-integer conversion, which is always considered a
 // narrowing conversion even if the value is a constant and can be
 // represented exactly as an integer.
-S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_type_narrowing
-   : diag::ext_init_list_type_narrowing)
-  << PostInit->getSourceRange()
-  << PreNarrowingType.getLocalUnqualifiedType()
-  << EntityType.getLocalUnqualifiedType();
+S.Diag(PostInit->getLocStart(), NarrowingErrs(S.getLangOpts())
+? diag::ext_init_list_type_narrowing
+: diag::warn_init_list_type_narrowing)
+<< PostInit->getSourceRange()
+<< PreNarrowingType.getLocalUnqualifiedType()
+<< EntityType.getLocalUnqualifiedType();
 break;
 
   case NK_Constant_Narrowing:
 // A constant value was narrowed.
 S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_constant_narrowing
-   : diag::ext_init_list_constant_narrowing)
-  << PostInit->getSourceRange()
-  << ConstantValue.getAsString(S.getASTContext(), ConstantType)
-  << EntityType.getLocalUnqualifiedType();
+   NarrowingErrs(S.getLangOpts())
+   ? diag::ext_init_list_constant_narrowing
+   : diag::warn_init_list_constant_narrowing)
+<< PostInit->getSourceRange()
+<< ConstantValue.getAsString(S.getASTContext(), ConstantType)
+<< EntityType.getLocalUnqualifiedType();
 break;
 
   case NK_Variable_Narrowing:
 // A variable's value may have been narrowed.
 S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_variable_narrowing
-   : diag::ext_init_list_variable_narrowing)
-  << PostInit->getSourceRange()
-  << PreNarrowingType.getLocalUnqualifiedType()
-  << EntityType.getLocalUnqualifiedType();
+   NarrowingErrs(S.getLangOpts())
+   ? diag::ext_init_list_variable_narrowing
+   : diag::warn_init_list_variable_narrowing)
+<< PostInit->getSourceRange()
+<< PreNarrowingType.getLocalUnqualifiedType()
+<< EntityType.getLocalUnqualifiedType();
 break;
   }
 


Index: clang/test/SemaCXX/ms-initlist-narrowing.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-initlist-narrowing.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -fms-compatibility-version=19.0 -std=c++11
+
+int ai[] = { 1, 2.0 };  // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
+
+template
+struct Agg {
+  T t;
+};
+
+void f(int i) {
+  // Constant expression.
+  Agg f8 = {1E50};  // expected-error {{constant expression evaluates to 1.00e+50 which cannot be narrowed to type 'float'}} expected-note {{silence}}
+
+  // Non-constant expression.
+  double d = 1.0;
+  Agg f2 = {d};  // expected-error {{non-constant

[PATCH] D48296: clang-cl: Emit normal narrowing diagnostics for initializer lists if -fmsc-version is at least 1900 (i.e. MSVC2015).

2018-06-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks! I'd keep it DefaultIgnored: I'd be annoyed if I'd get these by default 
in C++98 mode.


https://reviews.llvm.org/D48296



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


[PATCH] D47344: LWG 2843 "Unclear behavior of std::pmr::memory_resource::do_allocate()"

2018-06-18 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@EricWF ping; is this a reasonable solution to LWG 2843 on platforms without 
aligned new and delete?


Repository:
  rCXX libc++

https://reviews.llvm.org/D47344



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


[PATCH] D48285: [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag

2018-06-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Also, great, and can i has tests?^^

Like a simple code snippet with two `// RUN: ... -analyzer-output=text` lines 
and different expected-warnings/notes under `#if`s.


Repository:
  rC Clang

https://reviews.llvm.org/D48285



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


[PATCH] D47358: : Implement {un, }synchronized_pool_resource.

2018-06-18 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone planned changes to this revision.
Quuxplusone added inline comments.



Comment at: src/experimental/memory_resource.cpp:240
+bool allocation_contains(const char *p) const {
+// TODO: This part technically relies on undefined behavior.
+return allocation <= p && p < ((char*)allocation + bytes);

I now see how to avoid doing this: instead of keeping a separate free-list per 
each chunk, I should keep one big free-list per pool, where blocks from all 
chunks in the same pool are mixed together. This is okay because we never 
deallocate one chunk unless we're deallocating *all* chunks.
I'll rework the patch to eliminate this undefined behavior and keep a free-list 
per pool.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47358



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


[PATCH] D48285: [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag

2018-06-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:696
 void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
   auto Chk = Mgr.registerChecker();
   Chk->IsPedantic = Mgr.getAnalyzerOptions().getBooleanOption(

george.karpenkov wrote:
> registerChecker passes through arguments to the constructor. Could we use 
> that instead of mutable fields?
Really? Yay. I never noticed that. I think currently all checkers that need 
options use mutable fields for that purpose, and everybody thought it was 
intended to work this way.

I'm not super worried about fields being mutable because all checker callbacks 
are `const` (so you're still protected from mutating them in all of your code), 
but that'd definitely make the code look better.


Repository:
  rC Clang

https://reviews.llvm.org/D48285



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


[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-06-18 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris added a comment.

I'm really excited by this clang-tidy check and I think it's worth having. I do 
think there's more work needed to bring it up to a level of quality that would 
be helpful to more users.




Comment at: docs/clang-tidy/checks/bugprone-exception-escape.rst:6
+
+Finds functions which may throw an excpetion directly or indirectly, but they
+should not. The functions which should not throw exceptions are the following:

excpetion -> exception



Comment at: test/clang-tidy/bugprone-exception-escape.cpp:178
+void indirect_implicit() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'indirect_implicit' which should not throw exceptions
+  implicit_int_thrower();

Can we make the warning more accurate here? Something like:

```
warning: call to 'implicit_int_thrower' may throw an exception and propagate 
through noexcept function 'indirect_implicit'
```

It would be helpful to diagnose the point at which the exception may be thrown 
from within the function (if it's an operator, a function call, etc.) that 
doesn't have exceptions handled. If you can highlight not just the line number 
but the actual expression in which the uncaught exception may propagate, it 
would make this warning much better.

If you think it's worth it (or if it's feasible), having a FixIt hint to wrap a 
block of statements where exceptions may propagate in a `try { ... } catch 
(...) { ... }` block would turn this warning from a good warning, to a great 
warning -- potentially something that could be automatically applied by a tool 
as well.


https://reviews.llvm.org/D33537



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


[PATCH] D48106: implemented proto to llvm

2018-06-18 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse requested changes to this revision.
morehouse added inline comments.
This revision now requires changes to proceed.



Comment at: tools/clang-fuzzer/CMakeLists.txt:72
 
+  # Build the lllvm protobuf fuzzer
+  add_clang_executable(clang-llvm-proto-fuzzer

llvm



Comment at: tools/clang-fuzzer/CMakeLists.txt:83
 clangFuzzerInitialize
 clangHandleCXX
 )

Maybe remove `clangHandleCXX` here, so you can use this variable for linking 
`clang-llvm-proto-fuzzer`.



Comment at: tools/clang-fuzzer/handle-llvm/CMakeLists.txt:5
+  handle_llvm.cpp
+  )

There's fewer libraries linked here than in `handle-cxx/` (not saying this is 
wrong, but it could be).  Do you get link errors if you build 
`clang-llvm-proto-fuzzer` with shared libraries?



Comment at: tools/clang-fuzzer/handle-llvm/\:31
+#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Support/raw_ostream.h"
+

Please sort includes alphabetically, with handle_llvm.h separate at the top.



Comment at: tools/clang-fuzzer/handle-llvm/\:42
+void InitializeEverything() {
+
+  InitializeAllTargets();

Nit:  avoid empty lines at beginning or end of a `{}` block (here and below)



Comment at: tools/clang-fuzzer/handle-llvm/\:62
+  initializeScavengerTestPass(*Registry);
+
+}

Does this initialization need to happen every time the fuzzer generates a new 
input, or can we call this from `LLVMFuzzerInitialize()` instead?



Comment at: tools/clang-fuzzer/handle-llvm/\:71
+  StringRef *ID = new StringRef("IR");
+  MemoryBufferRef *ir = new MemoryBufferRef(*IRString, *ID);
+

# Avoid using `new` when you could create the object on the stack instead.  
This will prevent you from introducing memory leaks if you forget to call 
`delete` later.
# I don't think you need to construct StringRefs or the MemoryBufferRef here.  
Instead you can probably do `parseIR(MemoryBufferRef(S, "IR"), Err, ...)` below.



Comment at: tools/clang-fuzzer/handle-llvm/\:79
+  SMDiagnostic Err;
+  std::unique_ptr M;
+  Triple TheTriple;

I'd move the `unique_ptr` definition to the same line as `parseIR`.



Comment at: tools/clang-fuzzer/handle-llvm/\:81
+  Triple TheTriple;
+  TheTriple.setTriple(sys::getDefaultTargetTriple());
+

What's the point of wrapping `sys::getDefaultTargetTriple()` if we always 
unwrap `TheTriple` below?



Comment at: tools/clang-fuzzer/handle-llvm/\:84
+  // Set the Module to include the the IR code to be compiled
+  M = parseIR(*ir, Err, Context, false);
+

What does `UpgradeDebugInfo=false` do here?  The documentation warns about 
setting this bool to false.



Comment at: tools/clang-fuzzer/handle-llvm/\:84
+  // Set the Module to include the the IR code to be compiled
+  M = parseIR(*ir, Err, Context, false);
+

morehouse wrote:
> What does `UpgradeDebugInfo=false` do here?  The documentation warns about 
> setting this bool to false.
What if `parseIR` returns nullptr?



Comment at: tools/clang-fuzzer/handle-llvm/\:88
+  std::string Error;
+  const Target *TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(),
+ Error);

What if `lookupTarget` returns nullptr?



Comment at: tools/clang-fuzzer/handle-llvm/\:90
+ Error);
+  std::string CPUStr = getCPUStr(), FeaturesStr = getFeaturesStr();
+

Please separate to 2 statements.



Comment at: tools/clang-fuzzer/handle-llvm/\:98
+  switch(A[2]) {  
+   case '0': OLvl = CodeGenOpt::None; break;
+case '1': OLvl = CodeGenOpt::Less; break;

Fix indentation here.



Comment at: tools/clang-fuzzer/handle-llvm/\:101
+case '2': OLvl = CodeGenOpt::Default; break;
+case '3': OLvl = CodeGenOpt::Aggressive; break;
+  }

Maybe add a default case here with an error message?



Comment at: tools/clang-fuzzer/handle-llvm/\:104
+}
+  }
+

It might make sense to move command line arg parsing to a helper function, and 
then call that function closer to the top.  That way if there's a bad argument 
we can quit before doing all the IR parsing.



Comment at: tools/clang-fuzzer/handle-llvm/\:113
+
+  legacy::PassManager PM;
+  TargetLibraryInfoImpl TLII(Triple(M->getTargetTriple()));

Any reason not to use the newer PassManager?



Comment at: tools/clang-fuzzer/handle-llvm/\:127
+
+  LLVMTargetMachine &LLVMTM = static_cast(*Target);
+  MachineModuleInfo *MMI = new MachineModuleInfo(&LLVMTM);
--

[PATCH] D47988: [CodeGen] Emit MSVC funclet IR for Obj-C exceptions

2018-06-18 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D47988#1135929, @rnk wrote:

> In https://reviews.llvm.org/D47988#1135533, @rjmccall wrote:
>
> > In general, it's unfortunate that this has to leave so many 
> > C++-runtime-specific tendrils in the ObjC code.  Unlike the EH type patch, 
> > though, I'm not sure I can see a great alternative here, especially because 
> > of the semantic restrictions required by outlining.
>
>
> It's technically possible to lift those restrictions by returning an i32 from 
> the outlined function and switching on it. Right? The question is, is it 
> worth it? The catch funclet would effectively store the i32 to the stack 
> frame, then "catchret" via the runtime, and then we'd switch out to the jump 
> target.


I don't think it's important.  Uses of control flow out of `@finally` are rare, 
and we could probably forbid it entirely without significant loss.


Repository:
  rC Clang

https://reviews.llvm.org/D47988



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


Buildbot numbers for the week of 6/10/2018 - 6/16/2018

2018-06-18 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the last week of 6/10/2018 - 6/16/2018.

Please see the same data in attached csv files:

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

Thanks

Galina


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

Buildbot numbers for the week of 5/27/2018 - 6/2/2018

2018-06-18 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 5/27/2018 - 6/2/2018.

Please see the same data in attached csv files:

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

Thanks

Galina


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

Buildbot numbers for the week of 6/3/2018 - 6/9/2018

2018-06-18 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 6/3/2018 - 6/9/2018.

Please see the same data in attached csv files:

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

Thanks

Galina


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

[PATCH] D47988: [CodeGen] Emit MSVC funclet IR for Obj-C exceptions

2018-06-18 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D47988#1135533, @rjmccall wrote:

> In general, it's unfortunate that this has to leave so many 
> C++-runtime-specific tendrils in the ObjC code.  Unlike the EH type patch, 
> though, I'm not sure I can see a great alternative here, especially because 
> of the semantic restrictions required by outlining.


It's technically possible to lift those restrictions by returning an i32 from 
the outlined function and switching on it. Right? The question is, is it worth 
it? The catch funclet would effectively store the i32 to the stack frame, then 
"catchret" via the runtime, and then we'd switch out to the jump target.


Repository:
  rC Clang

https://reviews.llvm.org/D47988



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


[PATCH] D44788: Add an option to support debug fission on implicit ThinLTO.

2018-06-18 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added inline comments.



Comment at: lib/Driver/ToolChains/CommonArgs.cpp:423
+llvm::sys::path::native(Dwo_Dir, DwoDir);
+llvm::sys::path::append(DwoDir, Twine(Output.getFilename()) + "_dwo");
+CmdArgs.push_back(

I think that if I pass `-gsplit-dwarf=/path/to/foo` I would expect the dwo 
directory to be named `/path/to/foo`, not `/path/to/foo/something_dwo`.



Comment at: lib/Driver/ToolChains/CommonArgs.cpp:428
+
+  if (Args.hasArg(options::OPT_gsplit_dwarf)) {
+if (!Args.getLastArg(options::OPT_gsplit_dwarf_EQ)) {

If you make this `else if (Args.hasArg(options::OPT_gsplit_dwarf)) {` you 
wouldn't need the if on line 429.


https://reviews.llvm.org/D44788



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


[PATCH] D47341: [Sema] Fix infinite typo correction loop.

2018-06-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping.


https://reviews.llvm.org/D47341



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


[PATCH] D48106: implemented proto to llvm

2018-06-18 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 151801.
emmettneyman added a comment.

- removed unnecessary includes and linked libs


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLLVMProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  tools/clang-fuzzer/handle-llvm/\
  tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  tools/clang-fuzzer/handle-llvm/handle_llvm.h
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,159 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::string BinopToString(std::ostream &os, const BinaryOp &x);
+std::string StateSeqToString(std::ostream &os, const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+std::string get_var() {
+  static int ctr = 0;
+  return "%var" + std::to_string(ctr++);
+}
+
+// Proto to LLVM.
+
+std::string ConstToString(const Const &x) {
+  return std::to_string(x.val());
+}
+std::string VarRefToString(std::ostream &os, const VarRef &x) {
+  std::string arr;
+  switch(x.arr()) {
+  case VarRef::ARR_A:
+arr = "%a";
+break;
+  case VarRef::ARR_B:
+arr = "%b";
+break;
+

[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: lib/Frontend/InitHeaderSearch.cpp:374-377
+  IsBaseFound = AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
+"powerpc-apple-darwin10", "",
+"ppc64", triple);
+  IsBaseFound &= AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",

Why are you using `&=` here instead of `|=`? I haven't tested but I expect that 
either 4.2.1 will work or 4.0.0, you don't need both of them.



Comment at: lib/Frontend/InitHeaderSearch.cpp:404
 }
+if (!IsBaseFound && !LangOpts.CUDA)
+  Headers.getDiags().Report(SourceLocation(),

What is so special about CUDA? Is it OK to emit the warning for OpenCL, for 
instance?



Comment at: test/Frontend/warning-stdlibcxx-darwin.cpp:1-2
+// RUN: %clang -cc1 -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist %s 
2>&1 | FileCheck %s
+// CHECK: include path for stdlibc++ headers not found; pass '-std=libc++' on 
the command line to use the libc++ standard library instead

Do you think there is a value in adding a test that does exactly what the 
warning suggests and verifies there are no warnings?


Repository:
  rC Clang

https://reviews.llvm.org/D48297



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


[PATCH] D48106: implemented proto to llvm

2018-06-18 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 151798.
emmettneyman added a comment.

Implemented HandleLLVM fuzz target

  -HandleLLVM function compiles LLVM IR
  -ExampleClangLLVMProtoFuzzer wraps the fuzz target
  -Next step is to compile at different opt levels and run the executables


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLLVMProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  tools/clang-fuzzer/handle-llvm/\
  tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  tools/clang-fuzzer/handle-llvm/handle_llvm.h
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,159 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::string BinopToString(std::ostream &os, const BinaryOp &x);
+std::string StateSeqToString(std::ostream &os, const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+std::string get_var() {
+  static int ctr = 0;
+  return "%var" + std::to_string(ctr++);
+}
+
+// Proto to LLVM.
+
+std::string ConstToString(const Const &x) {
+  return std::to_string(x.val());
+}
+std::string VarRefToString(std::ostream &os, const Va

[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-18 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Frontend/InitHeaderSearch.cpp:491
 } else {
-  AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
+  AddDefaultCPlusPlusIncludePaths(Lang, triple, HSOpts);
 }

bruno wrote:
> If we happen to suggest libc++, but it's also not there, do we still want the 
> warning? Should we check it exists first? 
I don't think such a check is that valuable on Darwin, which is where this 
warning fires, since libc++ is the default standard library on Darwin.


Repository:
  rC Clang

https://reviews.llvm.org/D48297



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


[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-18 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: lib/Frontend/InitHeaderSearch.cpp:491
 } else {
-  AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
+  AddDefaultCPlusPlusIncludePaths(Lang, triple, HSOpts);
 }

If we happen to suggest libc++, but it's also not there, do we still want the 
warning? Should we check it exists first? 


Repository:
  rC Clang

https://reviews.llvm.org/D48297



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


[PATCH] D48296: clang-cl: Emit normal narrowing diagnostics for initializer lists if -fmsc-version is at least 1900 (i.e. MSVC2015).

2018-06-18 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Do you think we should go ahead and remove the `DefaultIgnore` on these 
warnings as well? At this point, approximately nobody will see them.




Comment at: clang/lib/Sema/SemaInit.cpp:8367-8370
+bool DiagErr =
+S.getLangOpts().CPlusPlus11 &&
+(!S.getLangOpts().MicrosoftExt ||
+ S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015));

Can you hoist this out of the switch or put it in a helper, maybe with a name 
like [Ii]sNarrowingAnError



Comment at: clang/lib/Sema/SemaInit.cpp:8377
+<< EntityType.getLocalUnqualifiedType();
+  } break;
+

I'd put the break inside the brace if you still need it after this.


https://reviews.llvm.org/D48296



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


[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-18 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: bruno, vsapsai.

Xcode 10 removes support for libstdc++, but the users just get a confusing 
include not file warning when including an STL header (when building for iOS6 
which uses libstdc++ by default for example).
This patch adds a new warning that lets the user know that the libstdc++ 
include path was not found to ensure that the user is more aware of why the 
error occurs.

rdar://40830462


Repository:
  rC Clang

https://reviews.llvm.org/D48297

Files:
  include/clang/Basic/DiagnosticFrontendKinds.td
  include/clang/Lex/HeaderSearch.h
  lib/Frontend/InitHeaderSearch.cpp
  test/Frontend/warning-stdlibcxx-darwin.cpp

Index: test/Frontend/warning-stdlibcxx-darwin.cpp
===
--- /dev/null
+++ test/Frontend/warning-stdlibcxx-darwin.cpp
@@ -0,0 +1,2 @@
+// RUN: %clang -cc1 -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist %s 2>&1 | FileCheck %s
+// CHECK: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead
Index: lib/Frontend/InitHeaderSearch.cpp
===
--- lib/Frontend/InitHeaderSearch.cpp
+++ lib/Frontend/InitHeaderSearch.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
+#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -55,11 +56,13 @@
 
   /// AddPath - Add the specified path to the specified group list, prefixing
   /// the sysroot if used.
-  void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
 
   /// AddUnmappedPath - Add the specified path to the specified group list,
   /// without performing any sysroot remapping.
-  void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework);
 
   /// AddSystemHeaderPrefix - Add the specified prefix to the system header
@@ -70,10 +73,9 @@
 
   /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
   ///  libstdc++.
-  void AddGnuCPlusPlusIncludePaths(StringRef Base,
-   StringRef ArchDir,
-   StringRef Dir32,
-   StringRef Dir64,
+  /// Returns true if the \p Base path was found, false if it does not exist.
+  bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir,
+   StringRef Dir32, StringRef Dir64,
const llvm::Triple &triple);
 
   /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
@@ -88,7 +90,8 @@
 
   // AddDefaultCPlusPlusIncludePaths -  Add paths that should be searched when
   //  compiling c++.
-  void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
+  void AddDefaultCPlusPlusIncludePaths(const LangOptions &LangOpts,
+   const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts);
 
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
@@ -112,23 +115,22 @@
 #endif
 }
 
-void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
+bool InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework) {
   // Add the path with sysroot prepended, if desired and this is a system header
   // group.
   if (HasSysroot) {
 SmallString<256> MappedPathStorage;
 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
 if (CanPrefixSysroot(MappedPathStr)) {
-  AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
-  return;
+  return AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
 }
   }
 
-  AddUnmappedPath(Path, Group, isFramework);
+  return AddUnmappedPath(Path, Group, isFramework);
 }
 
-void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework) {
   assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
 
@@ -150,7 +152,7 @@
   if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
 IncludePath.push_back(
   std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
-return;
+return true;
   }
 
   // Check to see if this is an apple-style headermap (which are not allowed to
@@ -162,23 +164,24 @@
 

[PATCH] D48206: IRgen: Mark aliases of ctors and dtors as unnamed_addr.

2018-06-18 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334982: IRgen: Mark aliases of ctors and dtors as 
unnamed_addr. (authored by pcc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48206?vs=151455&id=151787#toc

Repository:
  rC Clang

https://reviews.llvm.org/D48206

Files:
  lib/CodeGen/CGCXX.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/constructor-alias.cpp
  test/CodeGenCXX/ctor-dtor-alias.cpp
  test/CodeGenCXX/destructors.cpp
  test/CodeGenCXX/dllexport-alias.cpp
  test/CodeGenCXX/dllexport.cpp
  test/CodeGenCXX/microsoft-abi-structors-alias.cpp
  test/CodeGenCXX/virtual-bases.cpp
  test/CodeGenCXX/virtual-destructor-calls.cpp

Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -1193,7 +1193,6 @@
   /// are emitted lazily.
   void EmitGlobal(GlobalDecl D);
 
-  bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
   bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
 
   llvm::GlobalValue *GetGlobalValue(StringRef Ref);
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -3693,6 +3693,9 @@
   // Create the alias with no name.
   auto *Alias = llvm::GlobalAlias::create(Linkage, "", Aliasee);
 
+  // Constructors and destructors are always unnamed_addr.
+  Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
   // Switch any previous uses to the alias.
   if (Entry) {
 assert(Entry->getType() == Aliasee->getType() &&
Index: lib/CodeGen/CGCXX.cpp
===
--- lib/CodeGen/CGCXX.cpp
+++ lib/CodeGen/CGCXX.cpp
@@ -109,17 +109,8 @@
   D->getType()->getAs()->getCallConv())
 return true;
 
-  return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
-  GlobalDecl(BaseD, Dtor_Base));
-}
-
-/// Try to emit a definition as a global alias for another definition.
-/// If \p InEveryTU is true, we know that an equivalent alias can be produced
-/// in every translation unit.
-bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
- GlobalDecl TargetDecl) {
-  if (!getCodeGenOpts().CXXCtorDtorAliases)
-return true;
+  GlobalDecl AliasDecl(D, Dtor_Base);
+  GlobalDecl TargetDecl(BaseD, Dtor_Base);
 
   // The alias will use the linkage of the referent.  If we can't
   // support aliases with that linkage, fail.
@@ -193,6 +184,9 @@
   auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
   Aliasee, &getModule());
 
+  // Destructors are always unnamed_addr.
+  Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
   // Switch any previous uses to the alias.
   if (Entry) {
 assert(Entry->getType() == AliasType &&
Index: test/CodeGenCXX/microsoft-abi-structors-alias.cpp
===
--- test/CodeGenCXX/microsoft-abi-structors-alias.cpp
+++ test/CodeGenCXX/microsoft-abi-structors-alias.cpp
@@ -22,7 +22,7 @@
 void foo() {
   B b;
 }
-// CHECK-DAG: @"??1B@test2@@UAE@XZ" = dso_local alias void (%"struct.test2::B"*), bitcast (void (%"struct.test2::A"*)* @"??1A@test2@@UAE@XZ" to void (%"struct.test2::B"*)*)
+// CHECK-DAG: @"??1B@test2@@UAE@XZ" = dso_local unnamed_addr alias void (%"struct.test2::B"*), bitcast (void (%"struct.test2::A"*)* @"??1A@test2@@UAE@XZ" to void (%"struct.test2::B"*)*)
 }
 
 namespace test3 {
Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -641,7 +641,7 @@
   A::~A() { }
   B::~B() { }
   // Emit a alias definition of B's constructor.
-  // M32-DAG: @"??1B@UseDtorAlias@@QAE@XZ" = dso_local dllexport alias {{.*}} @"??1A@UseDtorAlias@@QAE@XZ"
+  // M32-DAG: @"??1B@UseDtorAlias@@QAE@XZ" = dso_local dllexport unnamed_addr alias {{.*}} @"??1A@UseDtorAlias@@QAE@XZ"
 }
 
 struct __declspec(dllexport) DefaultedCtorsDtors {
Index: test/CodeGenCXX/dllexport-alias.cpp
===
--- test/CodeGenCXX/dllexport-alias.cpp
+++ test/CodeGenCXX/dllexport-alias.cpp
@@ -14,5 +14,5 @@
 
 A::~A() {}
 
-// CHECK: @_ZN1AC1Ev = dso_local dllexport alias void (%class.A*), void (%class.A*)* @_ZN1AC2Ev
-// CHECK: @_ZN1AD1Ev = dso_local dllexport alias void (%class.A*), void (%class.A*)* @_ZN1AD2Ev
+// CHECK: @_ZN1AC1Ev = dso_local dllexport unnamed_addr alias void (%class.A*), void (%class.A*)* @_ZN1AC2Ev
+// CHECK: @_ZN1AD1Ev = dso_local dllexport unnamed_addr alias void (%class.A*), void (%class.A*)* @_ZN1AD2Ev
Index: test/CodeGenCXX/virtual-destructor-calls.cpp

r334982 - IRgen: Mark aliases of ctors and dtors as unnamed_addr.

2018-06-18 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Jun 18 13:58:54 2018
New Revision: 334982

URL: http://llvm.org/viewvc/llvm-project?rev=334982&view=rev
Log:
IRgen: Mark aliases of ctors and dtors as unnamed_addr.

This is not only semantically correct but ensures that they will not
be marked as address-significant once D48155 lands.

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

Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/constructor-alias.cpp
cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
cfe/trunk/test/CodeGenCXX/destructors.cpp
cfe/trunk/test/CodeGenCXX/dllexport-alias.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-structors-alias.cpp
cfe/trunk/test/CodeGenCXX/virtual-bases.cpp
cfe/trunk/test/CodeGenCXX/virtual-destructor-calls.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=334982&r1=334981&r2=334982&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Jun 18 13:58:54 2018
@@ -109,17 +109,8 @@ bool CodeGenModule::TryEmitBaseDestructo
   D->getType()->getAs()->getCallConv())
 return true;
 
-  return TryEmitDefinitionAsAlias(GlobalDecl(D, Dtor_Base),
-  GlobalDecl(BaseD, Dtor_Base));
-}
-
-/// Try to emit a definition as a global alias for another definition.
-/// If \p InEveryTU is true, we know that an equivalent alias can be produced
-/// in every translation unit.
-bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
- GlobalDecl TargetDecl) {
-  if (!getCodeGenOpts().CXXCtorDtorAliases)
-return true;
+  GlobalDecl AliasDecl(D, Dtor_Base);
+  GlobalDecl TargetDecl(BaseD, Dtor_Base);
 
   // The alias will use the linkage of the referent.  If we can't
   // support aliases with that linkage, fail.
@@ -193,6 +184,9 @@ bool CodeGenModule::TryEmitDefinitionAsA
   auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
   Aliasee, &getModule());
 
+  // Destructors are always unnamed_addr.
+  Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
   // Switch any previous uses to the alias.
   if (Entry) {
 assert(Entry->getType() == AliasType &&

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=334982&r1=334981&r2=334982&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Jun 18 13:58:54 2018
@@ -1193,7 +1193,6 @@ public:
   /// are emitted lazily.
   void EmitGlobal(GlobalDecl D);
 
-  bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
   bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
 
   llvm::GlobalValue *GetGlobalValue(StringRef Ref);

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=334982&r1=334981&r2=334982&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon Jun 18 13:58:54 2018
@@ -3693,6 +3693,9 @@ static void emitConstructorDestructorAli
   // Create the alias with no name.
   auto *Alias = llvm::GlobalAlias::create(Linkage, "", Aliasee);
 
+  // Constructors and destructors are always unnamed_addr.
+  Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
   // Switch any previous uses to the alias.
   if (Entry) {
 assert(Entry->getType() == Aliasee->getType() &&

Modified: cfe/trunk/test/CodeGenCXX/constructor-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-alias.cpp?rev=334982&r1=334981&r2=334982&view=diff
==
--- cfe/trunk/test/CodeGenCXX/constructor-alias.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/constructor-alias.cpp Mon Jun 18 13:58:54 2018
@@ -9,4 +9,4 @@ struct B {
 B::B() {
 }
 
-// CHECK: @_ZN1BC1Ev = alias void (%struct.B*), void (%struct.B*)* @_ZN1BC2Ev
+// CHECK: @_ZN1BC1Ev = unnamed_addr alias void (%struct.B*), void 
(%struct.B*)* @_ZN1BC2Ev

Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=334982&r1=334981&r2=334982&view=diff
==
--- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Mon Jun 18 13:58:54 2018
@@ -14,8 +14

[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:3973
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
+  Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);

Use `Args.hasFlag` to determine if `-fdigraphs` or `-fno-digraphs` was 
specified last, then `CmdArgs.push_back("-fno-digraphs")` if digraphs are 
disabled. (There are lots of examples of that in this file that you can follow.)

What should `-fdigraphs` do under `-std=c89`? I think produing a "this flag is 
not compatible with that flag" diagnostic would make sense for that case.


Repository:
  rC Clang

https://reviews.llvm.org/D48266



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


[PATCH] D48296: clang-cl: Emit normal narrowing diagnostics for initializer lists if -fmsc-version is at least 1900 (i.e. MSVC2015).

2018-06-18 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: rnk.

Diagnostics for narrowing conversions in initializer lists are currently 
DefaultIgnored in Microsoft mode. But MSVC 2015 did add warnings about 
narrowing conversions (C2397), so clang-cl can remove its special case code if 
MSCompatibilityVersion is new enough.

(In MSVC, C2397 is just a warning and in clang it's default-mapped to an error, 
but it can be remapped, and disabled with -Wno-c++11-narrowing, so that should 
be fine.)

Fixes PR37314.


https://reviews.llvm.org/D48296

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/ms-initlist-narrowing.cpp

Index: clang/test/SemaCXX/ms-initlist-narrowing.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-initlist-narrowing.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -fms-compatibility-version=19.0 -std=c++11
+
+int ai[] = { 1, 2.0 };  // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
+
+template
+struct Agg {
+  T t;
+};
+
+void f(int i) {
+  // Constant expression.
+  Agg f8 = {1E50};  // expected-error {{constant expression evaluates to 1.00e+50 which cannot be narrowed to type 'float'}} expected-note {{silence}}
+
+  // Non-constant expression.
+  double d = 1.0;
+  Agg f2 = {d};  // expected-error {{non-constant-expression cannot be narrowed from type 'double' to 'float'}} expected-note {{silence}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -8360,40 +8360,49 @@
 // No narrowing occurred.
 return;
 
-  case NK_Type_Narrowing:
+  case NK_Type_Narrowing: {
 // This was a floating-to-integer conversion, which is always considered a
 // narrowing conversion even if the value is a constant and can be
 // represented exactly as an integer.
-S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_type_narrowing
-   : diag::ext_init_list_type_narrowing)
-  << PostInit->getSourceRange()
-  << PreNarrowingType.getLocalUnqualifiedType()
-  << EntityType.getLocalUnqualifiedType();
-break;
-
-  case NK_Constant_Narrowing:
+bool DiagErr =
+S.getLangOpts().CPlusPlus11 &&
+(!S.getLangOpts().MicrosoftExt ||
+ S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015));
+S.Diag(PostInit->getLocStart(), !DiagErr
+? diag::warn_init_list_type_narrowing
+: diag::ext_init_list_type_narrowing)
+<< PostInit->getSourceRange()
+<< PreNarrowingType.getLocalUnqualifiedType()
+<< EntityType.getLocalUnqualifiedType();
+  } break;
+
+  case NK_Constant_Narrowing: {
 // A constant value was narrowed.
+bool DiagErr =
+S.getLangOpts().CPlusPlus11 &&
+(!S.getLangOpts().MicrosoftExt ||
+ S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015));
 S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_constant_narrowing
-   : diag::ext_init_list_constant_narrowing)
-  << PostInit->getSourceRange()
-  << ConstantValue.getAsString(S.getASTContext(), ConstantType)
-  << EntityType.getLocalUnqualifiedType();
-break;
-
-  case NK_Variable_Narrowing:
+   !DiagErr ? diag::warn_init_list_constant_narrowing
+: diag::ext_init_list_constant_narrowing)
+<< PostInit->getSourceRange()
+<< ConstantValue.getAsString(S.getASTContext(), ConstantType)
+<< EntityType.getLocalUnqualifiedType();
+  } break;
+
+  case NK_Variable_Narrowing: {
 // A variable's value may have been narrowed.
+bool DiagErr =
+S.getLangOpts().CPlusPlus11 &&
+(!S.getLangOpts().MicrosoftExt ||
+ S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015));
 S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_variable_narrowing
-   : diag::ext_init_list_variable_narrowing)
-  << PostInit->getSourceRange()
-  << PreNarrowingType.getLocalUnqualifiedType()
-  << EntityType.getLocalUnqualifiedType();
-break;
+   !DiagErr ? diag::warn_init_list_variable_narrowing
+: diag::ext_init_list_variable_narrowing)
+<< PostInit->getSourceRange()
+<< PreNarrowingType.getLocalUnqualifiedType()
+<< EntityType.getLocalUnqualifiedType();
+  } break;
   }
 
   SmallString<128> StaticCast;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/m

[PATCH] D46190: For a referenced declaration, mark any associated usings as referenced.

2018-06-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

The right way to handle this is to pass both the ultimately-selected 
declaration and the declaration found by name lookup into the calls to 
`MarkAnyDeclReferenced` and friends. We should mark the selected declaration as 
`Used` (when appropriate), and mark the found declaration as `Referenced`.

We should not be trying to reconstruct which using declarations are in scope 
after the fact. Only declarations actually found by name lookup and then 
selected by the context performing the lookup should be marked referenced. 
(There may be cases where name lookup discards equivalent lookup results that 
are not redeclarations of one another, though, and to handle such cases 
properly, you may need to teach name lookup to track a list of found 
declarations rather than only one.)




Comment at: lib/Sema/Sema.cpp:1884-1885
+  ND = NA->getAliasedNamespace();
+  if (auto *NNS = NA->getQualifier())
+MarkNamespaceAliasReferenced(NNS->getAsNamespaceAlias());
+}

The loop and recursion here -- and indeed this whole function -- seem 
unnecessary.

```
namespace A {} // #1 
namespace X {
  namespace B = A; // #2
}
namespace Y = X; // #3
namespace C = Y::B; // #4
```

Declaration `#4` should mark `#2` and `#3` referenced. So the only 
'unreferenced namespace alias' warning we should get here is for `#4` -- and 
there is no need for marking `#4` as referenced to affect `#2` or `#3`.



Comment at: lib/Sema/Sema.cpp:1890-1891
+
+/// \brief Mark as referenced any 'using declaration' that have introduced
+/// the given declaration in the current context.
+void Sema::MarkUsingReferenced(Decl *D, CXXScopeSpec *SS, Expr *E) {

Why is this ever appropriate? I would think we should just mark the named 
declaration from the relevant lookup as referenced in all cases.


https://reviews.llvm.org/D46190



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


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-18 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes updated this revision to Diff 151771.
jtbandes added a comment.

Added `-fdigraphs`. I kept it as a cc1 option because it seemed awkward to 
"check whether the last arg was -fno-digraphs and pass only that arg to cc1" 
(if just directly forwarding all args, there would be an unrecognized argument 
error if it's not a cc1 option).


Repository:
  rC Clang

https://reviews.llvm.org/D48266

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Lexer/digraph.c


Index: test/Lexer/digraph.c
===
--- test/Lexer/digraph.c
+++ test/Lexer/digraph.c
@@ -1,6 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -DDIGRAPHS -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -DDIGRAPHS -fno-digraphs -fdigraphs -fsyntax-only -verify 
-ffreestanding %s
+// RUN: %clang_cc1 -fno-digraphs -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -fdigraphs -fno-digraphs -fsyntax-only -verify 
-ffreestanding %s
+
+#if DIGRAPHS
 
+// expected-no-diagnostics
 %:include 
 
 %:ifndef BUFSIZE
@@ -14,3 +19,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// expected-error@+1 {{expected ')'}} expected-note@+1{{to match this '('}}
+void copy(char d<::>);
+
+// expected-error@+1 {{expected function body}}
+void copy() <% %>
+
+#endif
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2174,6 +2174,8 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  Opts.Digraphs = Args.hasFlag(OPT_fdigraphs, OPT_fno_digraphs, Opts.Digraphs);
+
   if (Args.hasArg(OPT_fno_operator_names))
 Opts.CXXOperatorNames = 0;
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3970,6 +3970,7 @@
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
+  Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1334,6 +1334,10 @@
 def fno_diagnostics_show_option : Flag<["-"], "fno-diagnostics-show-option">, 
Group;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], 
"fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-"], "fdigraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', 
'%:' (default)">;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,
   HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>;
 def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, 
Group,


Index: test/Lexer/digraph.c
===
--- test/Lexer/digraph.c
+++ test/Lexer/digraph.c
@@ -1,6 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -DDIGRAPHS -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -DDIGRAPHS -fno-digraphs -fdigraphs -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -fno-digraphs -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -fdigraphs -fno-digraphs -fsyntax-only -verify -ffreestanding %s
+
+#if DIGRAPHS
 
+// expected-no-diagnostics
 %:include 
 
 %:ifndef BUFSIZE
@@ -14,3 +19,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// expected-error@+1 {{expected ')'}} expected-note@+1{{to match this '('}}
+void copy(char d<::>);
+
+// expected-error@+1 {{expected function body}}
+void copy() <% %>
+
+#endif
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2174,6 +2174,8 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  Opts.Digraphs = Arg

[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-18 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes marked an inline comment as done.
jtbandes added inline comments.



Comment at: include/clang/Driver/Options.td:1337-1338
 Flags<[CC1Option]>, Group;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,

rsmith wrote:
> In the driver, we generally want a `-ffoo` option matching `-fno-foo`. That 
> is, the driver (but not `-cc1`) should support a matching `-fdigraphs` option 
> to undo the effect of `-fno-digraphs`, unless there's a good reason not to do 
> so.
Didn't find a great place to put this option; I'm not sure what this file's 
organization scheme is supposed to be.


Repository:
  rC Clang

https://reviews.llvm.org/D48266



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


[PATCH] D47401: [X86] Rewrite the max and min reduction intrinsics to make better use of other functions and to reduce width to 256 and 128 bits were possible.

2018-06-18 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Is there any llvm side fast isel tests for these?




Comment at: cfe/trunk/lib/Headers/avx512fintrin.h:9855
+  __v8di __t6 = (__v8di)_mm512_##op(__t4, __t5); \
+  return __t6[0];
 

craig.topper wrote:
> RKSimon wrote:
> > Would it be dumb to allow VLX capable CPUs to use 128/256 variants of the 
> > VPMAXUQ etc ? Or is it better to focus on improving SimplifyDemandedElts to 
> > handle this (and many other reduction cases that all tend to keep to the 
> > original vector width)?
> I'm not sure how to do that from clang. Should we be using a reduction 
> intrinsic and do custom lowering in the backend?
I believe we're still missing the clang reduction intrinsics.

We also have the problem with the 'fast math only' accumulator argument on the 
'experimental' reductions that we can't actually change because arm64 already 
relies on them in production code...

But we could maybe propose clang integer reduction intrinsics?

TBH I don't think any of that needs to be done for this patch, its just an 
indication that x86 reductions aren't great yet.


Repository:
  rL LLVM

https://reviews.llvm.org/D47401



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


[PATCH] D47586: Update NRVO logic to support early return (Attempt 2)

2018-06-18 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.

LGTM




Comment at: test/CodeGenCXX/nrvo-noopt.cpp:1
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+

You don't need the `-O0` here; that's the default.


Repository:
  rC Clang

https://reviews.llvm.org/D47586



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


[PATCH] D48155: Teach Clang to emit address-significance tables.

2018-06-18 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.

Please add documentation and release notes for this flag too.


https://reviews.llvm.org/D48155



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


[PATCH] D48292: use modern type trait implementations when available

2018-06-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added reviewers: EricWF, mclow.lists.
Herald added a subscriber: cfe-commits.

Teach libcxx to stop using various deprecated __has_* type traits, in favor of 
the ("modern", C++11 era) __is_* type traits.

This is mostly just a simplification, but fixes at least one bug: `_Atomic T` 
should be considered trivially-destructible, but is not considered to be POD by 
Clang, and `__has_trivial_destructor` is specified in the GCC documentation as 
returning `false` for non-POD non-class types.


Repository:
  rCXX libc++

https://reviews.llvm.org/D48292

Files:
  include/type_traits
  
test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp

Index: test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
===
--- test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
+++ test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
@@ -116,4 +116,12 @@
 test_is_not_trivially_destructible();
 test_is_not_trivially_destructible();
 #endif
+
+#if defined(__is_identifier)
+#if !__is_identifier(_Atomic)
+test_is_trivially_destructible<_Atomic int>();
+test_is_trivially_destructible<_Atomic float>();
+test_is_trivially_destructible<_Atomic int*>();
+#endif
+#endif
 }
Index: include/type_traits
===
--- include/type_traits
+++ include/type_traits
@@ -3675,9 +3675,14 @@
 
 // is_trivially_destructible
 
-#if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
+#if __has_keyword(__is_trivially_destructible)
 
 template  struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
+: public integral_constant {};
+
+#elif __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
+
+template  struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
 : public integral_constant::value && __has_trivial_destructor(_Tp)> {};
 
 #else
@@ -3702,19 +3707,16 @@
 
 // is_nothrow_constructible
 
-#if 0
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+#if __has_keyword(__is_nothrow_constructible)
+
 template 
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
-: public integral_constant
-{
-};
+: public integral_constant {};
 
-#else
+#elif __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
-
 template  struct __libcpp_is_nothrow_constructible;
 
 template 
@@ -3750,7 +3752,7 @@
 {
 };
 
-#else  // __has_feature(cxx_noexcept)
+#else  // __has_keyword(__is_nothrow_constructible) || __has_feature(cxx_noexcept)
 
 template 
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
@@ -3806,9 +3808,26 @@
 
 #else  // _LIBCPP_HAS_NO_VARIADICS
 
+#if __has_keyword(__is_nothrow_constructible)
+
 template 
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
+: public integral_constant {};
+
+template 
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _A0>
+: public integral_constant {};
+
+template 
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp>
+: public integral_constant {};
+
+#else  // __has_keyword(__is_nothrow_constructible)
+
+template 
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
 : false_type
 {
 };
@@ -3857,8 +3876,8 @@
 {
 };
 
+#endif  // __has_keyword(__is_nothrow_constructible)
 #endif  // _LIBCPP_HAS_NO_VARIADICS
-#endif  // __has_feature(is_nothrow_constructible)
 
 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
 template 
@@ -3908,8 +3927,14 @@
 
 // is_nothrow_assignable
 
-#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
+#if __has_keyword(__is_nothrow_assignable)
 
+template 
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
+: public integral_constant {};
+
+#elif __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
+
 template  struct __libcpp_is_nothrow_assignable;
 
 template 
@@ -3930,7 +3955,7 @@
 {
 };
 
-#else  // __has_feature(cxx_noexcept)
+#else  // __has_keyword(__is_nothrow_assignable) || __has_feature(cxx_noexcept)
 
 template 
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r334807 - [clangd] Do not report comments that only have special chars.

2018-06-18 Thread Reid Kleckner via cfe-commits
And, as soon as I sent that, I realized what was up. Apparently
auto-complete is driven by the parser, and delayed template parsing means
we don't parse templates. That seems like a serious issue that should get
fixed eventually.

Anyway, I landed a crummy workaround in r334973 to green the bots.

On Mon, Jun 18, 2018 at 11:53 AM Reid Kleckner  wrote:

> This test has been failing on Windows since it has been added:
> http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12549
>
> I took a look at the unittest code, but I'm not familiar enough with this
> code to debug it. Can you take a look at this?
>
> On Fri, Jun 15, 2018 at 1:35 AM Ilya Biryukov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: ibiryukov
>> Date: Fri Jun 15 01:31:17 2018
>> New Revision: 334807
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=334807&view=rev
>> Log:
>> [clangd] Do not report comments that only have special chars.
>>
>> Summary:
>> Like the following:
>>   // ---
>>   // ===
>>   // ***
>>
>> It does not cover all the cases, but those are definitely not very
>> useful.
>>
>> Reviewers: sammccall, ioeric, hokein
>>
>> Reviewed By: sammccall
>>
>> Subscribers: MaskRay, jkorous, cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D48171
>>
>> Modified:
>> clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
>> clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
>>
>> Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=334807&r1=334806&r2=334807&view=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Fri Jun 15
>> 01:31:17 2018
>> @@ -151,6 +151,16 @@ bool canRequestComment(const ASTContext
>>const ObjCPropertyDecl *PDecl = M ? M->findPropertyDecl() : nullptr;
>>return !PDecl || canRequestForDecl(*PDecl);
>>  }
>> +
>> +bool LooksLikeDocComment(llvm::StringRef CommentText) {
>> +  // We don't report comments that only contain "special" chars.
>> +  // This avoids reporting various delimiters, like:
>> +  //   =
>> +  //   -
>> +  //   *
>> +  return CommentText.find_first_not_of("/*-= \t\r\n") !=
>> llvm::StringRef::npos;
>> +}
>> +
>>  } // namespace
>>
>>  std::string getDocComment(const ASTContext &Ctx,
>> @@ -167,7 +177,10 @@ std::string getDocComment(const ASTConte
>>const RawComment *RC = getCompletionComment(Ctx, Decl);
>>if (!RC)
>>  return "";
>> -  return RC->getFormattedText(Ctx.getSourceManager(),
>> Ctx.getDiagnostics());
>> +  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(),
>> Ctx.getDiagnostics());
>> +  if (!LooksLikeDocComment(Doc))
>> +return "";
>> +  return Doc;
>>  }
>>
>>  std::string
>> @@ -180,7 +193,10 @@ getParameterDocComment(const ASTContext
>>const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
>>if (!RC)
>>  return "";
>> -  return RC->getFormattedText(Ctx.getSourceManager(),
>> Ctx.getDiagnostics());
>> +  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(),
>> Ctx.getDiagnostics());
>> +  if (!LooksLikeDocComment(Doc))
>> +return "";
>> +  return Doc;
>>  }
>>
>>  void getLabelAndInsertText(const CodeCompletionString &CCS, std::string
>> *Label,
>>
>> Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=334807&r1=334806&r2=334807&view=diff
>>
>> ==
>> --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
>> (original)
>> +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri
>> Jun 15 01:31:17 2018
>> @@ -1100,6 +1100,65 @@ TEST(CompletionTest, DocumentationFromCh
>>Contains(AllOf(Not(IsDocumented()), Named("func";
>>  }
>>
>> +TEST(CompletionTest, NonDocComments) {
>> +  MockFSProvider FS;
>> +  auto FooCpp = testPath("foo.cpp");
>> +  FS.Files[FooCpp] = "";
>> +
>> +  MockCompilationDatabase CDB;
>> +  IgnoreDiagnostics DiagConsumer;
>> +  ClangdServer Server(CDB, FS, DiagConsumer,
>> ClangdServer::optsForTest());
>> +
>> +  Annotations Source(R"cpp(
>> +// --
>> +int comments_foo();
>> +
>> +// A comment and a decl are separated by newlines.
>> +// Therefore, the comment shouldn't show up as doc comment.
>> +
>> +int comments_bar();
>> +
>> +// this comment should be in the results.
>> +int comments_baz();
>> +
>> +
>> +template 
>> +struct Struct {
>> +  int comments_qux();
>> +  int comments_quux();
>> +};
>> +
>> +
>> +// This comment should not be there.
>> +
>> 

[clang-tools-extra] r334973 - Fix clangd test to pass when delayed template parsing is on by default

2018-06-18 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Jun 18 11:55:10 2018
New Revision: 334973

URL: http://llvm.org/viewvc/llvm-project?rev=334973&view=rev
Log:
Fix clangd test to pass when delayed template parsing is on by default

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=334973&r1=334972&r2=334973&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon Jun 18 
11:55:10 2018
@@ -1212,6 +1212,9 @@ TEST(CompletionTest, NonDocComments) {
   int a = comments^;
 }
   )cpp");
+  // FIXME: Auto-completion in a template requires disabling delayed template
+  // parsing.
+  CDB.ExtraClangFlags.push_back("-fno-delayed-template-parsing");
   Server.addDocument(FooCpp, Source.code(), WantDiagnostics::Yes);
   CompletionList Completions = cantFail(runCodeComplete(
   Server, FooCpp, Source.point(), clangd::CodeCompleteOptions()));


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


r334972 - Don't let test/Driver/no-canonical-prefixes.c form a symlink cycle the second time it runs.

2018-06-18 Thread Nico Weber via cfe-commits
Author: nico
Date: Mon Jun 18 11:50:35 2018
New Revision: 334972

URL: http://llvm.org/viewvc/llvm-project?rev=334972&view=rev
Log:
Don't let test/Driver/no-canonical-prefixes.c form a symlink cycle the second 
time it runs.

The test makes %t.fake a symlink to %t.real by running `ln -sf %t.real
%t.fake`. If %t.fake already is a symlink to %t.real when this runs (e.g. if
the test has run before), then this effectively becomes `ln -sf %t.real 
%t.real`,
symlinking the directory to itself. At least on my mac, this leads to the
directory containing itself.

As fix, just remove %t.fake before creating the symlink. To clean up build dirs
on bots, also remove %t.real for a while.

https://reviews.llvm.org/D48224

Modified:
cfe/trunk/test/Driver/no-canonical-prefixes.c

Modified: cfe/trunk/test/Driver/no-canonical-prefixes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/no-canonical-prefixes.c?rev=334972&r1=334971&r2=334972&view=diff
==
--- cfe/trunk/test/Driver/no-canonical-prefixes.c (original)
+++ cfe/trunk/test/Driver/no-canonical-prefixes.c Mon Jun 18 11:50:35 2018
@@ -1,9 +1,14 @@
 // Due to ln -sf:
 // REQUIRES: shell
+// RUN: rm -rf %t.real
 // RUN: mkdir -p %t.real
 // RUN: cd %t.real
 // RUN: ln -sf %clang test-clang
 // RUN: cd ..
+// Important to remove %t.fake: If it already is a symlink to %t.real when
+// `ln -sf %t.real %t.fake` runs, then that would symlink %t.real to itself,
+// forming a cycle.
+// RUN: rm -rf %t.fake
 // RUN: ln -sf %t.real %t.fake
 // RUN: cd %t.fake
 // RUN: ./test-clang -v -S %s 2>&1 | FileCheck --check-prefix=CANONICAL %s


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


[PATCH] D48224: Don't let test/Driver/no-canonical-prefixes.c form a symlink cycle the second time it runs.

2018-06-18 Thread Nico Weber via Phabricator via cfe-commits
thakis closed this revision.
thakis added a comment.

r334972, thanks!


https://reviews.llvm.org/D48224



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


Re: [clang-tools-extra] r334807 - [clangd] Do not report comments that only have special chars.

2018-06-18 Thread Reid Kleckner via cfe-commits
This test has been failing on Windows since it has been added:
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12549

I took a look at the unittest code, but I'm not familiar enough with this
code to debug it. Can you take a look at this?

On Fri, Jun 15, 2018 at 1:35 AM Ilya Biryukov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ibiryukov
> Date: Fri Jun 15 01:31:17 2018
> New Revision: 334807
>
> URL: http://llvm.org/viewvc/llvm-project?rev=334807&view=rev
> Log:
> [clangd] Do not report comments that only have special chars.
>
> Summary:
> Like the following:
>   // ---
>   // ===
>   // ***
>
> It does not cover all the cases, but those are definitely not very
> useful.
>
> Reviewers: sammccall, ioeric, hokein
>
> Reviewed By: sammccall
>
> Subscribers: MaskRay, jkorous, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D48171
>
> Modified:
> clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
> clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
>
> Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=334807&r1=334806&r2=334807&view=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
> +++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Fri Jun 15
> 01:31:17 2018
> @@ -151,6 +151,16 @@ bool canRequestComment(const ASTContext
>const ObjCPropertyDecl *PDecl = M ? M->findPropertyDecl() : nullptr;
>return !PDecl || canRequestForDecl(*PDecl);
>  }
> +
> +bool LooksLikeDocComment(llvm::StringRef CommentText) {
> +  // We don't report comments that only contain "special" chars.
> +  // This avoids reporting various delimiters, like:
> +  //   =
> +  //   -
> +  //   *
> +  return CommentText.find_first_not_of("/*-= \t\r\n") !=
> llvm::StringRef::npos;
> +}
> +
>  } // namespace
>
>  std::string getDocComment(const ASTContext &Ctx,
> @@ -167,7 +177,10 @@ std::string getDocComment(const ASTConte
>const RawComment *RC = getCompletionComment(Ctx, Decl);
>if (!RC)
>  return "";
> -  return RC->getFormattedText(Ctx.getSourceManager(),
> Ctx.getDiagnostics());
> +  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(),
> Ctx.getDiagnostics());
> +  if (!LooksLikeDocComment(Doc))
> +return "";
> +  return Doc;
>  }
>
>  std::string
> @@ -180,7 +193,10 @@ getParameterDocComment(const ASTContext
>const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
>if (!RC)
>  return "";
> -  return RC->getFormattedText(Ctx.getSourceManager(),
> Ctx.getDiagnostics());
> +  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(),
> Ctx.getDiagnostics());
> +  if (!LooksLikeDocComment(Doc))
> +return "";
> +  return Doc;
>  }
>
>  void getLabelAndInsertText(const CodeCompletionString &CCS, std::string
> *Label,
>
> Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=334807&r1=334806&r2=334807&view=diff
>
> ==
> --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
> (original)
> +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Jun
> 15 01:31:17 2018
> @@ -1100,6 +1100,65 @@ TEST(CompletionTest, DocumentationFromCh
>Contains(AllOf(Not(IsDocumented()), Named("func";
>  }
>
> +TEST(CompletionTest, NonDocComments) {
> +  MockFSProvider FS;
> +  auto FooCpp = testPath("foo.cpp");
> +  FS.Files[FooCpp] = "";
> +
> +  MockCompilationDatabase CDB;
> +  IgnoreDiagnostics DiagConsumer;
> +  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
> +
> +  Annotations Source(R"cpp(
> +// --
> +int comments_foo();
> +
> +// A comment and a decl are separated by newlines.
> +// Therefore, the comment shouldn't show up as doc comment.
> +
> +int comments_bar();
> +
> +// this comment should be in the results.
> +int comments_baz();
> +
> +
> +template 
> +struct Struct {
> +  int comments_qux();
> +  int comments_quux();
> +};
> +
> +
> +// This comment should not be there.
> +
> +template 
> +int Struct::comments_qux() {
> +}
> +
> +// This comment **should** be in results.
> +template 
> +int Struct::comments_quux() {
> +  int a = comments^;
> +}
> +  )cpp");
> +  Server.addDocument(FooCpp, Source.code(), WantDiagnostics::Yes);
> +  CompletionList Completions = cantFail(runCodeComplete(
> +  Server, FooCpp, Source.point(), clangd::CodeCompleteOptions()));
> +
> +  // We should not get any of those comments in completion.
> +  EXPECT_THA

[PATCH] D48224: Don't let test/Driver/no-canonical-prefixes.c form a symlink cycle the second time it runs.

2018-06-18 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D48224



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


[PATCH] D47988: [CodeGen] Emit MSVC funclet IR for Obj-C exceptions

2018-06-18 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In general, it's unfortunate that this has to leave so many 
C++-runtime-specific tendrils in the ObjC code.  Unlike the EH type patch, 
though, I'm not sure I can see a great alternative here, especially because of 
the semantic restrictions required by outlining.




Comment at: lib/CodeGen/CGCXXABI.h:248
+llvm_unreachable("Only needed for the Microsoft ABI");
+  }
 

Should you just generalize the existing method to only take a VarDecl* so it 
can be used for either kind of catch?


Repository:
  rC Clang

https://reviews.llvm.org/D47988



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


[PATCH] D47233: [CodeGen] Emit MSVC RTTI for Obj-C EH types

2018-06-18 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGObjCMac.cpp:7457-7460
 CGObjCNonFragileABIMac::GetEHType(QualType T) {
   // There's a particular fixed type info for 'id'.
   if (T->isObjCIdType() || T->isObjCQualifiedIdType()) {
+if (CGM.getTriple().isWindowsMSVCEnvironment())

rnk wrote:
> @rjmccall how should this be organized in the long run? At this point, the 
> naming seems totally wrong. Is the non-fragile ABI sort of the canonical way 
> forward for Obj-C, i.e. it's what a new platform would want to use to best 
> stay in sync with the future of obj-c?
For Darwin, yes, absolutely.

I think this method should probably just completely delegate to the `CGCXXABI` 
using a new `getAddrOfObjCRTTIDescriptor` method.


Repository:
  rC Clang

https://reviews.llvm.org/D47233



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


[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-06-18 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov requested changes to this revision.
george.karpenkov added a comment.
This revision now requires changes to proceed.

Looks good overall, but some nits inline.




Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:682
 
+StringRef getVariableName(const FieldDecl *Field) {
+  const auto *CXXParent = dyn_cast(Field->getParent());

Can we have a comment explaining the semantics? From my understanding, you find 
a corresponding capture using a source location, and get a name from there.



Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:685
+
+  if (CXXParent && CXXParent->isLambda()) {
+CXXRecordDecl::capture_const_iterator CapturedVar =

CXXParent is guaranteed to be non-null at this stage, otherwise dyn_cast fails



Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:687
+CXXRecordDecl::capture_const_iterator CapturedVar =
+std::find_if(CXXParent->captures_begin(), CXXParent->captures_end(),
+ [&Field](const LambdaCapture &L) {

Could we just use a for-each here? Sorry for being opinionated, I'm pretty sure 
it would be both shorter and more readable.



Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:689
+ [&Field](const LambdaCapture &L) {
+   return Field->getLocation().getRawEncoding() ==
+  L.getLocation().getRawEncoding();

That's exactly the semantics of the equality operator on source locations, so 
why not `Field->getLocation() == L.getLocation()` ?


Repository:
  rC Clang

https://reviews.llvm.org/D48291



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


[PATCH] D47988: [CodeGen] Emit MSVC funclet IR for Obj-C exceptions

2018-06-18 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Ping.


Repository:
  rC Clang

https://reviews.llvm.org/D47988



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


[PATCH] D47233: [CodeGen] Emit MSVC RTTI for Obj-C EH types

2018-06-18 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Ping.


Repository:
  rC Clang

https://reviews.llvm.org/D47233



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


r334965 - [analyzer] Remove accidentally committed lines.

2018-06-18 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Jun 18 10:59:03 2018
New Revision: 334965

URL: http://llvm.org/viewvc/llvm-project?rev=334965&view=rev
Log:
[analyzer] Remove accidentally committed lines.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=334965&r1=334964&r2=334965&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Mon Jun 18 10:59:03 2018
@@ -2548,10 +2548,7 @@ bool GRBugReporter::generatePathDiagnost
 // new symbols and regions are interesting, or add other visitors based on
 // the information they find. If they do, we need to regenerate the path
 // based on our new report configuration.
-int jj=0;
-do { // TODO: dump statistics on the MAX number of iterations of this loop.
-  jj++;
-  assert(jj<10);
+do {
   // Get a clean copy of all the visitors.
   for (BugReport::visitor_iterator I = R->visitor_begin(),
E = R->visitor_end(); I != E; ++I)


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


[PATCH] D47670: [analyzer] [NFC] Remove unused Extensive diagnostic setting, rename AlternateExtensive to Extensive.

2018-06-18 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@alexfh apologies, fixed.


Repository:
  rC Clang

https://reviews.llvm.org/D47670



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


[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-06-18 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: xazax.hun, george.karpenkov, NoQ, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, 
whisperity.

Repository:
  rC Clang

https://reviews.llvm.org/D48291

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -737,6 +737,22 @@
 //===--===//
 
 template 
+struct LambdaThisTest {
+  Callable functor;
+
+  LambdaThisTest(const Callable &functor, int) : functor(functor) {
+// All good!
+  }
+};
+
+struct HasCapturableThis {
+  void fLambdaThisTest() {
+auto isEven = [this](int a) { return a % 2 == 0; }; // no-crash
+LambdaThisTest(isEven, int());
+  }
+};
+
+template 
 struct LambdaTest1 {
   Callable functor;
 
@@ -760,7 +776,7 @@
 
 void fLambdaTest2() {
   int b;
-  auto equals = [&b](int a) { return a == b; }; // expected-note{{uninitialized field 'this->functor.'}}
+  auto equals = [&b](int a) { return a == b; }; // expected-note{{uninitialized field 'this->functor.b'}}
   LambdaTest2(equals, int());
 }
 #else
@@ -782,8 +798,8 @@
 namespace LT3Detail {
 
 struct RecordType {
-  int x; // expected-note{{uninitialized field 'this->functor..x'}}
-  int y; // expected-note{{uninitialized field 'this->functor..y'}}
+  int x; // expected-note{{uninitialized field 'this->functor.rec1.x'}}
+  int y; // expected-note{{uninitialized field 'this->functor.rec1.y'}}
 };
 
 } // namespace LT3Detail
@@ -826,6 +842,35 @@
 }
 #endif //PEDANTIC
 
+template 
+struct MultipleLambdaCapturesTest1 {
+  Callable functor;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  MultipleLambdaCapturesTest1(const Callable &functor, int) : functor(functor) {} // expected-warning{{2 uninitialized field}}
+};
+
+void fMultipleLambdaCapturesTest1() {
+  int b1, b2 = 3, b3;
+  auto equals = [&b1, &b2, &b3](int a) { return a == b1 == b2 == b3; }; // expected-note{{uninitialized field 'this->functor.b1'}}
+  // expected-note@-1{{uninitialized field 'this->functor.b3'}}
+  MultipleLambdaCapturesTest1(equals, int());
+}
+
+template 
+struct MultipleLambdaCapturesTest2 {
+  Callable functor;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  MultipleLambdaCapturesTest2(const Callable &functor, int) : functor(functor) {} // expected-warning{{1 uninitialized field}}
+};
+
+void fMultipleLambdaCapturesTest2() {
+  int b1, b2 = 3, b3;
+  auto equals = [b1, &b2, &b3](int a) { return a == b1 == b2 == b3; }; // expected-note{{uninitialized field 'this->functor.b3'}}
+  MultipleLambdaCapturesTest2(equals, int());
+}
+
 //===--===//
 // System header tests.
 //===--===//
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -230,6 +230,10 @@
 /// Constructs a note message for a given FieldChainInfo object.
 void printNoteMessage(llvm::raw_ostream &Out, const FieldChainInfo &Chain);
 
+/// Returns with Field's name. This is a helper function to get the correct name
+/// even if Field is a captured lambda variable.
+StringRef getVariableName(const FieldDecl *Field);
+
 } // end of anonymous namespace
 
 //===--===//
@@ -594,30 +598,15 @@
 // "uninitialized field 'this->x'", but we can't refer to 'x' directly,
 // we need an explicit namespace resolution whether the uninit field was
 // 'D1::x' or 'D2::x'.
-//
-// TODO: If a field in the fieldchain is a captured lambda parameter, this
-// function constructs an empty string for it:
-//
-//   template  struct A {
-// Callable c;
-// A(const Callable &c, int) : c(c) {}
-//   };
-//
-//   int b; // say that this isn't zero initialized
-//   auto alwaysTrue = [&b](int a) { return true; };
-//
-// A call with these parameters: A::A(alwaysTrue, int())
-// will emit a note with the message "uninitialized field: 'this->c.'". If
-// possible, the lambda parameter name should be retrieved or be replaced with a
-// "" or something similar.
 void FieldChainInfo::print(llvm::raw_ostream &Out) const {
   if (Chain.isEmpty())
 return;
 
   const llvm::ImmutableListImpl *L =
   Chain.getInternalPointer();
   printTail(Out, L->getTail());
-  Out << L->getHead()->getDecl()->getNameAsString();
+
+  Out << getVariableName(L->getHead()->getDecl());
 }
 
 void FieldChainInfo::printTail(
@@ -628,7 +617,7 @@
 
   printTail(Out, L->getTail());
   const FieldDecl *Field = L-

[PATCH] D48288: Fix a bug introduced by rL334850

2018-06-18 Thread Tomasz Krupa via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334964: Fix a bug introduced by rL334850 (authored by 
tkrupa, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48288?vs=151742&id=151752#toc

Repository:
  rC Clang

https://reviews.llvm.org/D48288

Files:
  lib/CodeGen/CGBuiltin.cpp


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -9907,15 +9907,15 @@
   Intrinsic::x86_avx512_mask_sqrt_ss;
   return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
 }
-Value *A = Builder.CreateExtractElement(Ops[0], (uint64_t)0);
+Value *A = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
 Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
 Value *Src = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
 int MaskSize = Ops[3]->getType()->getScalarSizeInBits();
 llvm::Type *MaskTy = llvm::VectorType::get(Builder.getInt1Ty(), MaskSize);
 Value *Mask = Builder.CreateBitCast(Ops[3], MaskTy);
 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
 A = Builder.CreateSelect(Mask, Builder.CreateCall(F, {A}), Src);
-return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
+return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
   }
   case X86::BI__builtin_ia32_sqrtpd256:
   case X86::BI__builtin_ia32_sqrtpd:


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -9907,15 +9907,15 @@
   Intrinsic::x86_avx512_mask_sqrt_ss;
   return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
 }
-Value *A = Builder.CreateExtractElement(Ops[0], (uint64_t)0);
+Value *A = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
 Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
 Value *Src = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
 int MaskSize = Ops[3]->getType()->getScalarSizeInBits();
 llvm::Type *MaskTy = llvm::VectorType::get(Builder.getInt1Ty(), MaskSize);
 Value *Mask = Builder.CreateBitCast(Ops[3], MaskTy);
 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
 A = Builder.CreateSelect(Mask, Builder.CreateCall(F, {A}), Src);
-return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
+return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
   }
   case X86::BI__builtin_ia32_sqrtpd256:
   case X86::BI__builtin_ia32_sqrtpd:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r334964 - Fix a bug introduced by rL334850

2018-06-18 Thread Tomasz Krupa via cfe-commits
Author: tkrupa
Date: Mon Jun 18 10:57:05 2018
New Revision: 334964

URL: http://llvm.org/viewvc/llvm-project?rev=334964&view=rev
Log:
Fix a bug introduced by rL334850

Summary: All *_sqrt_round_s[s|d] intrinsics should execute a square root on
zeroth element from B (Ops[1]) and insert in to A (Ops[0]), not the other way 
around.

Reviewers: itaraban, craig.topper

Reviewed By: craig.topper

Subscribers: craig.topper, cfe-commits

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

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

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334964&r1=334963&r2=334964&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Jun 18 10:57:05 2018
@@ -9907,7 +9907,7 @@ Value *CodeGenFunction::EmitX86BuiltinEx
   Intrinsic::x86_avx512_mask_sqrt_ss;
   return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
 }
-Value *A = Builder.CreateExtractElement(Ops[0], (uint64_t)0);
+Value *A = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
 Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
 Value *Src = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
 int MaskSize = Ops[3]->getType()->getScalarSizeInBits();
@@ -9915,7 +9915,7 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 Value *Mask = Builder.CreateBitCast(Ops[3], MaskTy);
 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
 A = Builder.CreateSelect(Mask, Builder.CreateCall(F, {A}), Src);
-return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
+return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
   }
   case X86::BI__builtin_ia32_sqrtpd256:
   case X86::BI__builtin_ia32_sqrtpd:


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


[PATCH] D48285: [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag

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

I wonder if this could be done when plist is emitted generally, independent of 
any checks.


Repository:
  rC Clang

https://reviews.llvm.org/D48285



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


[PATCH] D48290: [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-18 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added reviewers: sammccall, malaperle.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov.

Some URI schemes require a hint path to be provided, and workspace root
path seems to be a good fit.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48290

Files:
  clangd/ClangdServer.cpp
  clangd/FindSymbols.cpp
  clangd/FindSymbols.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/FindSymbolsTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp
  unittests/clangd/TestFS.cpp

Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -66,7 +66,8 @@
   return Path.str();
 }
 
-/// unittest: is a scheme that refers to files relative to testRoot()
+/// unittest: is a scheme that refers to files relative to testRoot().
+/// URI body is relative path to testRoot().
 class TestScheme : public URIScheme {
 public:
   static const char *Scheme;
@@ -89,7 +90,7 @@
   llvm::inconvertibleErrorCode());
 
 return URI(Scheme, /*Authority=*/"",
-   llvm::sys::path::convert_to_slash(Body));
+   StringRef(llvm::sys::path::convert_to_slash(Body)).ltrim('/'));
   }
 };
 
Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -379,7 +379,7 @@
   TestFileName = testPath("x.cpp");
   runSymbolCollector("class Foo {};", /*Main=*/"");
   EXPECT_THAT(Symbols, UnorderedElementsAre(
-   AllOf(QName("Foo"), DeclURI("unittest:///x.h";
+   AllOf(QName("Foo"), DeclURI("unittest:x.h";
 }
 
 TEST_F(SymbolCollectorTest, InvalidURIScheme) {
Index: unittests/clangd/FindSymbolsTests.cpp
===
--- unittests/clangd/FindSymbolsTests.cpp
+++ unittests/clangd/FindSymbolsTests.cpp
@@ -40,13 +40,18 @@
 ClangdServer::Options optsForTests() {
   auto ServerOpts = ClangdServer::optsForTest();
   ServerOpts.BuildDynamicSymbolIndex = true;
+  ServerOpts.URISchemes = {"unittest", "file"};
   return ServerOpts;
 }
 
 class WorkspaceSymbolsTest : public ::testing::Test {
 public:
   WorkspaceSymbolsTest()
-  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {}
+  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {
+// Make sure the test root directory is created.
+FSProvider.Files[testPath("unused")] = "";
+Server.setRootPath(testRoot());
+  }
 
 protected:
   MockFSProvider FSProvider;
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -104,7 +104,7 @@
   Req.Query = "";
   bool SeenSymbol = false;
   M.fuzzyFind(Req, [&](const Symbol &Sym) {
-EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:///f.h");
+EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:f.h");
 SeenSymbol = true;
   });
   EXPECT_TRUE(SeenSymbol);
Index: clangd/FindSymbols.h
===
--- clangd/FindSymbols.h
+++ clangd/FindSymbols.h
@@ -27,9 +27,11 @@
 /// "::". For example, "std::" will list all children of the std namespace and
 /// "::" alone will list all children of the global namespace.
 /// \p Limit limits the number of results returned (0 means no limit).
+/// \p RootPath Root path of the workspace. This is used as the hint path when
+/// resolving URIs.
 llvm::Expected>
 getWorkspaceSymbols(llvm::StringRef Query, int Limit,
-const SymbolIndex *const Index);
+const SymbolIndex *const Index, llvm::StringRef RootPath);
 
 } // namespace clangd
 } // namespace clang
Index: clangd/FindSymbols.cpp
===
--- clangd/FindSymbols.cpp
+++ clangd/FindSymbols.cpp
@@ -95,8 +95,8 @@
 } // namespace
 
 llvm::Expected>
-getWorkspaceSymbols(StringRef Query, int Limit,
-const SymbolIndex *const Index) {
+getWorkspaceSymbols(StringRef Query, int Limit, const SymbolIndex *const Index,
+StringRef RootPath) {
   std::vector Result;
   if (Query.empty() || !Index)
 return Result;
@@ -116,7 +116,7 @@
 Req.MaxCandidateCount = Limit;
   TopN Top(Req.MaxCandidateCount);
   FuzzyMatcher Filter(Req.Query);
-  Index->fuzzyFind(Req, [&Top, &Filter](const Symbol &Sym) {
+  Index->fuzzyFind(Req, [RootPath, &Top, &Filter](const Symbol &Sym) {
 // Prefer the definition over e.g. a function declaration in a header
 auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
 auto Uri = URI::parse(CD.FileURI);
@@ -126,9 +126,7 @@
   CD.FileURI, Sym.Name));
   return;
 }
-// FIXME: Passing no H

[PATCH] D48287: [HIP] Support -fcuda-flush-denormals-to-zero for amdgcn

2018-06-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 151748.
yaxunl added a comment.

Correct comments in test.


https://reviews.llvm.org/D48287

Files:
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenCUDA/flush-denormals.cu


Index: test/CodeGenCUDA/flush-denormals.cu
===
--- test/CodeGenCUDA/flush-denormals.cu
+++ test/CodeGenCUDA/flush-denormals.cu
@@ -5,18 +5,33 @@
 // RUN:   -triple nvptx-nvidia-cuda -emit-llvm -o - %s | \
 // RUN:   FileCheck %s -check-prefix CHECK -check-prefix FTZ
 
+// RUN: %clang_cc1 -fcuda-is-device -x hip \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDNOFTZ
+// RUN: %clang_cc1 -fcuda-is-device -x hip -fcuda-flush-denormals-to-zero \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDFTZ
+
 #include "Inputs/cuda.h"
 
 // Checks that device function calls get emitted with the "ntpvx-f32ftz"
 // attribute set to "true" when we compile CUDA device code with
 // -fcuda-flush-denormals-to-zero.  Further, check that we reflect the presence
 // or absence of -fcuda-flush-denormals-to-zero in a module flag.
 
+// AMDGCN targets always have +fp64-fp16-denormals.
+// AMDGCN targets without fast FMAF (e.g. gfx803) always have +fp32-denormals.
+// For AMDGCN target with fast FMAF (e.g. gfx900), it has +fp32-denormals
+// by default and -fp32-denormals when there is option
+// -fcuda-flush-denormals-to-zero.
+
 // CHECK-LABEL: define void @foo() #0
 extern "C" __device__ void foo() {}
 
 // FTZ: attributes #0 = {{.*}} "nvptx-f32ftz"="true"
 // NOFTZ-NOT: attributes #0 = {{.*}} "nvptx-f32ftz"
+// AMDNOFTZ: attributes #0 = {{.*}}+fp32-denormals{{.*}}+fp64-fp16-denormals
+// AMDFTZ: attributes #0 = {{.*}}+fp64-fp16-denormals{{.*}}-fp32-denormals
 
 // FTZ:!llvm.module.flags = !{{{.*}}[[MODFLAG:![0-9]+]]}
 // FTZ:[[MODFLAG]] = !{i32 4, !"nvvm-reflect-ftz", i32 1}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -690,7 +690,9 @@
 Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
 Args.hasArg(OPT_cl_fast_relaxed_math));
   Opts.Reassociate = Args.hasArg(OPT_mreassociate);
-  Opts.FlushDenorm = Args.hasArg(OPT_cl_denorms_are_zero);
+  Opts.FlushDenorm = Args.hasArg(OPT_cl_denorms_are_zero) ||
+ (Args.hasArg(OPT_fcuda_is_device) &&
+  Args.hasArg(OPT_fcuda_flush_denormals_to_zero));
   Opts.CorrectlyRoundedDivSqrt =
   Args.hasArg(OPT_cl_fp32_correctly_rounded_divide_sqrt);
   Opts.UniformWGSize =


Index: test/CodeGenCUDA/flush-denormals.cu
===
--- test/CodeGenCUDA/flush-denormals.cu
+++ test/CodeGenCUDA/flush-denormals.cu
@@ -5,18 +5,33 @@
 // RUN:   -triple nvptx-nvidia-cuda -emit-llvm -o - %s | \
 // RUN:   FileCheck %s -check-prefix CHECK -check-prefix FTZ
 
+// RUN: %clang_cc1 -fcuda-is-device -x hip \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDNOFTZ
+// RUN: %clang_cc1 -fcuda-is-device -x hip -fcuda-flush-denormals-to-zero \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDFTZ
+
 #include "Inputs/cuda.h"
 
 // Checks that device function calls get emitted with the "ntpvx-f32ftz"
 // attribute set to "true" when we compile CUDA device code with
 // -fcuda-flush-denormals-to-zero.  Further, check that we reflect the presence
 // or absence of -fcuda-flush-denormals-to-zero in a module flag.
 
+// AMDGCN targets always have +fp64-fp16-denormals.
+// AMDGCN targets without fast FMAF (e.g. gfx803) always have +fp32-denormals.
+// For AMDGCN target with fast FMAF (e.g. gfx900), it has +fp32-denormals
+// by default and -fp32-denormals when there is option
+// -fcuda-flush-denormals-to-zero.
+
 // CHECK-LABEL: define void @foo() #0
 extern "C" __device__ void foo() {}
 
 // FTZ: attributes #0 = {{.*}} "nvptx-f32ftz"="true"
 // NOFTZ-NOT: attributes #0 = {{.*}} "nvptx-f32ftz"
+// AMDNOFTZ: attributes #0 = {{.*}}+fp32-denormals{{.*}}+fp64-fp16-denormals
+// AMDFTZ: attributes #0 = {{.*}}+fp64-fp16-denormals{{.*}}-fp32-denormals
 
 // FTZ:!llvm.module.flags = !{{{.*}}[[MODFLAG:![0-9]+]]}
 // FTZ:[[MODFLAG]] = !{i32 4, !"nvvm-reflect-ftz", i32 1}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -690,7 +690,9 @@
 Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
 Args.hasArg(OPT_cl_fast_relaxed_math));
  

[PATCH] D48285: [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag

2018-06-18 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov accepted this revision.
george.karpenkov added a comment.
This revision is now accepted and ready to land.

LGTM provided the nit on passing arguments is fixed.




Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:696
 void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
   auto Chk = Mgr.registerChecker();
   Chk->IsPedantic = Mgr.getAnalyzerOptions().getBooleanOption(

registerChecker passes through arguments to the constructor. Could we use that 
instead of mutable fields?


Repository:
  rC Clang

https://reviews.llvm.org/D48285



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


[PATCH] D48288: Fix a bug introduced by rL334850

2018-06-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D48288



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


[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-18 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:1248
+  bool RHSFixed = RHSType->isFixedPointType();
+
+  if (LHSFixed && RHSFixed) {

ebevhan wrote:
> ebevhan wrote:
> > leonardchan wrote:
> > > leonardchan wrote:
> > > > ebevhan wrote:
> > > > > ebevhan wrote:
> > > > > > leonardchan wrote:
> > > > > > > ebevhan wrote:
> > > > > > > > leonardchan wrote:
> > > > > > > > > ebevhan wrote:
> > > > > > > > > > I don't see how these semantics work properly. The 
> > > > > > > > > > specification requires that operations be done in the full 
> > > > > > > > > > precision of both types. You cannot convert the types 
> > > > > > > > > > before performing the operation like this, since the 
> > > > > > > > > > operation will not be done in full precision in that case.
> > > > > > > > > > 
> > > > > > > > > > The operator semantics of Embedded-C require the operand 
> > > > > > > > > > types of binary operators to be different. It's only when 
> > > > > > > > > > you've performed the operation that you are allowed to 
> > > > > > > > > > convert the result to the resulting type.
> > > > > > > > > Initially the idea was to convert both sides to fixed point 
> > > > > > > > > types, then perform standard binary operations between the 
> > > > > > > > > fixed point types.
> > > > > > > > > 
> > > > > > > > > For the example, a `fract * int` would have the int converted 
> > > > > > > > > to a fixed point type by left shifting it by the scale of the 
> > > > > > > > > fract, multiplying, then right shifting by the scale again to 
> > > > > > > > > get the resulting fract. The only unhandled thing is 
> > > > > > > > > overflow, but the precision of the fract remains the same. 
> > > > > > > > > The operands would also be casted up beforehand so there was 
> > > > > > > > > enough space to store the result, which was casted down back 
> > > > > > > > > to the original fract after performing the right shift by the 
> > > > > > > > > scale.
> > > > > > > > > 
> > > > > > > > > Operations between fixed point types would follow a similar 
> > > > > > > > > process of casting both operands to the higher rank fixed 
> > > > > > > > > point type, and depending on the operation, more underlying 
> > > > > > > > > shifting and casting would be done to retain full precision 
> > > > > > > > > of the higher ranked type.
> > > > > > > > > 
> > > > > > > > > Though I will admit that I did not realize until now that 
> > > > > > > > > multiplying a fixed point type by an integer does not require 
> > > > > > > > > shifting the integer.
> > > > > > > > I see how you've reasoned; this is how C normally works. The 
> > > > > > > > `fract` is of higher rank than `int` and therefore is the 
> > > > > > > > 'common type' of the operation. However, even though it is 
> > > > > > > > higher rank there is no guarantee that you can perform the 
> > > > > > > > operation without overflowing. And overflow matters here; the 
> > > > > > > > spec says that it must be done in the full precision (integral 
> > > > > > > > + fractional) of both types.
> > > > > > > > 
> > > > > > > > > The only unhandled thing is overflow, but the precision of 
> > > > > > > > > the fract remains the same. The operands would also be casted 
> > > > > > > > > up beforehand so there was enough space to store the result, 
> > > > > > > > > which was casted down back to the original fract after 
> > > > > > > > > performing the right shift by the scale.
> > > > > > > > 
> > > > > > > > The precision remains the same (and while it doesn't have to be 
> > > > > > > > the same to perform an operation, it makes the implementation 
> > > > > > > > more regular; things like addition and subtraction 'just 
> > > > > > > > work'), but you cannot perform a conversion to `fract` *before* 
> > > > > > > > the operation itself, since if you do, there's nothing to 'cast 
> > > > > > > > up'. Casting up is needed for things like `fract * fract` to 
> > > > > > > > prevent overflow, but for `fract * int` you need to cast to a 
> > > > > > > > type that can fit both all values of the int and all values of 
> > > > > > > > the fract, and *then* you can cast up before doing the 
> > > > > > > > multiplication.
> > > > > > > > 
> > > > > > > > > Operations between fixed point types would follow a similar 
> > > > > > > > > process of casting both operands to the higher rank fixed 
> > > > > > > > > point type, and depending on the operation, more underlying 
> > > > > > > > > shifting and casting would be done to retain full precision 
> > > > > > > > > of the higher ranked type.
> > > > > > > > 
> > > > > > > > This might work, but I feel there could be edge cases. The E-C 
> > > > > > > > fixed-point ranks are very odd as they don't reflect reality; 
> > > > > > > > `short _Accum` cannot be considered strictly 'above' `long 
> > > > > > > > _Fract`, but the former has a higher rank than the latter. 
> > > > > > > > Depending on how 

[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-18 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 151744.
leonardchan added a comment.

- Removed CK_IntegralToFixedPoint to be added to later patch addressing 
conversion
- Create CXString for FixedPointLiteral


Repository:
  rC Clang

https://reviews.llvm.org/D46915

Files:
  include/clang-c/Index.h
  include/clang/AST/ASTContext.h
  include/clang/AST/Expr.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TargetInfo.h
  include/clang/Driver/Options.td
  include/clang/Lex/LiteralSupport.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/AST/Type.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/LiteralSupport.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Frontend/fixed_point.c
  test/Frontend/fixed_point_bit_widths.c
  test/Frontend/fixed_point_declarations.c
  test/Frontend/fixed_point_errors.c
  test/Frontend/fixed_point_same_fbits.c
  tools/libclang/CIndex.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -305,6 +305,10 @@
 K = CXCursor_IntegerLiteral;
 break;
 
+  case Stmt::FixedPointLiteralClass:
+K = CXCursor_FixedPointLiteral;
+break;
+
   case Stmt::FloatingLiteralClass:
 K = CXCursor_FloatingLiteral;
 break;
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -5061,6 +5061,8 @@
 return cxstring::createRef("VariableRef");
   case CXCursor_IntegerLiteral:
   return cxstring::createRef("IntegerLiteral");
+  case CXCursor_FixedPointLiteral:
+  return cxstring::createRef("FixedPointLiteral");
   case CXCursor_FloatingLiteral:
   return cxstring::createRef("FloatingLiteral");
   case CXCursor_ImaginaryLiteral:
Index: test/Frontend/fixed_point_same_fbits.c
===
--- /dev/null
+++ test/Frontend/fixed_point_same_fbits.c
@@ -0,0 +1,28 @@
+// RUN: %clang -ffixed-point -S -emit-llvm -o - %s | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang -ffixed-point -fsame-fbits -S -emit-llvm -o - %s | FileCheck %s -check-prefix=SAME
+
+/* The scale for unsigned fixed point types should be the same as that of signed
+ * fixed point types when -fsame-fbits is enabled. */
+
+void func() {
+  unsigned short _Accum u_short_accum = 0.5uhk;
+  unsigned _Accum u_accum = 0.5uk;
+  unsigned long _Accum u_long_accum = 0.5ulk;
+  unsigned short _Fract u_short_fract = 0.5uhr;
+  unsigned _Fract u_fract = 0.5ur;
+  unsigned long _Fract u_long_fract = 0.5ulr;
+
+// DEFAULT: store i16 128, i16* %u_short_accum, align 2
+// DEFAULT: store i32 32768, i32* %u_accum, align 4
+// DEFAULT: store i64 2147483648, i64* %u_long_accum, align 8
+// DEFAULT: store i8  -128, i8* %u_short_fract, align 1
+// DEFAULT: store i16 -32768, i16* %u_fract, align 2
+// DEFAULT: store i32 -2147483648, i32* %u_long_fract, align 4
+
+// SAME: store i16 64, i16* %u_short_accum, align 2
+// SAME: store i32 16384, i32* %u_accum, align 4
+// SAME: store i64 1073741824, i64* %u_long_accum, align 8
+// SAME: store i8  64, i8* %u_short_fract, align 1
+// SAME: store i16 16384, i16* %u_fract, align 2
+// SAME: store i32 1073741824, i32* %u_long_fract, align 4
+}
Index: test/Frontend/fixed_point_errors.c
===
--- test/Frontend/fixed_point_errors.c
+++ test/Frontend/fixed_point_errors.c
@@ -13,7 +13,6 @@
 _Sat long long _Fract sat_longlong_fract; // expected-error{{'long long _Fract' is invalid}}
 _Sat unsigned long long _Fract sat_u_longlong_fract;  // expected-error{{'long long _Fract' is invalid}}
 
-
 /* Although _Complex types work with floating point numbers, the extension
  * provides no info for complex fixed point types. */
 
@@ -78,6 +77,50 @@
 _Sat int i;   // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'int'}}
 _Sat _Sat _Fract fract;   // expected-warning{{duplicate '_Sat' declaration specifier}}
 
+
+/* Literals that cannot fit into types */
+signed short _Accum s_short_accum = 256.0hk;// expected-error{{this value is too large for this fixed point type}}
+unsigned short _Accum u_short_accum = 256.0uhk; // expected-error{{this value is 

[PATCH] D48288: Fix a bug introduced by rL334850

2018-06-18 Thread Tomasz Krupa via Phabricator via cfe-commits
tkrupa created this revision.
tkrupa added a reviewer: itaraban.
Herald added a subscriber: cfe-commits.

All *_sqrt_round_s[s|d] intrinsics should execute a square root on zeroth 
element from B (Ops[1]) and insert in to A (Ops[0]), not the other way around.


Repository:
  rC Clang

https://reviews.llvm.org/D48288

Files:
  lib/CodeGen/CGBuiltin.cpp


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -9907,15 +9907,15 @@
   Intrinsic::x86_avx512_mask_sqrt_ss;
   return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
 }
-Value *A = Builder.CreateExtractElement(Ops[0], (uint64_t)0);
+Value *A = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
 Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
 Value *Src = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
 int MaskSize = Ops[3]->getType()->getScalarSizeInBits();
 llvm::Type *MaskTy = llvm::VectorType::get(Builder.getInt1Ty(), MaskSize);
 Value *Mask = Builder.CreateBitCast(Ops[3], MaskTy);
 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
 A = Builder.CreateSelect(Mask, Builder.CreateCall(F, {A}), Src);
-return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
+return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
   }
   case X86::BI__builtin_ia32_sqrtpd256:
   case X86::BI__builtin_ia32_sqrtpd:


Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -9907,15 +9907,15 @@
   Intrinsic::x86_avx512_mask_sqrt_ss;
   return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
 }
-Value *A = Builder.CreateExtractElement(Ops[0], (uint64_t)0);
+Value *A = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
 Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
 Value *Src = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
 int MaskSize = Ops[3]->getType()->getScalarSizeInBits();
 llvm::Type *MaskTy = llvm::VectorType::get(Builder.getInt1Ty(), MaskSize);
 Value *Mask = Builder.CreateBitCast(Ops[3], MaskTy);
 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
 A = Builder.CreateSelect(Mask, Builder.CreateCall(F, {A}), Src);
-return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
+return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
   }
   case X86::BI__builtin_ia32_sqrtpd256:
   case X86::BI__builtin_ia32_sqrtpd:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48241: [DebugInfo] Emit ObjC methods as part of interface.

2018-06-18 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

In https://reviews.llvm.org/D48241#1134985, @labath wrote:

> This is not true. (Unlike the .apple_*** tables, ) .debug_names allows you to 
> specify a different schema for every entry in the acelerator table. The 
> schema is specifing using abbreviations in much the same way as .debug_abbrev 
> specifies the schema for .debug_info. So you could easily have one 
> abbreviation for regular classes, and a different one for objc interfaces. 
> Currently, our .debug_names generator does not support these kinds of 
> heterogeneous tables, but that's simply because I had no use for it. It could 
> be added if necessary (though it will require some 
> generalization/refactoring). OTOH, our consumer should already be able to 
> handle these kinds of tables as input.


Indeed, you are correct, I was thinking about the Apple structure with the 
atoms and forgot about the abbreviation in each entries for DWARF. Thanks for 
pointing this out!


https://reviews.llvm.org/D48241



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


r334962 - [OPENMP, NVPTX] Emit simple reduction if requested.

2018-06-18 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jun 18 10:11:45 2018
New Revision: 334962

URL: http://llvm.org/viewvc/llvm-project?rev=334962&view=rev
Log:
[OPENMP, NVPTX] Emit simple reduction if requested.

If simple reduction is requested, use the simple reduction instead of
the runtime functions calls.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=334962&r1=334961&r2=334962&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Mon Jun 18 10:11:45 2018
@@ -3163,6 +3163,12 @@ void CGOpenMPRuntimeNVPTX::emitReduction
   assert((TeamsReduction || ParallelReduction || SimdReduction) &&
  "Invalid reduction selection in emitReduction.");
 
+  if (Options.SimpleReduction) {
+CGOpenMPRuntime::emitReduction(CGF, Loc, Privates, LHSExprs, RHSExprs,
+   ReductionOps, Options);
+return;
+  }
+
   ASTContext &C = CGM.getContext();
 
   // 1. Build a list of reduction variables.

Modified: cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp?rev=334962&r1=334961&r2=334962&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp Mon Jun 18 10:11:45 2018
@@ -78,9 +78,8 @@ int bar(int n){
 // CHECK: call void @__kmpc_kernel_init(i32 %{{.+}}, i16 1)
 // CHECK-NOT: call void @__kmpc_for_static_init
 // CHECK-NOT: call void @__kmpc_for_static_fini
-// CHECK: [[RES:%.+]] = call i32 @__kmpc_nvptx_simd_reduce_nowait(i32 %{{.+}}, 
i32 1, i{{64|32}} {{8|4}}, i8* %{{.+}}, void (i8*, i16, i16, i16)* @{{.+}}, 
void (i8*, i32)* @{{.+}})
-// CHECK: switch i32 [[RES]]
-// CHECK: call void @__kmpc_nvptx_end_reduce_nowait(i32 %{{.+}})
+// CHECK-NOT: call i32 @__kmpc_nvptx_simd_reduce_nowait(
+// CHECK-NOT: call void @__kmpc_nvptx_end_reduce_nowait(
 // CHECK: call void @__kmpc_kernel_deinit(i16 1)
 // CHECK: ret void
 


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


[PATCH] D48287: [HIP] Support -fcuda-flush-denormals-to-zero for amdgcn

2018-06-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: b-sumner, tra.
yaxunl added a reviewer: scchan.

https://reviews.llvm.org/D48287

Files:
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenCUDA/flush-denormals.cu


Index: test/CodeGenCUDA/flush-denormals.cu
===
--- test/CodeGenCUDA/flush-denormals.cu
+++ test/CodeGenCUDA/flush-denormals.cu
@@ -5,6 +5,13 @@
 // RUN:   -triple nvptx-nvidia-cuda -emit-llvm -o - %s | \
 // RUN:   FileCheck %s -check-prefix CHECK -check-prefix FTZ
 
+// RUN: %clang_cc1 -fcuda-is-device -x hip \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDNOFTZ
+// RUN: %clang_cc1 -fcuda-is-device -x hip -fcuda-flush-denormals-to-zero \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDFTZ
+
 #include "Inputs/cuda.h"
 
 // Checks that device function calls get emitted with the "ntpvx-f32ftz"
@@ -12,11 +19,17 @@
 // -fcuda-flush-denormals-to-zero.  Further, check that we reflect the presence
 // or absence of -fcuda-flush-denormals-to-zero in a module flag.
 
+// AMDGCN targets always have +fp64-fp16-denormals.
+// For AMDGCN target with fast FMAF (e.g. gfx900), it has +fp32-denormals
+// by default and -fp32-denormals when there is option -fcuda-is-device.
+
 // CHECK-LABEL: define void @foo() #0
 extern "C" __device__ void foo() {}
 
 // FTZ: attributes #0 = {{.*}} "nvptx-f32ftz"="true"
 // NOFTZ-NOT: attributes #0 = {{.*}} "nvptx-f32ftz"
+// AMDNOFTZ: attributes #0 = {{.*}}+fp32-denormals{{.*}}+fp64-fp16-denormals
+// AMDFTZ: attributes #0 = {{.*}}+fp64-fp16-denormals{{.*}}-fp32-denormals
 
 // FTZ:!llvm.module.flags = !{{{.*}}[[MODFLAG:![0-9]+]]}
 // FTZ:[[MODFLAG]] = !{i32 4, !"nvvm-reflect-ftz", i32 1}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -690,7 +690,9 @@
 Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
 Args.hasArg(OPT_cl_fast_relaxed_math));
   Opts.Reassociate = Args.hasArg(OPT_mreassociate);
-  Opts.FlushDenorm = Args.hasArg(OPT_cl_denorms_are_zero);
+  Opts.FlushDenorm = Args.hasArg(OPT_cl_denorms_are_zero) ||
+ (Args.hasArg(OPT_fcuda_is_device) &&
+  Args.hasArg(OPT_fcuda_flush_denormals_to_zero));
   Opts.CorrectlyRoundedDivSqrt =
   Args.hasArg(OPT_cl_fp32_correctly_rounded_divide_sqrt);
   Opts.UniformWGSize =


Index: test/CodeGenCUDA/flush-denormals.cu
===
--- test/CodeGenCUDA/flush-denormals.cu
+++ test/CodeGenCUDA/flush-denormals.cu
@@ -5,6 +5,13 @@
 // RUN:   -triple nvptx-nvidia-cuda -emit-llvm -o - %s | \
 // RUN:   FileCheck %s -check-prefix CHECK -check-prefix FTZ
 
+// RUN: %clang_cc1 -fcuda-is-device -x hip \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDNOFTZ
+// RUN: %clang_cc1 -fcuda-is-device -x hip -fcuda-flush-denormals-to-zero \
+// RUN:   -triple amdgcn-amd-amdhsa -target-cpu gfx900 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s -check-prefix CHECK -check-prefix AMDFTZ
+
 #include "Inputs/cuda.h"
 
 // Checks that device function calls get emitted with the "ntpvx-f32ftz"
@@ -12,11 +19,17 @@
 // -fcuda-flush-denormals-to-zero.  Further, check that we reflect the presence
 // or absence of -fcuda-flush-denormals-to-zero in a module flag.
 
+// AMDGCN targets always have +fp64-fp16-denormals.
+// For AMDGCN target with fast FMAF (e.g. gfx900), it has +fp32-denormals
+// by default and -fp32-denormals when there is option -fcuda-is-device.
+
 // CHECK-LABEL: define void @foo() #0
 extern "C" __device__ void foo() {}
 
 // FTZ: attributes #0 = {{.*}} "nvptx-f32ftz"="true"
 // NOFTZ-NOT: attributes #0 = {{.*}} "nvptx-f32ftz"
+// AMDNOFTZ: attributes #0 = {{.*}}+fp32-denormals{{.*}}+fp64-fp16-denormals
+// AMDFTZ: attributes #0 = {{.*}}+fp64-fp16-denormals{{.*}}-fp32-denormals
 
 // FTZ:!llvm.module.flags = !{{{.*}}[[MODFLAG:![0-9]+]]}
 // FTZ:[[MODFLAG]] = !{i32 4, !"nvvm-reflect-ftz", i32 1}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -690,7 +690,9 @@
 Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
 Args.hasArg(OPT_cl_fast_relaxed_math));
   Opts.Reassociate = Args.hasArg(OPT_mreassociate);
-  Opts.FlushDenorm = Args.hasArg(OPT_cl_denorms_are_zero);
+  Opts.FlushDenorm = Args.hasArg(OPT_cl_denorms_are_zero) ||
+ (Args.hasArg(OPT_fcuda_is_device) &&
+  Args.hasArg(OPT_fcuda_flush_de

[PATCH] D47687: [Sema] Missing -Wlogical-op-parentheses warnings in macros (PR18971)

2018-06-18 Thread Xing via Phabricator via cfe-commits
Higuoxing updated this revision to Diff 151736.
Higuoxing added a comment.

test case has been passed


https://reviews.llvm.org/D47687

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/parentheses.c


Index: test/Sema/parentheses.c
===
--- test/Sema/parentheses.c
+++ test/Sema/parentheses.c
@@ -14,6 +14,10 @@
   if ((i = 4)) {}
 }
 
+#define VOID_CAST(cond) ( (void)(cond) )
+#define APPLY_OPS(op0, op1, x, y, z) ( VOID_CAST(x op0 y op1 z) )
+#define APPLY_OPS_DIRECTLY(op0, op1, x, y, z) ( (void)(x op0 y op1 z) )
+
 void bitwise_rel(unsigned i) {
   (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} 
\
 // expected-note{{place parentheses around the '==' 
expression to silence this warning}} \
@@ -96,6 +100,22 @@
 
   (void)(i && i || 0); // no warning.
   (void)(0 || i && i); // no warning.
+
+  VOID_CAST(i && i || i);   // expected-warning {{'&&' within '||'}} \
+// expected-note {{place parentheses around the 
'&&' expression to silence this warning}}
+
+  APPLY_OPS_DIRECTLY(&&, ||, i, i, i); // no warning.
+  APPLY_OPS(&&, ||, i, i, i);  // no warning.
+
+  APPLY_OPS_DIRECTLY(&&, ||, i, i, i || i && i);   // expected-warning {{'&&' 
within '||'}} \
+   // expected-note {{place 
parentheses around the '&&' expression to silence this warning}}
+  APPLY_OPS(&&, ||, i, i, i || i && i);// no warning.
+
+  APPLY_OPS_DIRECTLY(&&, ||, i, i, i && i); // no warning.
+  APPLY_OPS_DIRECTLY(&&, ||, i, i, i || i); // no warning.
+
+  APPLY_OPS(&&, ||, i, i, i && i); // no warning.
+  APPLY_OPS(&&, ||, i, i, i || i); // no warning.
 }
 
 _Bool someConditionFunc();
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12233,6 +12233,35 @@
   }
 }
 
+/// Look for '&&' in the righ or left hand side of a '||' expr
+static void DiagnoseLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc,
+  Expr *LHSExpr, Expr *RHSExpr) {
+  SourceManager &SM = Self.getSourceManager();
+  if (!OpLoc.isMacroID()) {
+DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
+DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
+return;
+  }
+
+  // Diagnose parentheses, if and only if operator and its LHS, RHS
+  // are from the same argument position of first level macros
+  SourceLocation OpExpansionLoc;
+  if (!SM.isMacroArgExpansion(OpLoc, &OpExpansionLoc) ||
+  SM.getImmediateMacroCallerLoc(OpLoc).isMacroID())
+return;
+
+  SourceLocation ExprExpansionLoc;
+  if (SM.isMacroArgExpansion(LHSExpr->getExprLoc(), &ExprExpansionLoc) &&
+  OpExpansionLoc == ExprExpansionLoc &&
+  !SM.getImmediateMacroCallerLoc(LHSExpr->getExprLoc()).isMacroID())
+DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
+
+  if (SM.isMacroArgExpansion(RHSExpr->getExprLoc(), &ExprExpansionLoc) &&
+  OpExpansionLoc == ExprExpansionLoc &&
+  !SM.getImmediateMacroCallerLoc(RHSExpr->getExprLoc()).isMacroID())
+DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
+}
+
 /// Look for bitwise op in the left or right hand of a bitwise op with
 /// lower precedence and emit a diagnostic together with a fixit hint that 
wraps
 /// the '&' expression in parentheses.
@@ -12310,10 +12339,8 @@
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
   // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
-DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
-DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
-  }
+  if (Opc == BO_LOr)
+DiagnoseLogicalAndInLogicalOr(Self, OpLoc, LHSExpr, RHSExpr);
 
   if ((Opc == BO_Shl && 
LHSExpr->getType()->isIntegralType(Self.getASTContext()))
   || Opc == BO_Shr) {


Index: test/Sema/parentheses.c
===
--- test/Sema/parentheses.c
+++ test/Sema/parentheses.c
@@ -14,6 +14,10 @@
   if ((i = 4)) {}
 }
 
+#define VOID_CAST(cond) ( (void)(cond) )
+#define APPLY_OPS(op0, op1, x, y, z) ( VOID_CAST(x op0 y op1 z) )
+#define APPLY_OPS_DIRECTLY(op0, op1, x, y, z) ( (void)(x op0 y op1 z) )
+
 void bitwise_rel(unsigned i) {
   (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \
 // expected-note{{place parentheses around the '==' expression to silence this warning}} \
@@ -96,6 +100,22 @@
 
   (void)(i && i || 0); // no warning.
   (void)(0 || i && i); // no warning.
+
+  VOID_CAST(i && i || i);   // expected-warning {{'&&' within '||'}} \
+// expected-note {{place parentheses around the '&&' expression to silence this warning}}
+
+  APPLY_OPS_DIRECTLY(&&, ||, i, 

[PATCH] D48285: [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag

2018-06-18 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs, 
whisperity.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet.

For Plist consumers that don't support notes just yet, this flag can be used to 
convert them into warnings. For now, I defaulted it to false.


Repository:
  rC Clang

https://reviews.llvm.org/D48285

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp

Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -10,10 +10,19 @@
 // This file defines a checker that reports uninitialized fields in objects
 // created after a constructor call.
 //
-// This checker has an option "Pedantic" (boolean). If its not set or is set to
-// false, the checker won't emit warnings for objects that don't have at least
-// one initialized field. This may be set with
-// `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.
+// This checker has two options:
+//   - "Pedantic" (boolean). If its not set or is set to false, the checker
+// won't emit warnings for objects that don't have at least one initialized
+// field. This may be set with
+//
+//  `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.
+//
+//   - "NotesAsWarnings" (boolean). If set to true, the checker will emit a
+// warning for each uninitalized field, as opposed to emitting one warning
+// per constructor call, and listing the uninitialized fields that belongs
+// to it in notes. Defaults to false.
+//
+//  `-analyzer-config alpha.cplusplus.UninitializedObject:NotesAsWarnings=true`.
 //
 //===--===//
 
@@ -32,7 +41,9 @@
   std::unique_ptr BT_uninitField;
 
 public:
-  bool IsPedantic; // Will be initialized when registering the checker.
+  // These fields will be initialized when registering the checker.
+  bool IsPedantic;
+  bool ShouldConvertNotesToWarnings;
 
   UninitializedObjectChecker()
   : BT_uninitField(new BuiltinBug(this, "Uninitialized fields")) {}
@@ -216,6 +227,9 @@
   return T->isBuiltinType() || T->isEnumeralType();
 }
 
+/// Constructs a note message for a given FieldChainInfo object.
+void printNoteMessage(llvm::raw_ostream &Out, const FieldChainInfo &Chain);
+
 } // end of anonymous namespace
 
 //===--===//
@@ -264,6 +278,23 @@
 LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
 CallSite, Context.getSourceManager(), Node->getLocationContext());
 
+  // For Plist consumers that don't support notes just yet, we'll convert notes
+  // to warnings.
+  if (ShouldConvertNotesToWarnings) {
+for (const auto &Chain : UninitFields) {
+  SmallString<100> WarningBuf;
+  llvm::raw_svector_ostream WarningOS(WarningBuf);
+
+  printNoteMessage(WarningOS, Chain);
+
+  auto Report = llvm::make_unique(
+  *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
+  Node->getLocationContext()->getDecl());
+  Context.emitReport(std::move(Report));
+}
+return;
+  }
+
   SmallString<100> WarningBuf;
   llvm::raw_svector_ostream WarningOS(WarningBuf);
   WarningOS << UninitFields.size() << " uninitialized field"
@@ -274,29 +305,16 @@
   *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
   Node->getLocationContext()->getDecl());
 
-  // TODO: As of now, one warning is emitted per constructor call, and the
-  // uninitialized fields are listed in notes. Until there's a better support
-  // for notes avaible, a note-less version of this checker should be
-  // implemented.
-  for (const auto &FieldChain : UninitFields) {
+  for (const auto &Chain : UninitFields) {
 SmallString<200> NoteBuf;
 llvm::raw_svector_ostream NoteOS(NoteBuf);
 
-if (FieldChain.isPointer()) {
-  if (FieldChain.isDereferenced())
-NoteOS << "uninitialized pointee 'this->";
-  else
-NoteOS << "uninitialized pointer 'this->";
-} else
-  NoteOS << "uninitialized field 'this->";
-FieldChain.print(NoteOS);
-NoteOS << "'";
+printNoteMessage(NoteOS, Chain);
 
 Report->addNote(NoteOS.str(),
-PathDiagnosticLocation::create(FieldChain.getEndOfChain(),
+PathDiagnosticLocation::create(Chain.getEndOfChain(),
Context.getSourceManager()));
   }
-
   Context.emitReport(std::move(Report));
 }
 
@@ -660,10 +678,24 @@
   return false;
 }
 
+void printNoteMessage(llvm::raw_ostream &Out, const FieldChainInfo &Chain) {
+  if (Chain.isPointer()) {
+if (Chain.isDereferenced())
+  Out << "uninitialized pointee 'this->";
+else
+  Out << "uninitialized pointer 'this

[PATCH] D47687: [Sema] Missing -Wlogical-op-parentheses warnings in macros (PR18971)

2018-06-18 Thread Xing via Phabricator via cfe-commits
Higuoxing added a comment.

In https://reviews.llvm.org/D47687#1135284, @dexonsmith wrote:

> Did you miss this comment from my previous review?
>
> > I would like to see tests like the following:
> > 
> >   NESTING_VOID_WRAPPER(&&, ||, i, i, i && i); // no warning.
> >   NESTING_VOID_WRAPPER(||, &&, i, i, i || i); // no warning.


I think this test case should pass, please wait
I cloned a newer version codes, and I am compiling it... about 1-2 hours

Sorry for disturbing you too much on reviewing codes

I think I could give it a try on giving it a fix-it...

Big thanks!


https://reviews.llvm.org/D47687



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


[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

We should probably just leave them around. Leave a NOTE so they don't get 
deleted.


https://reviews.llvm.org/D45616



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


[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2018-06-18 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

I added extra assertion into the test for the difference. Interestingly, it 
also works if I assert `n-m` is in the range instead of `m-n`.


https://reviews.llvm.org/D35110



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


[PATCH] D46190: For a referenced declaration, mark any associated usings as referenced.

2018-06-18 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Style comments.
The two new Sema methods (for namespaces and using references) are C++ 
specific, so SemaDeclCXX.cpp would seem like a more appropriate home for them.




Comment at: lib/Sema/Sema.cpp:1879
+void Sema::MarkNamespaceAliasReferenced(NamedDecl *ND) {
+  if (ND && !ND->isReferenced()) {
+NamespaceAliasDecl *NA = nullptr;

You could do this as an early return and reduce indentation in the rest of the 
method.
```
if (!ND || ND->isReferenced())
  return;
```




Comment at: lib/Sema/Sema.cpp:1880
+  if (ND && !ND->isReferenced()) {
+NamespaceAliasDecl *NA = nullptr;
+while ((NA = dyn_cast(ND)) && !NA->isReferenced()) {

Initializing this to nullptr is redundant, as you set NA in the while-loop 
expression.



Comment at: lib/Sema/Sema.cpp:1891
+/// \brief Mark as referenced any 'using declaration' that have introduced
+/// the given declaration in the current context.
+void Sema::MarkUsingReferenced(Decl *D, CXXScopeSpec *SS, Expr *E) {

`\brief` is unnecessary, as we have auto-brief turned on.



Comment at: lib/Sema/Sema.cpp:1903
+  if (auto *NNS = SS ? SS->getScopeRep()
+ : E ? dyn_cast(E)->getQualifier()
+ : nullptr) {

This dyn_cast<> can be simply a cast<>.



Comment at: lib/Sema/Sema.cpp:1916
+  if ((USD = dyn_cast(DR)) && !USD->isReferenced()) {
+if (USD->getTargetDecl() == D) {
+  USD->setReferenced();

You could sink the declaration of USD like so:
```
for (auto *DR : S->decls())
  if (auto *USD = dyn_cast(DR))
if (!USD->isReferenced() && USD->getTargetDecl() == D) {
```
Also I would put braces around the 'for' loop body, even though it is 
technically one statement.



Comment at: lib/Sema/Sema.cpp:1927
+// Check if the declaration was introduced by a 'using-directive'.
+auto *Target = dyn_cast(DC);
+for (auto *UD : S->using_directives())

You verified that his is a namespace earlier, so use cast<> not dyn_cast<>.


https://reviews.llvm.org/D46190



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


[PATCH] D47687: [Sema] Missing -Wlogical-op-parentheses warnings in macros (PR18971)

2018-06-18 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Did you miss this comment from my previous review?

> I would like to see tests like the following:
> 
>   NESTING_VOID_WRAPPER(&&, ||, i, i, i && i); // no warning.
>   NESTING_VOID_WRAPPER(||, &&, i, i, i || i); // no warning.






Comment at: lib/Sema/SemaExpr.cpp:12254-12255
+if (SM.isMacroArgExpansion(LHSExpr->getExprLoc(), &ExprExpansionLoc) &&
+!SM.getImmediateMacroCallerLoc(LHSExpr->getExprLoc()).isMacroID() &&
+OpExpansionLoc == ExprExpansionLoc)
+  DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);

Can you reverse these two checks?  The second one looks cheaper.



Comment at: lib/Sema/SemaExpr.cpp:12243
+DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
+  } else {
+SourceLocation OpExpansionLoc;

dexonsmith wrote:
> You can reduce nesting below by adding an early return above this.
> 
> I also think you should describe at a high-level what you're trying to do in 
> the code that follows.  Something like:
> ```
> // Only diagnose operators in macros if they're from the same argument 
> position.
> ```
You added an early return -- but then you didn't actually reduce the nesting.  
Please remove the else that follows.



Comment at: test/Sema/parentheses.c:114
+  NON_NESTING_VOID_0(i && i || i); // expected-warning {{'&&' within '||'}} \
+   // expected-note {{place parentheses around 
the '&&' expression to silence this warning}}
+  NON_NESTING_VOID_0((i && i) || i); // no warning.

Higuoxing wrote:
> Higuoxing wrote:
> > dexonsmith wrote:
> > > Can you add fix-it CHECKs?
> > ```
> > llvm/tools/clang/test/Sema/parentheses.c:109:15: note: place parentheses 
> > around the '&&' expression to silence this warning
> >   VOID_CAST(i && i || i); // expected-warning {{'&&' within '||'}} \
> > ~~^~~~
> > llvm/tools/clang/test/Sema/parentheses.c:17:34: note: expanded from macro 
> > 'VOID_CAST'
> > #define VOID_CAST(cond) ( (void)(cond) )
> >  ^~~~
> > ```
> > 
> > Sorry, it seems that when deal with expressions in macros, there is no 
> > fix-it hint ...
> The `suggestParentheses` suppress the fix-it hint when the expression is in 
> macros
> 
> ```
>   if (ParenRange.getBegin().isFileID() && ParenRange.getEnd().isFileID() &&
>   EndLoc.isValid()) {
> Self.Diag(Loc, Note)
>   << FixItHint::CreateInsertion(ParenRange.getBegin(), "(")
>   << FixItHint::CreateInsertion(EndLoc, ")");
>   } else {
> // We can't display the parentheses, so just show the bare note.
> Self.Diag(Loc, Note) << ParenRange;
>   }
> ```
> 
> You see, there is a `isFileID()`
Can you make it work?  The diagnostic was disabled because it was low quality: 
no fix-it, and firing when it was not actionable.  I'm not convinced we should 
turn it back on until we can give a fix-it.


https://reviews.llvm.org/D47687



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


[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2018-06-18 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 151720.
baloghadamsoftware added a comment.

-(-2^n) == -2^n


https://reviews.llvm.org/D35110

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  test/Analysis/constraint_manager_negate_difference.c
  test/Analysis/ptr-arith.c

Index: test/Analysis/ptr-arith.c
===
--- test/Analysis/ptr-arith.c
+++ test/Analysis/ptr-arith.c
@@ -265,49 +265,26 @@
   clang_analyzer_eval((rhs - lhs) > 0); // expected-warning{{TRUE}}
 }
 
-//---
-// False positives
-//---
-
 void zero_implies_reversed_equal(int *lhs, int *rhs) {
   clang_analyzer_eval((rhs - lhs) == 0); // expected-warning{{UNKNOWN}}
   if ((rhs - lhs) == 0) {
-#ifdef ANALYZER_CM_Z3
 clang_analyzer_eval(rhs != lhs); // expected-warning{{FALSE}}
 clang_analyzer_eval(rhs == lhs); // expected-warning{{TRUE}}
-#else
-clang_analyzer_eval(rhs != lhs); // expected-warning{{UNKNOWN}}
-clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-#endif
 return;
   }
   clang_analyzer_eval((rhs - lhs) == 0); // expected-warning{{FALSE}}
-#ifdef ANALYZER_CM_Z3
   clang_analyzer_eval(rhs == lhs); // expected-warning{{FALSE}}
   clang_analyzer_eval(rhs != lhs); // expected-warning{{TRUE}}
-#else
-  clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(rhs != lhs); // expected-warning{{UNKNOWN}}
-#endif
 }
 
 void canonical_equal(int *lhs, int *rhs) {
   clang_analyzer_eval(lhs == rhs); // expected-warning{{UNKNOWN}}
   if (lhs == rhs) {
-#ifdef ANALYZER_CM_Z3
 clang_analyzer_eval(rhs == lhs); // expected-warning{{TRUE}}
-#else
-clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-#endif
 return;
   }
   clang_analyzer_eval(lhs == rhs); // expected-warning{{FALSE}}
-
-#ifdef ANALYZER_CM_Z3
   clang_analyzer_eval(rhs == lhs); // expected-warning{{FALSE}}
-#else
-  clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-#endif
 }
 
 void compare_element_region_and_base(int *p) {
Index: test/Analysis/constraint_manager_negate_difference.c
===
--- /dev/null
+++ test/Analysis/constraint_manager_negate_difference.c
@@ -0,0 +1,77 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin -analyzer-config aggressive-relational-comparison-simplification=true -verify %s
+
+void clang_analyzer_eval(int);
+
+void exit(int);
+
+#define UINT_MAX (~0U)
+#define INT_MAX (UINT_MAX & (UINT_MAX >> 1))
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+unsigned int __line, __const char *__function)
+ __attribute__ ((__noreturn__));
+#define assert(expr) \
+  ((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+void assert_in_range(int x) {
+  assert(x <= ((int)INT_MAX / 4));
+  assert(x >= -(((int)INT_MAX) / 4));
+}
+
+void assert_in_wide_range(int x) {
+  assert(x <= ((int)INT_MAX / 2));
+  assert(x >= -(((int)INT_MAX) / 2));
+}
+
+void assert_in_range_2(int m, int n) {
+  assert_in_range(m);
+  assert_in_range(n);
+}
+
+void equal(int m, int n) {
+  assert_in_range_2(m, n);
+  if (m != n)
+return;
+  assert_in_wide_range(m - n);
+  clang_analyzer_eval(n == m); // expected-warning{{TRUE}}
+}
+
+void non_equal(int m, int n) {
+  assert_in_range_2(m, n);
+  if (m == n)
+return;
+  assert_in_wide_range(m - n);
+  clang_analyzer_eval(n != m); // expected-warning{{TRUE}}
+}
+
+void less_or_equal(int m, int n) {
+  assert_in_range_2(m, n);
+  if (m < n)
+return;
+  assert_in_wide_range(m - n);
+  clang_analyzer_eval(n <= m); // expected-warning{{TRUE}}
+}
+
+void less(int m, int n) {
+  assert_in_range_2(m, n);
+  if (m <= n)
+return;
+  assert_in_wide_range(m - n);
+  clang_analyzer_eval(n < m); // expected-warning{{TRUE}}
+}
+
+void greater_or_equal(int m, int n) {
+  assert_in_range_2(m, n);
+  if (m > n)
+return;
+  assert_in_wide_range(m - n);
+  clang_analyzer_eval(n >= m); // expected-warning{{TRUE}}
+}
+
+void greater(int m, int n) {
+  assert_in_range_2(m, n);
+  if (m >= n)
+return;
+  assert_in_wide_range(m - n);
+  clang_analyzer_eval(n > m); // expected-warning{{TRUE}}
+}
Index: lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -174,6 +174,34 @@
   return newRanges;
 }
 
+// Turn all [A, B] ranges to [-B, -A]. Turn minimal signed value to maximal
+// signed value.
+RangeSet RangeSet::Negate(BasicValueFactory &BV, Factory &F) const {
+  PrimRangeSet newRanges = F.getEmptySet();
+
+  for (iterator i = begin(), e = end(); i != e; ++i) {
+const llvm::APSInt &from = i->From(), &to = i->To();
+   

[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-18 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:1248
+  bool RHSFixed = RHSType->isFixedPointType();
+
+  if (LHSFixed && RHSFixed) {

leonardchan wrote:
> leonardchan wrote:
> > ebevhan wrote:
> > > ebevhan wrote:
> > > > leonardchan wrote:
> > > > > ebevhan wrote:
> > > > > > leonardchan wrote:
> > > > > > > ebevhan wrote:
> > > > > > > > I don't see how these semantics work properly. The 
> > > > > > > > specification requires that operations be done in the full 
> > > > > > > > precision of both types. You cannot convert the types before 
> > > > > > > > performing the operation like this, since the operation will 
> > > > > > > > not be done in full precision in that case.
> > > > > > > > 
> > > > > > > > The operator semantics of Embedded-C require the operand types 
> > > > > > > > of binary operators to be different. It's only when you've 
> > > > > > > > performed the operation that you are allowed to convert the 
> > > > > > > > result to the resulting type.
> > > > > > > Initially the idea was to convert both sides to fixed point 
> > > > > > > types, then perform standard binary operations between the fixed 
> > > > > > > point types.
> > > > > > > 
> > > > > > > For the example, a `fract * int` would have the int converted to 
> > > > > > > a fixed point type by left shifting it by the scale of the fract, 
> > > > > > > multiplying, then right shifting by the scale again to get the 
> > > > > > > resulting fract. The only unhandled thing is overflow, but the 
> > > > > > > precision of the fract remains the same. The operands would also 
> > > > > > > be casted up beforehand so there was enough space to store the 
> > > > > > > result, which was casted down back to the original fract after 
> > > > > > > performing the right shift by the scale.
> > > > > > > 
> > > > > > > Operations between fixed point types would follow a similar 
> > > > > > > process of casting both operands to the higher rank fixed point 
> > > > > > > type, and depending on the operation, more underlying shifting 
> > > > > > > and casting would be done to retain full precision of the higher 
> > > > > > > ranked type.
> > > > > > > 
> > > > > > > Though I will admit that I did not realize until now that 
> > > > > > > multiplying a fixed point type by an integer does not require 
> > > > > > > shifting the integer.
> > > > > > I see how you've reasoned; this is how C normally works. The 
> > > > > > `fract` is of higher rank than `int` and therefore is the 'common 
> > > > > > type' of the operation. However, even though it is higher rank 
> > > > > > there is no guarantee that you can perform the operation without 
> > > > > > overflowing. And overflow matters here; the spec says that it must 
> > > > > > be done in the full precision (integral + fractional) of both types.
> > > > > > 
> > > > > > > The only unhandled thing is overflow, but the precision of the 
> > > > > > > fract remains the same. The operands would also be casted up 
> > > > > > > beforehand so there was enough space to store the result, which 
> > > > > > > was casted down back to the original fract after performing the 
> > > > > > > right shift by the scale.
> > > > > > 
> > > > > > The precision remains the same (and while it doesn't have to be the 
> > > > > > same to perform an operation, it makes the implementation more 
> > > > > > regular; things like addition and subtraction 'just work'), but you 
> > > > > > cannot perform a conversion to `fract` *before* the operation 
> > > > > > itself, since if you do, there's nothing to 'cast up'. Casting up 
> > > > > > is needed for things like `fract * fract` to prevent overflow, but 
> > > > > > for `fract * int` you need to cast to a type that can fit both all 
> > > > > > values of the int and all values of the fract, and *then* you can 
> > > > > > cast up before doing the multiplication.
> > > > > > 
> > > > > > > Operations between fixed point types would follow a similar 
> > > > > > > process of casting both operands to the higher rank fixed point 
> > > > > > > type, and depending on the operation, more underlying shifting 
> > > > > > > and casting would be done to retain full precision of the higher 
> > > > > > > ranked type.
> > > > > > 
> > > > > > This might work, but I feel there could be edge cases. The E-C 
> > > > > > fixed-point ranks are very odd as they don't reflect reality; 
> > > > > > `short _Accum` cannot be considered strictly 'above' `long _Fract`, 
> > > > > > but the former has a higher rank than the latter. Depending on how 
> > > > > > the types are specified for a target, implicit casts between 
> > > > > > fixed-point types might inadvertantly discard bits, even though the 
> > > > > > spec says that operations must be done in full precision.
> > > > > I see, so just to confirm, something like a `fract * int` would not 
> > > > > result in any implicit casting between either operand, but any 
> > > > > special a

[PATCH] D47670: [analyzer] [NFC] Remove unused Extensive diagnostic setting, rename AlternateExtensive to Extensive.

2018-06-18 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: lib/StaticAnalyzer/Core/BugReporter.cpp:2613
+  jj++;
+  assert(jj<10);
   // Get a clean copy of all the visitors.

Was this meant to be committed? I see this assertion firing on a ton of files.


Repository:
  rC Clang

https://reviews.llvm.org/D47670



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


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-18 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

Ping.  This can significantly improve compile time for projects that use the 
common /Yc /Yu PCH mechanism.


https://reviews.llvm.org/D46652



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


[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-18 Thread Gabor Buella via Phabricator via cfe-commits
GBuella updated this revision to Diff 151710.

https://reviews.llvm.org/D45616

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/avx-builtins.c
  test/CodeGen/avx-cmp-builtins.c
  test/CodeGen/avx2-builtins.c
  test/CodeGen/avx512f-builtins.c
  test/CodeGen/avx512vl-builtins.c

Index: test/CodeGen/avx512vl-builtins.c
===
--- test/CodeGen/avx512vl-builtins.c
+++ test/CodeGen/avx512vl-builtins.c
@@ -1073,53 +1073,168 @@
 
 __mmask8 test_mm256_cmp_ps_mask(__m256 __A, __m256 __B) {
   // CHECK-LABEL: @test_mm256_cmp_ps_mask
-  // CHECK: call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256
+  // CHECK: fcmp oeq <8 x float> %{{.*}}, %{{.*}}
   return (__mmask8)_mm256_cmp_ps_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm256_cmp_ps_mask_true_uq(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_true_us(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_false_oq(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_false_os(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_FALSE_OS);
+}
+
 __mmask8 test_mm256_mask_cmp_ps_mask(__mmask8 m, __m256 __A, __m256 __B) {
   // CHECK-LABEL: @test_mm256_mask_cmp_ps_mask
-  // CHECK: [[CMP:%.*]] = call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256
-  // CHECK: and <8 x i1> [[CMP]], {{.*}}
+  // CHECK: fcmp oeq <8 x float> %{{.*}}, %{{.*}}
+  // CHECK: and <8 x i1> %{{.*}}, %{{.*}}
   return _mm256_mask_cmp_ps_mask(m, __A, __B, 0);
 }
 
 __mmask8 test_mm_cmp_ps_mask(__m128 __A, __m128 __B) {
   // CHECK-LABEL: @test_mm_cmp_ps_mask
-  // CHECK: call <4 x i1> @llvm.x86.avx512.mask.cmp.ps.128
+  // CHECK: fcmp oeq <4 x float> %{{.*}}, %{{.*}}
   return (__mmask8)_mm_cmp_ps_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm_cmp_ps_mask_true_uq(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm_cmp_ps_mask_true_us(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm_cmp_ps_mask_false_oq(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm_cmp_ps_mask_false_os(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_FALSE_OS);
+}
+
 __mmask8 test_mm_mask_cmp_ps_mask(__mmask8 m, __m128 __A, __m128 __B) {
   // CHECK-LABEL: @test_mm_mask_cmp_ps_mask
-  // CHECK: [[CMP:%.*]] = call <4 x i1> @llvm.x86.avx512.mask.cmp.ps.128
-  // CHECK: and <4 x i1> [[CMP]], {{.*}}
+  // CHECK: fcmp oeq <4 x float> %{{.*}}, %{{.*}}
+  // CHECK: shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <4 x i32> 
+  // CHECK: and <4 x i1> %{{.*}}, %{{.*}}
   return _mm_mask_cmp_ps_mask(m, __A, __B, 0);
 }
 
 __mmask8 test_mm256_cmp_pd_mask(__m256d __A, __m256d __B) {
   // CHECK-LABEL: @test_mm256_cmp_pd_mask
-  // CHECK: call <4 x i1> @llvm.x86.avx512.mask.cmp.pd.256
+  // CHECK: fcmp oeq <4 x double> %{{.*}}, %{{.*}}
   return (__mmask8)_mm256_cmp_pd_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm256_cmp_pd_mask_true_uq(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_true_us(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_false_oq(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_false_os(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_FALSE_OS);
+}
+
 __mmask8 test_mm256_mask_cmp_pd_mask(__mmask8 m, __m256d __A, __m256d __B) {
   // CHECK-

[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-18 Thread Gabor Buella via Phabricator via cfe-commits
GBuella added a comment.

The question still left is, should we remove, auto upgrade the LLVM intrinsics 
not used anymore, or keep them around for when the signal behaviour is going to 
matter?


https://reviews.llvm.org/D45616



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


[libunwind] r334936 - Update copyright year to 2018.

2018-06-18 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Mon Jun 18 05:22:17 2018
New Revision: 334936

URL: http://llvm.org/viewvc/llvm-project?rev=334936&view=rev
Log:
Update copyright year to 2018.

Modified:
libunwind/trunk/LICENSE.TXT

Modified: libunwind/trunk/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/LICENSE.TXT?rev=334936&r1=334935&r2=334936&view=diff
==
--- libunwind/trunk/LICENSE.TXT (original)
+++ libunwind/trunk/LICENSE.TXT Mon Jun 18 05:22:17 2018
@@ -14,7 +14,7 @@ Full text of the relevant licenses is in
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2009-2017 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2018 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 


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


r334936 - Update copyright year to 2018.

2018-06-18 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Mon Jun 18 05:22:17 2018
New Revision: 334936

URL: http://llvm.org/viewvc/llvm-project?rev=334936&view=rev
Log:
Update copyright year to 2018.

Modified:
cfe/trunk/LICENSE.TXT
cfe/trunk/tools/clang-format-vs/ClangFormat/license.txt

Modified: cfe/trunk/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/LICENSE.TXT?rev=334936&r1=334935&r2=334936&view=diff
==
--- cfe/trunk/LICENSE.TXT (original)
+++ cfe/trunk/LICENSE.TXT Mon Jun 18 05:22:17 2018
@@ -4,7 +4,7 @@ LLVM Release License
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2007-2016 University of Illinois at Urbana-Champaign.
+Copyright (c) 2007-2018 University of Illinois at Urbana-Champaign.
 All rights reserved.
 
 Developed by:

Modified: cfe/trunk/tools/clang-format-vs/ClangFormat/license.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/ClangFormat/license.txt?rev=334936&r1=334935&r2=334936&view=diff
==
--- cfe/trunk/tools/clang-format-vs/ClangFormat/license.txt (original)
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/license.txt Mon Jun 18 05:22:17 
2018
@@ -4,7 +4,7 @@ LLVM Release License
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2007-2017 University of Illinois at Urbana-Champaign.
+Copyright (c) 2007-2018 University of Illinois at Urbana-Champaign.
 All rights reserved.
 
 Developed by:


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


[libclc] r334936 - Update copyright year to 2018.

2018-06-18 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Mon Jun 18 05:22:17 2018
New Revision: 334936

URL: http://llvm.org/viewvc/llvm-project?rev=334936&view=rev
Log:
Update copyright year to 2018.

Modified:
libclc/trunk/LICENSE.TXT

Modified: libclc/trunk/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/LICENSE.TXT?rev=334936&r1=334935&r2=334936&view=diff
==
--- libclc/trunk/LICENSE.TXT (original)
+++ libclc/trunk/LICENSE.TXT Mon Jun 18 05:22:17 2018
@@ -11,7 +11,7 @@ Full text of the relevant licenses is in
 
 ==
 
-Copyright (c) 2011-2016 by the contributors listed in CREDITS.TXT
+Copyright (c) 2011-2018 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 


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


[clang-tools-extra] r334936 - Update copyright year to 2018.

2018-06-18 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Mon Jun 18 05:22:17 2018
New Revision: 334936

URL: http://llvm.org/viewvc/llvm-project?rev=334936&view=rev
Log:
Update copyright year to 2018.

Modified:
clang-tools-extra/trunk/LICENSE.TXT
clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/license.txt

Modified: clang-tools-extra/trunk/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/LICENSE.TXT?rev=334936&r1=334935&r2=334936&view=diff
==
--- clang-tools-extra/trunk/LICENSE.TXT (original)
+++ clang-tools-extra/trunk/LICENSE.TXT Mon Jun 18 05:22:17 2018
@@ -4,7 +4,7 @@ LLVM Release License
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2007-2016 University of Illinois at Urbana-Champaign.
+Copyright (c) 2007-2018 University of Illinois at Urbana-Champaign.
 All rights reserved.
 
 Developed by:

Modified: clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/license.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/license.txt?rev=334936&r1=334935&r2=334936&view=diff
==
--- clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/license.txt (original)
+++ clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/license.txt Mon Jun 18 
05:22:17 2018
@@ -4,7 +4,7 @@ LLVM Release License
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2007-2016 University of Illinois at Urbana-Champaign.
+Copyright (c) 2007-2018 University of Illinois at Urbana-Champaign.
 All rights reserved.
 
 Developed by:


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


[libcxxabi] r334936 - Update copyright year to 2018.

2018-06-18 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Mon Jun 18 05:22:17 2018
New Revision: 334936

URL: http://llvm.org/viewvc/llvm-project?rev=334936&view=rev
Log:
Update copyright year to 2018.

Modified:
libcxxabi/trunk/LICENSE.TXT

Modified: libcxxabi/trunk/LICENSE.TXT
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/LICENSE.TXT?rev=334936&r1=334935&r2=334936&view=diff
==
--- libcxxabi/trunk/LICENSE.TXT (original)
+++ libcxxabi/trunk/LICENSE.TXT Mon Jun 18 05:22:17 2018
@@ -14,7 +14,7 @@ Full text of the relevant licenses is in
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2009-2017 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2018 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 


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


[PATCH] D47814: Teach libc++ to use native NetBSD's max_align_t

2018-06-18 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D47814



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


[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-06-18 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334935: [analyzer] Checker for uninitialized C++ objects 
(authored by Szelethus, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D45532

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/Inputs/system-header-simulator-for-cxx-uninitialized-object.h
  test/Analysis/cxx-uninitialized-object-inheritance.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -92,6 +92,7 @@
   UndefResultChecker.cpp
   UndefinedArraySubscriptChecker.cpp
   UndefinedAssignmentChecker.cpp
+  UninitializedObjectChecker.cpp
   UnixAPIChecker.cpp
   UnreachableCodeChecker.cpp
   VforkChecker.cpp
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -0,0 +1,669 @@
+//===- UninitializedObjectChecker.cpp *- C++ -*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file defines a checker that reports uninitialized fields in objects
+// created after a constructor call.
+//
+// This checker has an option "Pedantic" (boolean). If its not set or is set to
+// false, the checker won't emit warnings for objects that don't have at least
+// one initialized field. This may be set with
+// `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include 
+
+using namespace clang;
+using namespace clang::ento;
+
+namespace {
+
+class UninitializedObjectChecker : public Checker {
+  std::unique_ptr BT_uninitField;
+
+public:
+  bool IsPedantic; // Will be initialized when registering the checker.
+
+  UninitializedObjectChecker()
+  : BT_uninitField(new BuiltinBug(this, "Uninitialized fields")) {}
+  void checkEndFunction(CheckerContext &C) const;
+};
+
+llvm::ImmutableListFactory Factory;
+
+/// Represents a field chain. A field chain is a vector of fields where the
+/// first element of the chain is the object under checking (not stored), and
+/// every other element is a field, and the element that precedes it is the
+/// object that contains it.
+///
+/// Note that this class is immutable, and new fields may only be added through
+/// constructor calls.
+class FieldChainInfo {
+  using FieldChain = llvm::ImmutableList;
+
+  FieldChain Chain;
+
+  const bool IsDereferenced = false;
+
+public:
+  FieldChainInfo() = default;
+
+  FieldChainInfo(const FieldChainInfo &Other, const bool IsDereferenced)
+  : Chain(Other.Chain), IsDereferenced(IsDereferenced) {}
+
+  FieldChainInfo(const FieldChainInfo &Other, const FieldRegion *FR,
+ const bool IsDereferenced = false);
+
+  bool contains(const FieldRegion *FR) const { return Chain.contains(FR); }
+  bool isPointer() const;
+
+  /// If this is a fieldchain whose last element is an uninitialized region of a
+  /// pointer type, `IsDereferenced` will store whether the pointer itself or
+  /// the pointee is uninitialized.
+  bool isDereferenced() const;
+  const FieldDecl *getEndOfChain() const;
+  void print(llvm::raw_ostream &Out) const;
+
+private:
+  /// Prints every element except the last to `Out`. Since ImmutableLists store
+  /// elements in reverse order, and have no reverse iterators, we use a
+  /// recursive function to print the fieldchain correctly. The last element in
+  /// the chain is to be printed by `print`.
+  static void printTail(llvm::raw_ostream &Out,
+const llvm::ImmutableListImpl *L);
+  friend struct FieldChainInfoComparator;
+};
+
+struct FieldChainInfoComparator {
+  bool operator()(const FieldChainInfo &lhs, const FieldChainInfo &rhs) {
+assert(!lhs.Chain.isEmpty() && !rhs.Chain.isEmpty() &&
+   "Attempted to store an empty fieldchain!");
+return *lhs.Chain.begin() < *rhs.Chain.begin();
+  }
+};
+
+using UninitFieldSet = std::set;
+
+/// Searches for and stores uninitialized fields in a non-union object.
+class FindUninitializedFields {
+  Program

r334935 - [analyzer] Checker for uninitialized C++ objects

2018-06-18 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Mon Jun 18 04:50:17 2018
New Revision: 334935

URL: http://llvm.org/viewvc/llvm-project?rev=334935&view=rev
Log:
[analyzer] Checker for uninitialized C++ objects

This checker analyzes C++ constructor calls, and reports uninitialized fields.

Due to the nature of this problem (uninitialized fields after an object
construction), this checker doesn't search for bugs, but rather is a tool to
enforce a specific programming model where every field needs to be initialized.

This checker lands in alpha for now, and a number of followup patches will be
made to reduce false negatives and to make it easier for the user to understand
what rules the checker relies on, eg. whether a derived class' constructor is
responsible for initializing inherited data members or whether it should be
handled in the base class' constructor.

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp

cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-cxx-uninitialized-object.h
cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=334935&r1=334934&r2=334935&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Mon Jun 18 
04:50:17 2018
@@ -319,6 +319,10 @@ def MisusedMovedObjectChecker: Checker<"
   "object will be reported">,
  DescFile<"MisusedMovedObjectChecker.cpp">;
 
+def UninitializedObjectChecker: Checker<"UninitializedObject">,
+ HelpText<"Reports uninitialized fields after object construction">,
+ DescFile<"UninitializedObjectChecker.cpp">;
+
 } // end: "alpha.cplusplus"
 
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=334935&r1=334934&r2=334935&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Mon Jun 18 04:50:17 
2018
@@ -92,6 +92,7 @@ add_clang_library(clangStaticAnalyzerChe
   UndefResultChecker.cpp
   UndefinedArraySubscriptChecker.cpp
   UndefinedAssignmentChecker.cpp
+  UninitializedObjectChecker.cpp
   UnixAPIChecker.cpp
   UnreachableCodeChecker.cpp
   VforkChecker.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp?rev=334935&view=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp Mon 
Jun 18 04:50:17 2018
@@ -0,0 +1,669 @@
+//===- UninitializedObjectChecker.cpp *- C++ 
-*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file defines a checker that reports uninitialized fields in objects
+// created after a constructor call.
+//
+// This checker has an option "Pedantic" (boolean). If its not set or is set to
+// false, the checker won't emit warnings for objects that don't have at least
+// one initialized field. This may be set with
+// `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include 
+
+using namespace clang;
+using namespace clang::ento;
+
+namespace {
+
+class UninitializedObjectChecker : public Checker {
+  std::unique_ptr BT_uninitField;
+
+public:
+  bool IsPedantic; // Will be initialized when registering the checker.
+
+  UninitializedObjectChecker()
+  : BT_uninitField(new BuiltinBug(this, "Uninitialized fields")) {}
+  void checkEndFunction(CheckerContext &C) const;
+};
+
+llvm::ImmutableListFactory Factory;
+
+/// Represents a field chain. A field chain is a vector of fields where 

[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-06-18 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 151685.
Szelethus added a comment.

Whoo! Thank you all for helping me with the reviews. Very excited about the 
upcoming fixes, I have some neat ideas for some already.

- Rebased to 8186139d6aa0619e2057ae617c074e486a7b2f2b (revision 334929),
- Added a `FIXME` around base class handling as a reminder that this topic 
still needs to be discussed,
- Re-run tests on some projects just to be sure.


https://reviews.llvm.org/D45532

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/Inputs/system-header-simulator-for-cxx-uninitialized-object.h
  test/Analysis/cxx-uninitialized-object-inheritance.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- /dev/null
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -0,0 +1,1058 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -std=c++11 -DPEDANTIC -verify %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject -std=c++11 -verify %s
+
+//===--===//
+// Default constructor test.
+//===--===//
+
+class CompilerGeneratedConstructorTest {
+  int a, b, c, d, e, f, g, h, i, j;
+
+public:
+  CompilerGeneratedConstructorTest() = default;
+};
+
+void fCompilerGeneratedConstructorTest() {
+  CompilerGeneratedConstructorTest();
+}
+
+#ifdef PEDANTIC
+class DefaultConstructorTest {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void fDefaultConstructorTest() {
+  DefaultConstructorTest(); // expected-warning{{1 uninitialized field}}
+}
+#else
+class DefaultConstructorTest {
+  int a;
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void fDefaultConstructorTest() {
+  DefaultConstructorTest();
+}
+#endif // PEDANTIC
+
+//===--===//
+// Initializer list test.
+//===--===//
+
+class InitListTest1 {
+  int a;
+  int b;
+
+public:
+  InitListTest1()
+  : a(1),
+b(2) {
+// All good!
+  }
+};
+
+void fInitListTest1() {
+  InitListTest1();
+}
+
+class InitListTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  InitListTest2()
+  : a(3) {} // expected-warning{{1 uninitialized field}}
+};
+
+void fInitListTest2() {
+  InitListTest2();
+}
+
+class InitListTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  InitListTest3()
+  : b(4) {} // expected-warning{{1 uninitialized field}}
+};
+
+void fInitListTest3() {
+  InitListTest3();
+}
+
+//===--===//
+// Constructor body test.
+//===--===//
+
+class CtorBodyTest1 {
+  int a, b;
+
+public:
+  CtorBodyTest1() {
+a = 5;
+b = 6;
+// All good!
+  }
+};
+
+void fCtorBodyTest1() {
+  CtorBodyTest1();
+}
+
+class CtorBodyTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest2() {
+a = 7; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void fCtorBodyTest2() {
+  CtorBodyTest2();
+}
+
+class CtorBodyTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  CtorBodyTest3() {
+b = 8; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void fCtorBodyTest3() {
+  CtorBodyTest3();
+}
+
+#ifdef PEDANTIC
+class CtorBodyTest4 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest4() {}
+};
+
+void fCtorBodyTest4() {
+  CtorBodyTest4(); // expected-warning{{2 uninitialized fields}}
+}
+#else
+class CtorBodyTest4 {
+  int a;
+  int b;
+
+public:
+  CtorBodyTest4() {}
+};
+
+void fCtorBodyTest4() {
+  CtorBodyTest4();
+}
+#endif
+
+//===--===//
+// Constructor delegation test.
+//===--===//
+
+class CtorDelegationTest1 {
+  int a;
+  int b;
+
+public:
+  CtorDelegationTest1(int)
+  : a(9) {
+// leaves 'b' unintialized, but we'll never check this function
+  }
+
+  CtorDelegationTest1()
+  : CtorDelegationTest1(int{}) { // Initializing 'a'
+b = 10;
+ 

[PATCH] D48242: [ASTMatchers] Add support for matching the type of a friend decl.

2018-06-18 Thread David L. Jones via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334930: [ASTMatchers] Add support for matching the type of a 
friend decl. (authored by dlj, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48242?vs=151593&id=151671#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48242

Files:
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
  cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -38,6 +38,7 @@
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -120,10 +121,14 @@
 inline QualType getUnderlyingType(const ValueDecl &Node) {
   return Node.getType();
 }
-
 inline QualType getUnderlyingType(const TypedefNameDecl &Node) {
   return Node.getUnderlyingType();
 }
+inline QualType getUnderlyingType(const FriendDecl &Node) {
+  if (const TypeSourceInfo *TSI = Node.getFriendType())
+return TSI->getType();
+  return QualType();
+}
 
 /// Unifies obtaining the FunctionProtoType pointer from both
 /// FunctionProtoType and FunctionDecl nodes..
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -2860,13 +2860,17 @@
 /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")
 /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")
 /// and U (matcher = typedefDecl(hasType(asString("int")))
+/// and friend class X (matcher = friendDecl(hasType("X"))
 /// \code
 ///  class X {};
 ///  void y(X &x) { x; X z; }
 ///  typedef int U;
+///  class Y { friend class X; };
 /// \endcode
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
-hasType, AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, TypedefNameDecl, ValueDecl),
+hasType,
+AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, TypedefNameDecl,
+ValueDecl),
 internal::Matcher, InnerMatcher, 0) {
   QualType QT = internal::getUnderlyingType(Node);
   if (!QT.isNull())
@@ -2885,18 +2889,21 @@
 ///
 /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")
 /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")
+/// and friend class X (matcher = friendDecl(hasType("X"))
 /// \code
 ///  class X {};
 ///  void y(X &x) { x; X z; }
+///  class Y { friend class X; };
 /// \endcode
 ///
 /// Usable as: Matcher, Matcher
-AST_POLYMORPHIC_MATCHER_P_OVERLOAD(hasType,
-   AST_POLYMORPHIC_SUPPORTED_TYPES(Expr,
-   ValueDecl),
-   internal::Matcher, InnerMatcher, 1) {
-  return qualType(hasDeclaration(InnerMatcher))
-  .matches(Node.getType(), Finder, Builder);
+AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
+hasType, AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, ValueDecl),
+internal::Matcher, InnerMatcher, 1) {
+  QualType QT = internal::getUnderlyingType(Node);
+  if (!QT.isNull())
+return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder);
+  return false;
 }
 
 /// Matches if the type location of the declarator decl's type matches
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -160,6 +160,16 @@
   valueDecl(hasType(asString("void (void)");
 }
 
+TEST(FriendDecl, Matches) {
+  EXPECT_TRUE(matches("class Y { friend class X; };",
+  friendDecl(hasType(asString("class X");
+  EXPECT_TRUE(matches("class Y { friend class X; };",
+  friendDecl(hasType(recordDecl(hasName("X"));
+
+  EXPECT_TRUE(matches("class Y { friend void f(); };",
+  functionDecl(hasName("f"), hasParent(friendDecl();
+}
+
 TEST(Enum, DoesNotMatchClasses) {
   EXPECT_TRUE(notMatches("class X {};", enumDecl(hasName("X";
 }


Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -38,6 +38,7 @@
 #include "clang/AST/ASTTypeTraits.h"

r334930 - [ASTMatchers] Add support for matching the type of a friend decl.

2018-06-18 Thread David L. Jones via cfe-commits
Author: dlj
Date: Mon Jun 18 02:23:08 2018
New Revision: 334930

URL: http://llvm.org/viewvc/llvm-project?rev=334930&view=rev
Log:
[ASTMatchers] Add support for matching the type of a friend decl.

This allows matchers like:

  friendDecl(hasType(cxxRecordDecl(...)))
  friendDecl(hasType(asString(...)))

It seems that hasType is probably the most reasonable narrowing matcher to
overload, since it is already used to narrow to other declaration kinds.

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

Reviewers: klimek, aaron.ballman

Subscribers: cfe-commits

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=334930&r1=334929&r2=334930&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Jun 18 02:23:08 2018
@@ -2860,13 +2860,17 @@ AST_MATCHER_P_OVERLOAD(CallExpr, callee,
 /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")
 /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")
 /// and U (matcher = typedefDecl(hasType(asString("int")))
+/// and friend class X (matcher = friendDecl(hasType("X"))
 /// \code
 ///  class X {};
 ///  void y(X &x) { x; X z; }
 ///  typedef int U;
+///  class Y { friend class X; };
 /// \endcode
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
-hasType, AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, TypedefNameDecl, ValueDecl),
+hasType,
+AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, TypedefNameDecl,
+ValueDecl),
 internal::Matcher, InnerMatcher, 0) {
   QualType QT = internal::getUnderlyingType(Node);
   if (!QT.isNull())
@@ -2885,18 +2889,21 @@ AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
 ///
 /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")
 /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")
+/// and friend class X (matcher = friendDecl(hasType("X"))
 /// \code
 ///  class X {};
 ///  void y(X &x) { x; X z; }
+///  class Y { friend class X; };
 /// \endcode
 ///
 /// Usable as: Matcher, Matcher
-AST_POLYMORPHIC_MATCHER_P_OVERLOAD(hasType,
-   AST_POLYMORPHIC_SUPPORTED_TYPES(Expr,
-   ValueDecl),
-   internal::Matcher, InnerMatcher, 1) {
-  return qualType(hasDeclaration(InnerMatcher))
-  .matches(Node.getType(), Finder, Builder);
+AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
+hasType, AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, ValueDecl),
+internal::Matcher, InnerMatcher, 1) {
+  QualType QT = internal::getUnderlyingType(Node);
+  if (!QT.isNull())
+return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder);
+  return false;
 }
 
 /// Matches if the type location of the declarator decl's type matches

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=334930&r1=334929&r2=334930&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Mon Jun 18 
02:23:08 2018
@@ -38,6 +38,7 @@
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -120,10 +121,14 @@ inline QualType getUnderlyingType(const
 inline QualType getUnderlyingType(const ValueDecl &Node) {
   return Node.getType();
 }
-
 inline QualType getUnderlyingType(const TypedefNameDecl &Node) {
   return Node.getUnderlyingType();
 }
+inline QualType getUnderlyingType(const FriendDecl &Node) {
+  if (const TypeSourceInfo *TSI = Node.getFriendType())
+return TSI->getType();
+  return QualType();
+}
 
 /// Unifies obtaining the FunctionProtoType pointer from both
 /// FunctionProtoType and FunctionDecl nodes..

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=334930&r1=334929&r2=334930&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Mon Jun 18 02:23:08 
2018
@@ -160,6 +160,16 @@ TEST(ValueDecl, Matches) {
   

[PATCH] D48242: [ASTMatchers] Add support for matching the type of a friend decl.

2018-06-18 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.

lg, thx


Repository:
  rC Clang

https://reviews.llvm.org/D48242



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


[PATCH] D48242: [ASTMatchers] Add support for matching the type of a friend decl.

2018-06-18 Thread David L. Jones via Phabricator via cfe-commits
dlj added a comment.

Ping for Manuel...


Repository:
  rC Clang

https://reviews.llvm.org/D48242



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


[PATCH] D48241: [DebugInfo] Emit ObjC methods as part of interface.

2018-06-18 Thread Pavel Labath via Phabricator via cfe-commits
labath added a comment.

I also don't want to get involved too much, but here are my 2c: :)

In https://reviews.llvm.org/D48241#1134342, @JDevlieghere wrote:

> Putting it in a separate column is also a bad idea, because that means the 
> column is present for all the entries, including the ones that don't need it.


This is not true. (Unlike the .apple_*** tables, ) .debug_names allows you to 
specify a different schema for every entry in the acelerator table. The schema 
is specifing using abbreviations in much the same way as .debug_abbrev 
specifies the schema for .debug_info. So you could easily have one abbreviation 
for regular classes, and a different one for objc interfaces. Currently, our 
.debug_names generator does not support these kinds of heterogeneous tables, 
but that's simply because I had no use for it. It could be added if necessary 
(though it will require some generalization/refactoring). OTOH, our consumer 
should already be able to handle these kinds of tables as input.

That said, I like this approach more than the putting that information in the 
accel table. :)




Comment at: clang/test/CodeGenObjC/debug-info-category.m:35-37
+// DWARF5: !DISubprogram(name: "-[Foo integer]", scope: ![[STRUCT]], 
{{.*}}isDefinition: false
+// DWARF5: !DISubprogram(name: "-[Foo integer:]", scope: ![[STRUCT]], 
{{.*}}isDefinition: false
+// DWARF5: !DISubprogram(name: "-[Foo(Bar) add:]", scope: ![[STRUCT]], 
{{.*}}isDefinition: false

Would it make sense to remove the interface part from the method name. When 
these were freestanding, they were necessary as they were the only link between 
the method and the interface, but now they are kind of redundant.

This is just an idea, I have no idea what kinds of havoc it will cause for 
existing consumers, but it seems to me it would make the objc methods more 
consistent with regular c++ methods.


https://reviews.llvm.org/D48241



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


r334929 - [ASTMatchers] Don't assert-fail in specifiesTypeLoc().

2018-06-18 Thread David L. Jones via cfe-commits
Author: dlj
Date: Mon Jun 18 01:59:16 2018
New Revision: 334929

URL: http://llvm.org/viewvc/llvm-project?rev=334929&view=rev
Log:
[ASTMatchers] Don't assert-fail in specifiesTypeLoc().

The specifiesTypeLoc() matcher narrows a nestedNameSpecifier matcher based on a
typeloc within the NNS. However, the matcher does not guard against NNS which
are a namespace, and cause getTypeLoc to assert-fail.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=334929&r1=334928&r2=334929&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Jun 18 01:59:16 2018
@@ -5536,7 +5536,8 @@ AST_MATCHER_P(NestedNameSpecifier, speci
 ///   matches "A::"
 AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
   internal::Matcher, InnerMatcher) {
-  return Node && InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+  return Node && Node.getNestedNameSpecifier()->getAsType() &&
+ InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
 }
 
 /// Matches on the prefix of a \c NestedNameSpecifier.

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=334929&r1=334928&r2=334929&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Mon Jun 18 01:59:16 
2018
@@ -1450,6 +1450,10 @@ TEST(NNS, MatchesNestedNameSpecifierPref
 "struct A { struct B { struct C {}; }; }; A::B::C c;",
 nestedNameSpecifierLoc(hasPrefix(
   specifiesTypeLoc(loc(qualType(asString("struct A";
+  EXPECT_TRUE(matches(
+"namespace N { struct A { struct B { struct C {}; }; }; } N::A::B::C c;",
+nestedNameSpecifierLoc(hasPrefix(
+  specifiesTypeLoc(loc(qualType(asString("struct N::A";
 }
 
 


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


[PATCH] D48269: [ASTMatchers] Don't assert-fail in specifiesTypeLoc().

2018-06-18 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.

lg, thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D48269



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


[PATCH] D48269: [ASTMatchers] Don't assert-fail in specifiesTypeLoc().

2018-06-18 Thread David L. Jones via Phabricator via cfe-commits
dlj created this revision.
dlj added a reviewer: klimek.
dlj added a project: clang.
Herald added a subscriber: cfe-commits.

The specifiesTypeLoc() matcher narrows a nestedNameSpecifier matcher based on a
typeloc within the NNS. However, the matcher does not guard against NNS which
are a namespace, and cause getTypeLoc to assert-fail.


Repository:
  rC Clang

https://reviews.llvm.org/D48269

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1450,6 +1450,10 @@
 "struct A { struct B { struct C {}; }; }; A::B::C c;",
 nestedNameSpecifierLoc(hasPrefix(
   specifiesTypeLoc(loc(qualType(asString("struct A";
+  EXPECT_TRUE(matches(
+"namespace N { struct A { struct B { struct C {}; }; }; } N::A::B::C c;",
+nestedNameSpecifierLoc(hasPrefix(
+  specifiesTypeLoc(loc(qualType(asString("struct N::A";
 }
 
 
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5536,7 +5536,8 @@
 ///   matches "A::"
 AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
   internal::Matcher, InnerMatcher) {
-  return Node && InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+  return Node && Node.getNestedNameSpecifier()->getAsType() &&
+ InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
 }
 
 /// Matches on the prefix of a \c NestedNameSpecifier.


Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1450,6 +1450,10 @@
 "struct A { struct B { struct C {}; }; }; A::B::C c;",
 nestedNameSpecifierLoc(hasPrefix(
   specifiesTypeLoc(loc(qualType(asString("struct A";
+  EXPECT_TRUE(matches(
+"namespace N { struct A { struct B { struct C {}; }; }; } N::A::B::C c;",
+nestedNameSpecifierLoc(hasPrefix(
+  specifiesTypeLoc(loc(qualType(asString("struct N::A";
 }
 
 
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5536,7 +5536,8 @@
 ///   matches "A::"
 AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
   internal::Matcher, InnerMatcher) {
-  return Node && InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+  return Node && Node.getNestedNameSpecifier()->getAsType() &&
+ InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
 }
 
 /// Matches on the prefix of a \c NestedNameSpecifier.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-06-18 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 151666.
baloghadamsoftware added a comment.

New warning message, more detailed docs.


https://reviews.llvm.org/D33537

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tidy/bugprone/ExceptionEscapeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-exception-escape.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-exception-escape.cpp

Index: test/clang-tidy/bugprone-exception-escape.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-exception-escape.cpp
@@ -0,0 +1,265 @@
+// RUN: %check_clang_tidy %s bugprone-exception-escape %t -- -extra-arg=-std=c++11 -config="{CheckOptions: [{key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, {key: bugprone-exception-escape.FunctionsThatShouldNotThrow, value: 'enabled1,enabled2,enabled3'}]}" --
+
+struct throwing_destructor {
+  ~throwing_destructor() {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function '~throwing_destructor' which should not throw exceptions
+throw 1;
+  }
+};
+
+struct throwing_move_constructor {
+  throwing_move_constructor(throwing_move_constructor&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'throwing_move_constructor' which should not throw exceptions
+throw 1;
+  }
+};
+
+struct throwing_move_assignment {
+  throwing_move_assignment& operator=(throwing_move_assignment&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: an exception may be thrown in function 'operator=' which should not throw exceptions
+throw 1;
+  }
+};
+
+void throwing_noexcept() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_noexcept' which should not throw exceptions
+  throw 1;
+}
+
+void throwing_throw_nothing() throw() {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
+  throw 1;
+}
+
+void throw_and_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch' which should not throw exceptions
+  try {
+throw 1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_some(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch_some' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_each(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch_each' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(double &) {
+  }
+}
+
+void throw_and_catch_all(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch_all' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(...) {
+  }
+}
+
+void throw_and_rethrow() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_rethrow' which should not throw exceptions
+  try {
+throw 1;
+  } catch(int &) {
+throw;
+  }
+}
+
+void throw_catch_throw() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_throw' which should not throw exceptions
+  try {
+throw 1;
+  } catch(int &) {
+throw 2;
+  }
+}
+
+void throw_catch_rethrow_the_rest(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_rethrow_the_rest' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(...) {
+throw;
+  }
+}
+
+class base {};
+class derived: public base {};
+
+void throw_derived_catch_base() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base' which should not throw exceptions
+  try {
+throw derived();
+  } catch(base &) {
+  }
+}
+
+void try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'try_nested_try' which should not throw exceptions
+  try {
+try {
+  if (n) throw 1;
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void bad_try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'bad_try_nested_try' which should not throw exceptions
+  try {
+if (n) throw 1;
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void try_nested_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[

[PATCH] D47687: [Sema] Missing -Wlogical-op-parentheses warnings in macros (PR18971)

2018-06-18 Thread Xing via Phabricator via cfe-commits
Higuoxing updated this revision to Diff 151661.
Higuoxing marked 12 inline comments as done.
Higuoxing removed a reviewer: echristo.

https://reviews.llvm.org/D47687

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/parentheses.c


Index: test/Sema/parentheses.c
===
--- test/Sema/parentheses.c
+++ test/Sema/parentheses.c
@@ -14,6 +14,10 @@
   if ((i = 4)) {}
 }
 
+#define VOID_CAST(cond) ( (void)(cond) )
+#define APPLY_OPS(op0, op1, x, y, z) ( VOID_CAST(x op0 y op1 z) )
+#define APPLY_OPS_DIRECTLY(op0, op1, x, y, z) ( (void)(x op0 y op1 z) )
+
 void bitwise_rel(unsigned i) {
   (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} 
\
 // expected-note{{place parentheses around the '==' 
expression to silence this warning}} \
@@ -96,6 +100,18 @@
 
   (void)(i && i || 0); // no warning.
   (void)(0 || i && i); // no warning.
+
+  VOID_CAST(i && i || i);   // expected-warning {{'&&' within '||'}} \
+// expected-note {{place parentheses around the 
'&&' expression to silence this warning}}
+  VOID_CAST((i && i) || i); // no warning.
+
+  APPLY_OPS_DIRECTLY(&&, ||, i, i, i); // no warning.
+  APPLY_OPS(&&, ||, i, i, i);  // no warning.
+
+  APPLY_OPS_DIRECTLY(&&, ||, i, i, i || i && i);   // expected-warning {{'&&' 
within '||'}} \
+   // expected-note {{place 
parentheses around the '&&' expression to silence this warning}}
+  APPLY_OPS_DIRECTLY(&&, ||, i, i, i || (i && i)); // no warning.
+  APPLY_OPS(&&, ||, i, i, i || i && i);// no warning.
 }
 
 _Bool someConditionFunc();
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12233,6 +12233,35 @@
   }
 }
 
+/// Look for '&&' in the righ or left hand side of a '||' expr
+static void DiagnoseLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc,
+  Expr *LHSExpr, Expr *RHSExpr) {
+  SourceManager &SM = Self.getSourceManager();
+  if (!OpLoc.isMacroID()) {
+DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
+DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
+return;
+  } else {
+// Diagnose parentheses, if and only if operator and its LHS, RHS
+// are from the same argument position of first level macros
+SourceLocation OpExpansionLoc;
+if (!SM.isMacroArgExpansion(OpLoc, &OpExpansionLoc) ||
+SM.getImmediateMacroCallerLoc(OpLoc).isMacroID())
+  return;
+
+SourceLocation ExprExpansionLoc;
+if (SM.isMacroArgExpansion(LHSExpr->getExprLoc(), &ExprExpansionLoc) &&
+!SM.getImmediateMacroCallerLoc(LHSExpr->getExprLoc()).isMacroID() &&
+OpExpansionLoc == ExprExpansionLoc)
+  DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
+
+if (SM.isMacroArgExpansion(RHSExpr->getExprLoc(), &ExprExpansionLoc) &&
+!SM.getImmediateMacroCallerLoc(LHSExpr->getExprLoc()).isMacroID() &&
+OpExpansionLoc == ExprExpansionLoc)
+  DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
+  }
+}
+
 /// Look for bitwise op in the left or right hand of a bitwise op with
 /// lower precedence and emit a diagnostic together with a fixit hint that 
wraps
 /// the '&' expression in parentheses.
@@ -12310,10 +12339,8 @@
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
   // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
-DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
-DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
-  }
+  if (Opc == BO_LOr)
+DiagnoseLogicalAndInLogicalOr(Self, OpLoc, LHSExpr, RHSExpr);
 
   if ((Opc == BO_Shl && 
LHSExpr->getType()->isIntegralType(Self.getASTContext()))
   || Opc == BO_Shr) {


Index: test/Sema/parentheses.c
===
--- test/Sema/parentheses.c
+++ test/Sema/parentheses.c
@@ -14,6 +14,10 @@
   if ((i = 4)) {}
 }
 
+#define VOID_CAST(cond) ( (void)(cond) )
+#define APPLY_OPS(op0, op1, x, y, z) ( VOID_CAST(x op0 y op1 z) )
+#define APPLY_OPS_DIRECTLY(op0, op1, x, y, z) ( (void)(x op0 y op1 z) )
+
 void bitwise_rel(unsigned i) {
   (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \
 // expected-note{{place parentheses around the '==' expression to silence this warning}} \
@@ -96,6 +100,18 @@
 
   (void)(i && i || 0); // no warning.
   (void)(0 || i && i); // no warning.
+
+  VOID_CAST(i && i || i);   // expected-warning {{'&&' within '||'}} \
+// expected-note {{place parentheses around the '&&' expression to silence this warning}}
+  VOID_CAST((i && i) || i); // no warning.
+
+  APPLY_OPS_DIRECTLY(&&, ||, i, i