[PATCH] D30393: Do not inherit default arguments for friend function in class template.

2017-06-07 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304965: Do not inherit default arguments for friend function 
in class template. (authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D30393?vs=101512&id=101861#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30393

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp


Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -547,17 +547,23 @@
   Diag(OldParam->getLocation(), diag::note_previous_definition)
 << OldParam->getDefaultArgRange();
 } else if (OldParamHasDfl) {
-  // Merge the old default argument into the new parameter.
-  // It's important to use getInit() here;  getDefaultArg()
-  // strips off any top-level ExprWithCleanups.
-  NewParam->setHasInheritedDefaultArg();
-  if (OldParam->hasUnparsedDefaultArg())
-NewParam->setUnparsedDefaultArg();
-  else if (OldParam->hasUninstantiatedDefaultArg())
-NewParam->setUninstantiatedDefaultArg(
-  OldParam->getUninstantiatedDefaultArg());
-  else
-NewParam->setDefaultArg(OldParam->getInit());
+  // Merge the old default argument into the new parameter unless the new
+  // function is a friend declaration in a template class. In the latter
+  // case the default arguments will be inherited when the friend
+  // declaration will be instantiated.
+  if (New->getFriendObjectKind() == Decl::FOK_None ||
+  !New->getLexicalDeclContext()->isDependentContext()) {
+// It's important to use getInit() here;  getDefaultArg()
+// strips off any top-level ExprWithCleanups.
+NewParam->setHasInheritedDefaultArg();
+if (OldParam->hasUnparsedDefaultArg())
+  NewParam->setUnparsedDefaultArg();
+else if (OldParam->hasUninstantiatedDefaultArg())
+  NewParam->setUninstantiatedDefaultArg(
+   
OldParam->getUninstantiatedDefaultArg());
+else
+  NewParam->setDefaultArg(OldParam->getInit());
+  }
 } else if (NewParamHasDfl) {
   if (New->getDescribedFunctionTemplate()) {
 // Paragraph 4, quoted above, only applies to non-template functions.
Index: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
===
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
@@ -73,3 +73,36 @@
 }
 
 } // namespace
+
+namespace pr12724 {
+
+void func_01(bool param = true);
+class C01 {
+public:
+  friend void func_01(bool param);
+};
+
+void func_02(bool param = true);
+template
+class C02 {
+public:
+  friend void func_02(bool param);
+};
+C02 c02;
+
+void func_03(bool param);
+template
+class C03 {
+public:
+  friend void func_03(bool param);
+};
+void func_03(bool param = true);
+C03 c03;
+
+void main() {
+  func_01();
+  func_02();
+  func_03();
+}
+
+} // namespace pr12724


Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -547,17 +547,23 @@
   Diag(OldParam->getLocation(), diag::note_previous_definition)
 << OldParam->getDefaultArgRange();
 } else if (OldParamHasDfl) {
-  // Merge the old default argument into the new parameter.
-  // It's important to use getInit() here;  getDefaultArg()
-  // strips off any top-level ExprWithCleanups.
-  NewParam->setHasInheritedDefaultArg();
-  if (OldParam->hasUnparsedDefaultArg())
-NewParam->setUnparsedDefaultArg();
-  else if (OldParam->hasUninstantiatedDefaultArg())
-NewParam->setUninstantiatedDefaultArg(
-  OldParam->getUninstantiatedDefaultArg());
-  else
-NewParam->setDefaultArg(OldParam->getInit());
+  // Merge the old default argument into the new parameter unless the new
+  // function is a friend declaration in a template class. In the latter
+  // case the default arguments will be inherited when the friend
+  // declaration will be instantiated.
+  if (New->getFriendObjectKind() == Decl::FOK_None ||
+  !New->getLexicalDeclContext()->isDependentContext()) {
+// It's important to use getInit() here;  getDefaultArg()
+// strips off any top-level ExprWithCleanups.
+NewParam->setHasInheritedDefaultArg();
+if (OldParam->hasUnparsedDefaultArg())
+  NewParam->setUnparsedDefaultArg();
+else if (OldParam->hasUninstantiatedDefaultArg())
+  NewParam->setUninstantiatedDefaultArg(
+ 

r304965 - Do not inherit default arguments for friend function in class template.

2017-06-07 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Thu Jun  8 01:31:19 2017
New Revision: 304965

URL: http://llvm.org/viewvc/llvm-project?rev=304965&view=rev
Log:
Do not inherit default arguments for friend function in class template.

A function declared in a friend declaration may have declarations prior
to the containing class definition. If such declaration defines default
argument, the friend function declaration inherits them. This behavior
causes problems if the class where the friend is declared is a template:
during the class instantiation the friend function looks like if it had
default arguments, so error is triggered.

With this change friend functions declared in class templates do not
inherit default arguments. Actual set of them will be defined at the
point where the containing class is instantiated.

This change fixes PR12724.

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

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=304965&r1=304964&r2=304965&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jun  8 01:31:19 2017
@@ -547,17 +547,23 @@ bool Sema::MergeCXXFunctionDecl(Function
   Diag(OldParam->getLocation(), diag::note_previous_definition)
 << OldParam->getDefaultArgRange();
 } else if (OldParamHasDfl) {
-  // Merge the old default argument into the new parameter.
-  // It's important to use getInit() here;  getDefaultArg()
-  // strips off any top-level ExprWithCleanups.
-  NewParam->setHasInheritedDefaultArg();
-  if (OldParam->hasUnparsedDefaultArg())
-NewParam->setUnparsedDefaultArg();
-  else if (OldParam->hasUninstantiatedDefaultArg())
-NewParam->setUninstantiatedDefaultArg(
-  OldParam->getUninstantiatedDefaultArg());
-  else
-NewParam->setDefaultArg(OldParam->getInit());
+  // Merge the old default argument into the new parameter unless the new
+  // function is a friend declaration in a template class. In the latter
+  // case the default arguments will be inherited when the friend
+  // declaration will be instantiated.
+  if (New->getFriendObjectKind() == Decl::FOK_None ||
+  !New->getLexicalDeclContext()->isDependentContext()) {
+// It's important to use getInit() here;  getDefaultArg()
+// strips off any top-level ExprWithCleanups.
+NewParam->setHasInheritedDefaultArg();
+if (OldParam->hasUnparsedDefaultArg())
+  NewParam->setUnparsedDefaultArg();
+else if (OldParam->hasUninstantiatedDefaultArg())
+  NewParam->setUninstantiatedDefaultArg(
+   
OldParam->getUninstantiatedDefaultArg());
+else
+  NewParam->setDefaultArg(OldParam->getInit());
+  }
 } else if (NewParamHasDfl) {
   if (New->getDescribedFunctionTemplate()) {
 // Paragraph 4, quoted above, only applies to non-template functions.

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp?rev=304965&r1=304964&r2=304965&view=diff
==
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp Thu Jun  8 
01:31:19 2017
@@ -73,3 +73,36 @@ void Test ()
 }
 
 } // namespace
+
+namespace pr12724 {
+
+void func_01(bool param = true);
+class C01 {
+public:
+  friend void func_01(bool param);
+};
+
+void func_02(bool param = true);
+template
+class C02 {
+public:
+  friend void func_02(bool param);
+};
+C02 c02;
+
+void func_03(bool param);
+template
+class C03 {
+public:
+  friend void func_03(bool param);
+};
+void func_03(bool param = true);
+C03 c03;
+
+void main() {
+  func_01();
+  func_02();
+  func_03();
+}
+
+} // namespace pr12724


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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 101860.
hintonda added a comment.

- Make sure types for ternary operator are the same.


https://reviews.llvm.org/D20693

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept-opt.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A {};
+class B {};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+template 
+void foo() throw();
+void footest() { foo(); foo(); }
+// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw(...)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void k() throw(int(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void k() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+void baz(int = (throw A(), 0)) throw(A, B) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void baz(int = (throw A(), 0)) noexcept(false) {}
+
+void g(void (*fp)(void) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void g(void (*fp)(void) noexcept);
+
+void f(void (*fp)(void) throw(int)) throw(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'throw(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void f(void (*fp)(void) noexcept(false)) noexcept(false);
+
+#define THROW throw
+void h(void (*fp)(void) THROW(int)) THROW(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'THROW(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'THROW(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void h(void (*fp)(void) noexcept(false)) noexcept(false);
+
+void j() throw(int(int) throw(void(void) throw(int)));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int) throw(void(void) throw(int)))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void j() noexcept(false);
+
+class Y {
+  Y() throw() = default;
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: Y() noexcept = default;
+
+struct Z {
+  void operator delete(void *ptr) throw();
+  void operator delete[](void *ptr) throw(int);
+  ~Z() throw(int) {}
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void operator delete(void *ptr) noexcept;
+// CHECK-FIXES: void operator delete[](void *ptr) noexcept(false);
+// CHECK-FIXES: ~Z() noexcept(fal

[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

Here's a simple example that demonstrates the corruption I'm seeing:

#include "llvm/ADT/StringRef.h"

int main() {

  std::string ss = "";
  llvm::StringRef Ref = true ? "noexcept" : ss;
  std::string s = Ref;
  return 0;

}


https://reviews.llvm.org/D20693



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


[PATCH] D26065: Improve diagnostics if friend function redefines file-level function.

2017-06-07 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304964: Improve diagnostics if friend function redefines 
file-level function. (authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D26065?vs=101666&id=101859#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26065

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp


Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -638,7 +638,12 @@
 Diag(Old->getLocation(), diag::note_previous_declaration);
 Invalid = true;
   } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
- Old->isDefined(Def)) {
+ Old->isDefined(Def) &&
+ // If a friend function is inlined but does not have 'inline'
+ // specifier, it is a definition. Do not report attribute conflict
+ // in this case, redefinition will be diagnosed later.
+ (New->isInlineSpecified() ||
+  New->getFriendObjectKind() == Decl::FOK_None)) {
 // C++11 [dcl.fcn.spec]p4:
 //   If the definition of a function appears in a translation unit before 
its
 //   first declaration as inline, the program is ill-formed.
Index: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
===
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
@@ -4,3 +4,31 @@
 }
 
 inline void f0(); // expected-error {{inline declaration of 'f0' follows 
non-inline definition}}
+
+void func_01() {} // expected-note{{previous definition is here}}
+struct C01 {
+  friend void func_01() {} // expected-error{{redefinition of 'func_01'}}
+};
+
+void func_02() {} // expected-note{{previous definition is here}}
+struct C02 {
+  friend inline void func_02(); // expected-error{{inline declaration of 
'func_02' follows non-inline definition}}
+};
+
+void func_03() {} // expected-note{{previous definition is here}}
+struct C03 {
+  friend inline void func_03() {} // expected-error{{inline declaration of 
'func_03' follows non-inline definition}}
+};
+
+void func_04() {} // expected-note{{previous definition is here}}
+inline void func_04() {} // expected-error{{inline declaration of 'func_04' 
follows non-inline definition}}
+
+void func_06() {} // expected-note{{previous definition is here}}
+template struct C06 {
+  friend inline void func_06() {} // expected-error{{inline declaration of 
'func_06' follows non-inline definition}}
+};
+
+void func_07() {} // expected-note{{previous definition is here}}
+template struct C07 {
+  friend inline void func_07(); // expected-error{{inline declaration of 
'func_07' follows non-inline definition}}
+};


Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -638,7 +638,12 @@
 Diag(Old->getLocation(), diag::note_previous_declaration);
 Invalid = true;
   } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
- Old->isDefined(Def)) {
+ Old->isDefined(Def) &&
+ // If a friend function is inlined but does not have 'inline'
+ // specifier, it is a definition. Do not report attribute conflict
+ // in this case, redefinition will be diagnosed later.
+ (New->isInlineSpecified() ||
+  New->getFriendObjectKind() == Decl::FOK_None)) {
 // C++11 [dcl.fcn.spec]p4:
 //   If the definition of a function appears in a translation unit before its
 //   first declaration as inline, the program is ill-formed.
Index: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
===
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
@@ -4,3 +4,31 @@
 }
 
 inline void f0(); // expected-error {{inline declaration of 'f0' follows non-inline definition}}
+
+void func_01() {} // expected-note{{previous definition is here}}
+struct C01 {
+  friend void func_01() {} // expected-error{{redefinition of 'func_01'}}
+};
+
+void func_02() {} // expected-note{{previous definition is here}}
+struct C02 {
+  friend inline void func_02(); // expected-error{{inline declaration of 'func_02' follows non-inline definition}}
+};
+
+void func_03() {} // expected-note{{previous definition is here}}
+struct C03 {
+  friend inline void func_03() {} // expected-error{{inline declaration of 'func_03' follows non-inline definition}}
+};
+
+void func_04() {} // expected-note{{previous definition is here}}
+inline void func_04() {} // expected-error{{inline declaration of 'func_04' 

r304964 - Improve diagnostics if friend function redefines file-level function.

2017-06-07 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Thu Jun  8 01:07:07 2017
New Revision: 304964

URL: http://llvm.org/viewvc/llvm-project?rev=304964&view=rev
Log:
Improve diagnostics if friend function redefines file-level function.

Clang makes check for function redefinition after it merged the new
declaration with the existing one. As a result, it produces poor
diagnostics in the case of a friend function defined inline, as in
the code:
```
void func() {}
class C { friend void func() {} };
```
Error message in this case states that `inline declaration of 'func'
follows non-inline definition`, which is misleading, as `func` does
not have explicit `inline` specifier.

With this changes compiler reports function redefinition if the new
function is a friend defined inline and it does not have explicit
`inline` specifier.

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

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=304964&r1=304963&r2=304964&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jun  8 01:07:07 2017
@@ -638,7 +638,12 @@ bool Sema::MergeCXXFunctionDecl(Function
 Diag(Old->getLocation(), diag::note_previous_declaration);
 Invalid = true;
   } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
- Old->isDefined(Def)) {
+ Old->isDefined(Def) &&
+ // If a friend function is inlined but does not have 'inline'
+ // specifier, it is a definition. Do not report attribute conflict
+ // in this case, redefinition will be diagnosed later.
+ (New->isInlineSpecified() ||
+  New->getFriendObjectKind() == Decl::FOK_None)) {
 // C++11 [dcl.fcn.spec]p4:
 //   If the definition of a function appears in a translation unit before 
its
 //   first declaration as inline, the program is ill-formed.

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp?rev=304964&r1=304963&r2=304964&view=diff
==
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.fct.spec/p4.cpp Thu Jun  8 01:07:07 
2017
@@ -4,3 +4,31 @@ void f0() { // expected-note {{previous
 }
 
 inline void f0(); // expected-error {{inline declaration of 'f0' follows 
non-inline definition}}
+
+void func_01() {} // expected-note{{previous definition is here}}
+struct C01 {
+  friend void func_01() {} // expected-error{{redefinition of 'func_01'}}
+};
+
+void func_02() {} // expected-note{{previous definition is here}}
+struct C02 {
+  friend inline void func_02(); // expected-error{{inline declaration of 
'func_02' follows non-inline definition}}
+};
+
+void func_03() {} // expected-note{{previous definition is here}}
+struct C03 {
+  friend inline void func_03() {} // expected-error{{inline declaration of 
'func_03' follows non-inline definition}}
+};
+
+void func_04() {} // expected-note{{previous definition is here}}
+inline void func_04() {} // expected-error{{inline declaration of 'func_04' 
follows non-inline definition}}
+
+void func_06() {} // expected-note{{previous definition is here}}
+template struct C06 {
+  friend inline void func_06() {} // expected-error{{inline declaration of 
'func_06' follows non-inline definition}}
+};
+
+void func_07() {} // expected-note{{previous definition is here}}
+template struct C07 {
+  friend inline void func_07(); // expected-error{{inline declaration of 
'func_07' follows non-inline definition}}
+};


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


[PATCH] D34021: [coroutines] Fix co_await for range statement

2017-06-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 101858.

https://reviews.llvm.org/D34021

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/coawait_range_for.cpp

Index: test/SemaCXX/coawait_range_for.cpp
===
--- /dev/null
+++ test/SemaCXX/coawait_range_for.cpp
@@ -0,0 +1,158 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts \
+// RUN:-fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify \
+// RUN:-fblocks
+#include "Inputs/std-coroutine.h"
+
+using namespace std::experimental;
+
+
+template 
+struct Awaiter {
+  bool await_ready();
+  void await_suspend(coroutine_handle<>);
+  Begin await_resume();
+};
+
+template  struct BeginTag { BeginTag() = delete; };
+template  struct IncTag { IncTag() = delete; };
+
+template 
+struct CoawaitTag { CoawaitTag() = delete; };
+
+template 
+struct Iter {
+  using value_type = T;
+  using reference = T &;
+  using pointer = T *;
+
+  IncTag operator++();
+  reference operator*();
+  pointer operator->();
+};
+template  bool operator==(Iter, Iter);
+template  bool operator!=(Iter, Iter);
+
+template 
+struct Range {
+  BeginTag> begin();
+  Iter end();
+};
+
+struct MyForLoopArrayAwaiter {
+  struct promise_type {
+MyForLoopArrayAwaiter get_return_object() { return {}; }
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+template 
+Awaiter await_transform(T *) = delete; // expected-note {{explicitly deleted}}
+  };
+};
+MyForLoopArrayAwaiter g() {
+  int arr[10] = {0};
+  for co_await(auto i : arr) {}
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+
+struct ForLoopAwaiterBadBeginTransform {
+  struct promise_type {
+ForLoopAwaiterBadBeginTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag) = delete; // expected-note 1+ {{explicitly deleted}}
+
+template 
+CoawaitTag await_transform(IncTag); // expected-note 1+ {{candidate}}
+  };
+};
+ForLoopAwaiterBadBeginTransform bad_begin() {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+template 
+ForLoopAwaiterBadBeginTransform bad_begin_template(Dummy) {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+template ForLoopAwaiterBadBeginTransform bad_begin_template(int); // expected-note {{requested here}}
+
+template 
+Awaiter operator co_await(CoawaitTag) = delete;
+// expected-note@-1 1+ {{explicitly deleted}}
+
+struct ForLoopAwaiterBadIncTransform {
+  struct promise_type {
+ForLoopAwaiterBadIncTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag e);
+
+template 
+CoawaitTag await_transform(IncTag);
+  };
+};
+ForLoopAwaiterBadIncTransform bad_inc_transform() {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'Range'}}
+}
+
+template 
+ForLoopAwaiterBadIncTransform bad_inc_transform_template(Dummy) {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'Range'}}
+}
+template ForLoopAwaiterBadIncTransform bad_inc_transform_template(long); // expected-note {{requested here}}
+
+// Ensure we mark and check the function as a coroutine even if it's
+// never instantiated.
+template 
+constexpr void never_instant(T) {
+  static_assert(sizeof(T) != sizeof(T), "function should not be instantiated");
+  for co_await(auto i : foo(T{})) {}
+  // expected-error@-1 {{'co_await' cannot be used in a constexpr function}}
+}
+
+struct ForLoopAwaiterCoawaitLookup {
+  struct promise_type {
+ForLoopAwaiterCoawaitLookup get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+template 
+CoawaitTag await_transform(BeginTag e);
+template 
+Awaiter await_transform(IncTag);
+  };
+};
+template 
+ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-

[PATCH] D33732: Catch invalid bitwise operation on vector of floats

2017-06-07 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304963: Catch invalid bitwise operation on vector of floats 
(authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D33732?vs=101359&id=101856#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33732

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/Sema/ext_vector_ops.c


Index: cfe/trunk/test/Sema/ext_vector_ops.c
===
--- cfe/trunk/test/Sema/ext_vector_ops.c
+++ cfe/trunk/test/Sema/ext_vector_ops.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple 
x86_64-apple-darwin10
+
+typedef unsigned int v2u __attribute__ ((ext_vector_type(2)));
+typedef int v2s __attribute__ ((ext_vector_type(2)));
+typedef float v2f __attribute__ ((ext_vector_type(2)));
+
+void test1(v2u v2ua, v2s v2sa, v2f v2fa) {
+  // Bitwise binary operators
+  (void)(v2ua & v2ua);
+  (void)(v2fa & v2fa); // expected-error{{invalid operands to binary 
expression}}
+
+  // Unary operators
+  (void)(~v2ua);
+  (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 
'float' values) to unary}}
+
+  // Comparison operators
+  v2sa = (v2ua==v2sa);
+
+  // Arrays
+  int array1[v2ua]; // expected-error{{size of array has non-integer type 
'v2u' (vector of 2 'unsigned int' values}}
+  int array2[17];
+  // FIXME: error message below needs type!
+  (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}}
+
+  v2u *v2u_ptr = 0;
+  v2s *v2s_ptr;
+}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -11975,16 +11975,13 @@
   << resultType << Input.get()->getSourceRange();
 else if (resultType->hasIntegerRepresentation())
   break;
-else if (resultType->isExtVectorType()) {
-  if (Context.getLangOpts().OpenCL) {
-// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate
-// on vector float types.
-QualType T = resultType->getAs()->getElementType();
-if (!T->isIntegerType())
-  return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
-   << resultType << Input.get()->getSourceRange());
-  }
-  break;
+else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) {
+  // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate
+  // on vector float types.
+  QualType T = resultType->getAs()->getElementType();
+  if (!T->isIntegerType())
+return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
+  << resultType << Input.get()->getSourceRange());
 } else {
   return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
<< resultType << Input.get()->getSourceRange());


Index: cfe/trunk/test/Sema/ext_vector_ops.c
===
--- cfe/trunk/test/Sema/ext_vector_ops.c
+++ cfe/trunk/test/Sema/ext_vector_ops.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple x86_64-apple-darwin10
+
+typedef unsigned int v2u __attribute__ ((ext_vector_type(2)));
+typedef int v2s __attribute__ ((ext_vector_type(2)));
+typedef float v2f __attribute__ ((ext_vector_type(2)));
+
+void test1(v2u v2ua, v2s v2sa, v2f v2fa) {
+  // Bitwise binary operators
+  (void)(v2ua & v2ua);
+  (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}}
+
+  // Unary operators
+  (void)(~v2ua);
+  (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}}
+
+  // Comparison operators
+  v2sa = (v2ua==v2sa);
+
+  // Arrays
+  int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values}}
+  int array2[17];
+  // FIXME: error message below needs type!
+  (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}}
+
+  v2u *v2u_ptr = 0;
+  v2s *v2s_ptr;
+}
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -11975,16 +11975,13 @@
   << resultType << Input.get()->getSourceRange();
 else if (resultType->hasIntegerRepresentation())
   break;
-else if (resultType->isExtVectorType()) {
-  if (Context.getLangOpts().OpenCL) {
-// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate
-// on vector float types.
-QualType T = resultType->getAs()->getElementType();
-if (!T->isIntegerType())
-  return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
-   << resultType << Input.get()->getSourceRange());
-  }
-  break;
+else if (resultType->isExt

r304963 - Catch invalid bitwise operation on vector of floats

2017-06-07 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Thu Jun  8 00:25:19 2017
New Revision: 304963

URL: http://llvm.org/viewvc/llvm-project?rev=304963&view=rev
Log:
Catch invalid bitwise operation on vector of floats

Bitwise complement applied to vector of floats described with
attribute `ext_vector_type` is not diagnosed as error. Attempt to
compile such construct causes assertion violation in Instruction.cpp.
With this change the complement is treated similar to the case of
vector type described with attribute `vector_size`.

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

Added:
cfe/trunk/test/Sema/ext_vector_ops.c
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=304963&r1=304962&r2=304963&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jun  8 00:25:19 2017
@@ -11975,16 +11975,13 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
   << resultType << Input.get()->getSourceRange();
 else if (resultType->hasIntegerRepresentation())
   break;
-else if (resultType->isExtVectorType()) {
-  if (Context.getLangOpts().OpenCL) {
-// OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate
-// on vector float types.
-QualType T = resultType->getAs()->getElementType();
-if (!T->isIntegerType())
-  return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
-   << resultType << Input.get()->getSourceRange());
-  }
-  break;
+else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) {
+  // OpenCL v1.1 s6.3.f: The bitwise operator not (~) does not operate
+  // on vector float types.
+  QualType T = resultType->getAs()->getElementType();
+  if (!T->isIntegerType())
+return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
+  << resultType << Input.get()->getSourceRange());
 } else {
   return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr)
<< resultType << Input.get()->getSourceRange());

Added: cfe/trunk/test/Sema/ext_vector_ops.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ext_vector_ops.c?rev=304963&view=auto
==
--- cfe/trunk/test/Sema/ext_vector_ops.c (added)
+++ cfe/trunk/test/Sema/ext_vector_ops.c Thu Jun  8 00:25:19 2017
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple 
x86_64-apple-darwin10
+
+typedef unsigned int v2u __attribute__ ((ext_vector_type(2)));
+typedef int v2s __attribute__ ((ext_vector_type(2)));
+typedef float v2f __attribute__ ((ext_vector_type(2)));
+
+void test1(v2u v2ua, v2s v2sa, v2f v2fa) {
+  // Bitwise binary operators
+  (void)(v2ua & v2ua);
+  (void)(v2fa & v2fa); // expected-error{{invalid operands to binary 
expression}}
+
+  // Unary operators
+  (void)(~v2ua);
+  (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 
'float' values) to unary}}
+
+  // Comparison operators
+  v2sa = (v2ua==v2sa);
+
+  // Arrays
+  int array1[v2ua]; // expected-error{{size of array has non-integer type 
'v2u' (vector of 2 'unsigned int' values}}
+  int array2[17];
+  // FIXME: error message below needs type!
+  (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}}
+
+  v2u *v2u_ptr = 0;
+  v2s *v2s_ptr;
+}


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


[PATCH] D34021: [coroutines] Fix co_await for range statement

2017-06-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 101857.
EricWF added a comment.

- More test cleanup. Sorry for the noise.


https://reviews.llvm.org/D34021

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/coawait_range_for.cpp

Index: test/SemaCXX/coawait_range_for.cpp
===
--- /dev/null
+++ test/SemaCXX/coawait_range_for.cpp
@@ -0,0 +1,157 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts \
+// RUN:-fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify \
+// RUN:-fblocks
+#include "Inputs/std-coroutine.h"
+
+using namespace std::experimental;
+
+
+template 
+struct Awaiter {
+  bool await_ready();
+  void await_suspend(coroutine_handle<>);
+  Begin await_resume();
+};
+
+template  struct BeginTag { BeginTag() = delete; };
+template  struct IncTag { IncTag() = delete; };
+
+template 
+struct CoawaitTag { CoawaitTag() = delete; };
+
+template 
+struct Iter {
+  using value_type = T;
+  using reference = T &;
+  using pointer = T *;
+
+  IncTag operator++();
+  reference operator*();
+  pointer operator->();
+};
+template  bool operator==(Iter, Iter);
+template  bool operator!=(Iter, Iter);
+
+template 
+struct Range {
+  BeginTag> begin();
+  Iter end();
+};
+
+struct MyForLoopArrayAwaiter {
+  struct promise_type {
+MyForLoopArrayAwaiter get_return_object() { return {}; }
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+template 
+Awaiter await_transform(T *) = delete; // expected-note {{explicitly deleted}}
+  };
+};
+MyForLoopArrayAwaiter g() {
+  int arr[10] = {0};
+  for co_await(auto i : arr) {}
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+
+struct ForLoopAwaiterBadBeginTransform {
+  struct promise_type {
+ForLoopAwaiterBadBeginTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag) = delete; // expected-note 1+ {{explicitly deleted}}
+
+template 
+CoawaitTag await_transform(IncTag); // expected-note 1+ {{candidate}}
+  };
+};
+ForLoopAwaiterBadBeginTransform bad_begin() {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+template 
+ForLoopAwaiterBadBeginTransform bad_begin_template(Dummy) {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+template ForLoopAwaiterBadBeginTransform bad_begin_template(int); // expected-note {{requested here}}
+
+template 
+Awaiter operator co_await(CoawaitTag) = delete;
+// expected-note@-1 1+ {{explicitly deleted}}
+
+struct ForLoopAwaiterBadIncTransform {
+  struct promise_type {
+ForLoopAwaiterBadIncTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag e);
+
+template 
+CoawaitTag await_transform(IncTag);
+  };
+};
+ForLoopAwaiterBadIncTransform bad_inc_transform() {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'Range'}}
+}
+
+template 
+ForLoopAwaiterBadIncTransform bad_inc_transform_template(Dummy) {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'Range'}}
+}
+template ForLoopAwaiterBadIncTransform bad_inc_transform_template(long); // expected-note {{requested here}}
+
+// Ensure we mark and check the function as a coroutine even if it's
+// never instantiated.
+template 
+constexpr void never_instant(T) {
+  for co_await(auto i : foo(T{})) {}
+  // expected-error@-1 {{'co_await' cannot be used in a constexpr function}}
+}
+
+struct ForLoopAwaiterCoawaitLookup {
+  struct promise_type {
+ForLoopAwaiterCoawaitLookup get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+template 
+CoawaitTag await_transform(BeginTag e);
+template 
+Awaiter await_transform(IncTag);
+  };
+};
+template 
+ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
+  Range R;
+  for co_await(auto i : R) {}
+  // expected-error@-1 {{no

[PATCH] D34021: [coroutines] Fix co_await for range statement

2017-06-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 101854.
EricWF added a comment.

- Fix clang-format nonsense in tests.


https://reviews.llvm.org/D34021

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/coawait_range_for.cpp

Index: test/SemaCXX/coawait_range_for.cpp
===
--- /dev/null
+++ test/SemaCXX/coawait_range_for.cpp
@@ -0,0 +1,187 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts \
+// RUN:-fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify \
+// RUN:-fblocks
+#include "Inputs/std-coroutine.h"
+
+using namespace std::experimental;
+
+template 
+struct EnableIf {};
+template 
+struct EnableIf { using type = T; };
+template 
+using EnableIfT = typename EnableIf::type;
+
+template 
+struct Awaiter {
+  Awaiter(Begin b);
+  bool await_ready();
+  void await_suspend(coroutine_handle<>);
+  Begin await_resume();
+};
+
+template 
+struct BeginTag {
+  BeginTag() = delete;
+};
+
+template 
+struct IncTag {
+  IncTag() = delete;
+};
+
+template 
+struct CoawaitTag {
+  CoawaitTag() = delete;
+};
+
+template 
+struct MyIter {
+  using value_type = T;
+  using reference = T &;
+  using pointer = T *;
+
+  IncTag operator++();
+  reference operator*();
+  pointer operator->();
+};
+template 
+bool operator==(MyIter, MyIter);
+template 
+bool operator!=(MyIter, MyIter);
+
+template 
+struct MyRange {
+  BeginTag> begin();
+  MyIter end();
+};
+
+struct MyForLoopArrayAwaiter {
+  struct promise_type {
+MyForLoopArrayAwaiter get_return_object() { return {}; }
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+template 
+Awaiter await_transform(T *) = delete; // expected-note {{explicitly deleted}}
+  };
+};
+MyForLoopArrayAwaiter g() {
+  int arr[10] = {0};
+  for co_await(auto i : arr)
+// expected-error@-1 {{call to deleted member function 'await_transform'}}
+// expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+{
+}
+}
+
+struct ForLoopAwaiterBadBeginTransform {
+  struct promise_type {
+ForLoopAwaiterBadBeginTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag) = delete; // expected-note 1+ {{explicitly deleted}}
+
+template 
+CoawaitTag await_transform(IncTag); // expected-note 1+ {{candidate}}
+  };
+};
+ForLoopAwaiterBadBeginTransform bad_begin() {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+}
+template 
+ForLoopAwaiterBadBeginTransform bad_begin_template(Dummy) {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+}
+template ForLoopAwaiterBadBeginTransform bad_begin_template(int); // expected-note {{requested here}}
+
+template 
+Awaiter operator co_await(CoawaitTag) = delete;
+// expected-note@-1 1+ {{explicitly deleted}}
+
+struct ForLoopAwaiterBadIncTransform {
+  struct promise_type {
+ForLoopAwaiterBadIncTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag e);
+
+template 
+CoawaitTag await_transform(IncTag);
+  };
+};
+ForLoopAwaiterBadIncTransform bad_inc_transform() {
+  MyRange R;
+  for co_await(auto i : R) {
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'MyRange'}}
+  ((void)i);
+}
+}
+
+template 
+ForLoopAwaiterBadIncTransform bad_inc_transform_template(Dummy) {
+  MyRange R;
+  for co_await(auto i : R) {
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'MyRange'}}
+  ((void)i);
+}
+}
+template ForLoopAwaiterBadIncTransform bad_inc_transform_template(long); // expected-note {{requested here}}
+
+// Ensure we mark and check the function as a coroutine even if it's
+// never instantiated.
+template 
+constexpr void never_instant(T) {
+  for co_await(auto i : foo(T{})) {}
+  // expected-error@-1 {{'co_await' cannot be used in a constexpr function}}
+}
+
+struct ForLoopAwaiterCoawaitLookup {
+  struct promise_type {
+ForLoopAwaiterCoawaitLookup get_return_object();
+void return_void();
+void unhandled_exce

[PATCH] D34021: [coroutines] Fix co_await for range statement

2017-06-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 101853.
EricWF added a comment.

- Add FIXME comments for incorrect use of `getCurScope()` after initial parse.


https://reviews.llvm.org/D34021

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/coawait_range_for.cpp

Index: test/SemaCXX/coawait_range_for.cpp
===
--- /dev/null
+++ test/SemaCXX/coawait_range_for.cpp
@@ -0,0 +1,197 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts \
+// RUN:-fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify \
+// RUN:-fblocks
+#include "Inputs/std-coroutine.h"
+
+using namespace std::experimental;
+
+template 
+struct EnableIf {};
+template 
+struct EnableIf { using type = T; };
+template 
+using EnableIfT = typename EnableIf::type;
+
+template 
+struct Awaiter {
+  Awaiter(Begin b);
+  bool await_ready();
+  void await_suspend(coroutine_handle<>);
+  Begin await_resume();
+};
+
+template 
+struct BeginTag {
+  BeginTag() = delete;
+};
+
+template 
+struct IncTag {
+  IncTag() = delete;
+};
+
+template 
+struct CoawaitTag {
+  CoawaitTag() = delete;
+};
+
+template 
+struct MyIter {
+  using value_type = T;
+  using reference = T &;
+  using pointer = T *;
+
+  IncTag operator++();
+  reference operator*();
+  pointer operator->();
+};
+template 
+bool operator==(MyIter, MyIter);
+template 
+bool operator!=(MyIter, MyIter);
+
+template 
+struct MyRange {
+  BeginTag> begin();
+  MyIter end();
+};
+
+struct MyForLoopArrayAwaiter {
+  struct promise_type {
+MyForLoopArrayAwaiter get_return_object() { return {}; }
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+template 
+Awaiter await_transform(T *) = delete; // expected-note {{explicitly deleted}}
+  };
+};
+MyForLoopArrayAwaiter g() {
+  int arr[10] = {0};
+  for
+co_await(auto i
+ : arr)
+// expected-error@-1 {{call to deleted member function 'await_transform'}}
+// expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+{
+}
+}
+
+struct ForLoopAwaiterBadBeginTransform {
+  struct promise_type {
+ForLoopAwaiterBadBeginTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag) = delete; // expected-note 1+ {{explicitly deleted}}
+
+template 
+CoawaitTag await_transform(IncTag); // expected-note 1+ {{candidate}}
+  };
+};
+ForLoopAwaiterBadBeginTransform bad_begin() {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+}
+template 
+ForLoopAwaiterBadBeginTransform bad_begin_template(Dummy) {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+}
+template ForLoopAwaiterBadBeginTransform bad_begin_template(int); // expected-note {{requested here}}
+
+template 
+Awaiter operator co_await(CoawaitTag) = delete;
+// expected-note@-1 1+ {{explicitly deleted}}
+
+struct ForLoopAwaiterBadIncTransform {
+  struct promise_type {
+ForLoopAwaiterBadIncTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag e);
+
+template 
+CoawaitTag await_transform(IncTag);
+  };
+};
+ForLoopAwaiterBadIncTransform bad_inc_transform() {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'MyRange'}}
+  ((void)i);
+}
+}
+
+template 
+ForLoopAwaiterBadIncTransform bad_inc_transform_template(Dummy) {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'MyRange'}}
+  ((void)i);
+}
+}
+template ForLoopAwaiterBadIncTransform bad_inc_transform_template(long); // expected-note {{requested here}}
+
+// Ensure we mark and check the function as a coroutine even if it's
+// never instantiated.
+template 
+constexpr void never_instant(T) {
+  for
+co_await(auto i
+ : foo(T{})) {}
+  // expected-error@-1 {{'co_await' cannot be used in a constexpr function}}
+}
+
+struct ForLoopAwaiterCoawaitLookup {
+  struct p

[PATCH] D34021: [coroutines] Fix co_await for range statement

2017-06-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.

Currently we build the co_await expressions on the wrong implicit statements of 
the implicit ranged for; Specifically we build the co_await expression wrapping 
the range declaration, but it should wrap the begin expression.

This patch fixes co_await on range for.


https://reviews.llvm.org/D34021

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/coawait_range_for.cpp

Index: test/SemaCXX/coawait_range_for.cpp
===
--- /dev/null
+++ test/SemaCXX/coawait_range_for.cpp
@@ -0,0 +1,197 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts \
+// RUN:-fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify \
+// RUN:-fblocks
+#include "Inputs/std-coroutine.h"
+
+using namespace std::experimental;
+
+template 
+struct EnableIf {};
+template 
+struct EnableIf { using type = T; };
+template 
+using EnableIfT = typename EnableIf::type;
+
+template 
+struct Awaiter {
+  Awaiter(Begin b);
+  bool await_ready();
+  void await_suspend(coroutine_handle<>);
+  Begin await_resume();
+};
+
+template 
+struct BeginTag {
+  BeginTag() = delete;
+};
+
+template 
+struct IncTag {
+  IncTag() = delete;
+};
+
+template 
+struct CoawaitTag {
+  CoawaitTag() = delete;
+};
+
+template 
+struct MyIter {
+  using value_type = T;
+  using reference = T &;
+  using pointer = T *;
+
+  IncTag operator++();
+  reference operator*();
+  pointer operator->();
+};
+template 
+bool operator==(MyIter, MyIter);
+template 
+bool operator!=(MyIter, MyIter);
+
+template 
+struct MyRange {
+  BeginTag> begin();
+  MyIter end();
+};
+
+struct MyForLoopArrayAwaiter {
+  struct promise_type {
+MyForLoopArrayAwaiter get_return_object() { return {}; }
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+template 
+Awaiter await_transform(T *) = delete; // expected-note {{explicitly deleted}}
+  };
+};
+MyForLoopArrayAwaiter g() {
+  int arr[10] = {0};
+  for
+co_await(auto i
+ : arr)
+// expected-error@-1 {{call to deleted member function 'await_transform'}}
+// expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+{
+}
+}
+
+struct ForLoopAwaiterBadBeginTransform {
+  struct promise_type {
+ForLoopAwaiterBadBeginTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag) = delete; // expected-note 1+ {{explicitly deleted}}
+
+template 
+CoawaitTag await_transform(IncTag); // expected-note 1+ {{candidate}}
+  };
+};
+ForLoopAwaiterBadBeginTransform bad_begin() {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+}
+template 
+ForLoopAwaiterBadBeginTransform bad_begin_template(Dummy) {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{call to deleted member function 'await_transform'}}
+  // expected-note@-2 {{'await_transform' implicitly required by 'co_await' here}}
+}
+}
+template ForLoopAwaiterBadBeginTransform bad_begin_template(int); // expected-note {{requested here}}
+
+template 
+Awaiter operator co_await(CoawaitTag) = delete;
+// expected-note@-1 1+ {{explicitly deleted}}
+
+struct ForLoopAwaiterBadIncTransform {
+  struct promise_type {
+ForLoopAwaiterBadIncTransform get_return_object();
+void return_void();
+void unhandled_exception();
+suspend_never initial_suspend();
+suspend_never final_suspend();
+
+template 
+Awaiter await_transform(BeginTag e);
+
+template 
+CoawaitTag await_transform(IncTag);
+  };
+};
+ForLoopAwaiterBadIncTransform bad_inc_transform() {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'MyRange'}}
+  ((void)i);
+}
+}
+
+template 
+ForLoopAwaiterBadIncTransform bad_inc_transform_template(Dummy) {
+  MyRange R;
+  for
+co_await(auto i
+ : R) {
+  // expected-error@-1 {{overload resolution selected deleted operator 'co_await'}}
+  // expected-note@-2 {{in implicit call to 'operator++' for iterator of type 'MyRange'}}
+  ((void)i);
+}
+}
+template ForLoopAwaiterBadIncTransform bad_inc_transform_template(long); // expected-note {{requested here}}
+
+// Ensure we mark and check the function as a coroutine even if it's
+// never instantiated.
+template 
+constexpr void never_instant(T) {
+  for
+co_await(auto i
+   

Re: r304956 - [ODRHash] Change the fall-back diagnostic error.

2017-06-07 Thread Richard Trieu via cfe-commits
After r304962, it should now produce messages like:

'foo' defined here has different definitions in different modules; first
difference is this unexpected decl
but in 'Module' found another unexpected decl

'foo' with definition in module 'FirstModule' has different definitions in
different modules; first difference is this field
but in 'Module' found different field

On Wed, Jun 7, 2017 at 6:41 PM, Richard Trieu  wrote:

> Yes, I will go correct the diagnostic text.
>
> In theory, there is nothing that is supposed to reach this diagnostic or
> the one below it.  Except that the hasher isn't complete yet and some
> things slip through.  Once things are more stable, these should be replaced
> with llvm_unreachable instead.
>
> On Wed, Jun 7, 2017 at 6:05 PM, Richard Smith 
> wrote:
>
>> On 7 June 2017 at 17:56, Richard Trieu via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: rtrieu
>>> Date: Wed Jun  7 19:56:21 2017
>>> New Revision: 304956
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=304956&view=rev
>>> Log:
>>> [ODRHash] Change the fall-back diagnostic error.
>>>
>>> Provide a little more information when a ODR violation is detected, but
>>> the
>>> specific error could not be diagnosed.
>>>
>>> Modified:
>>> cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
>>> cfe/trunk/lib/Serialization/ASTReader.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>>> Basic/DiagnosticSerializationKinds.td?rev=304956&r1=304955&r
>>> 2=304956&view=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
>>> (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Wed
>>> Jun  7 19:56:21 2017
>>> @@ -174,6 +174,13 @@ def note_module_odr_violation_mismatch_d
>>>"method %2 with %ordinal3 parameter of type %4%select{| decayed from
>>> %6}5|"
>>>"method %2 with %ordinal3 parameter named %4}1">;
>>>
>>> +def err_module_odr_violation_mismatch_decl_unknown : Error<
>>> +  "%q0 has different definitions in different modules; first difference
>>> is "
>>> +  "%select{definition in module '%2'|defined here}1 found different "
>>> +  "%select{static assert|field|method|other}3">;
>>> +def note_module_odr_violation_mismatch_decl_unknown : Note<
>>> +  "but in '%0' found different %select{static
>>> assert|field|method|other}1">;
>>>
>>
>> This will produce messages like
>>
>> "first difference is defined here found different static assert"
>> "first difference is definition in module 'X' found different other"
>>
>> ... which seem pretty confusing. Can this be rephrased so that it forms
>> easier-to-read sentences? (Also, can we get some test coverage for this
>> diagnostic?)
>>
>>
>>> +
>>>  def warn_duplicate_module_file_extension : Warning<
>>>"duplicate module file extension block name '%0'">,
>>>InGroup;
>>>
>>> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serializat
>>> ion/ASTReader.cpp?rev=304956&r1=304955&r2=304956&view=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
>>> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Jun  7 19:56:21 2017
>>> @@ -9753,13 +9753,13 @@ void ASTReader::diagnoseOdrViolations()
>>>if (Diagnosed == true)
>>>  continue;
>>>
>>> -  Diag(FirstRecord->getLocation(),
>>> -   diag::err_module_odr_violation_different_definitions)
>>> -  << FirstRecord << FirstModule.empty() << FirstModule;
>>> -
>>> -  Diag(SecondRecord->getLocation(),
>>> -   diag::note_module_odr_violation_different_definitions)
>>> -  << SecondModule;
>>> +  Diag(FirstDecl->getLocation(),
>>> +   diag::err_module_odr_violation_mismatch_decl_unknown)
>>> +  << FirstRecord << FirstModule.empty() << FirstModule <<
>>> FirstDiffType
>>> +  << FirstDecl->getSourceRange();
>>> +  Diag(SecondDecl->getLocation(),
>>> +   diag::note_module_odr_violation_mismatch_decl_unknown)
>>> +  << SecondModule << FirstDiffType <<
>>> SecondDecl->getSourceRange();
>>>Diagnosed = true;
>>>  }
>>>
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r304962 - [ODRHash] Make diagnostic message more readable.

2017-06-07 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Wed Jun  7 23:47:29 2017
New Revision: 304962

URL: http://llvm.org/viewvc/llvm-project?rev=304962&view=rev
Log:
[ODRHash] Make diagnostic message more readable.

Change the diagnostic message from r304956 to be less confusing by reordering
the flow of information.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=304962&r1=304961&r2=304962&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Wed Jun  7 
23:47:29 2017
@@ -175,11 +175,13 @@ def note_module_odr_violation_mismatch_d
   "method %2 with %ordinal3 parameter named %4}1">;
 
 def err_module_odr_violation_mismatch_decl_unknown : Error<
-  "%q0 has different definitions in different modules; first difference is "
-  "%select{definition in module '%2'|defined here}1 found different "
-  "%select{static assert|field|method|other}3">;
+  "%q0 %select{with definition in module '%2'|defined here}1 has different "
+  "definitions in different modules; first difference is this "
+  "%select{static assert|field|method|unexpected decl}3">;
 def note_module_odr_violation_mismatch_decl_unknown : Note<
-  "but in '%0' found different %select{static 
assert|field|method|other}1">;
+  "but in '%0' found "
+  "%select{different static assert|different field|different method|"
+  "another unexpected decl}1">;
 
 def warn_duplicate_module_file_extension : Warning<
   "duplicate module file extension block name '%0'">,


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


[PATCH] D30268: Avoid copy of __atoms when char_type is char

2017-06-07 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added a comment.

Ping


https://reviews.llvm.org/D30268



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


[PATCH] D31868: [analyzer] Check NULL pointer dereference issue for memset function

2017-06-07 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai updated this revision to Diff 101847.
xiangzhai added a comment.
Herald added a subscriber: xazax.hun.

Hi Artem,

I updated my patch please review it, thanks a lot!

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D31868

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  test/Analysis/null-deref-ps-region.c

Index: test/Analysis/null-deref-ps-region.c
===
--- test/Analysis/null-deref-ps-region.c
+++ test/Analysis/null-deref-ps-region.c
@@ -1,6 +1,11 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-store=region -verify %s
-// expected-no-diagnostics
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,unix,alpha.unix -std=gnu99 -analyzer-store=region -verify %s
 
+#include "Inputs/system-header-simulator.h"
+
+typedef __typeof(sizeof(int)) size_t;
+void *memset(void *__s, int __c, size_t __n);
+void *malloc(size_t __size);
+void free(void *__ptr);
 
 // The store for 'a[1]' should not be removed mistakenly. SymbolicRegions may
 // also be live roots.
@@ -13,3 +18,55 @@
 i = *p; // no-warning
   }
 }
+
+void foo() {
+  int *x = malloc(sizeof(int));
+  memset(x, 0, sizeof(int));
+  int n = 1 / *x; // FIXME: no-warning
+  free(x);
+}
+
+void bar() {
+  int *x = malloc(sizeof(int));
+  memset(x, 0, 1);
+  int n = 1 / *x; // no-warning
+  free(x);
+}
+
+void testConcreteNull() {
+  int *x = 0;
+  memset(x, 0, 1); // expected-warning {{Null pointer argument in call to memory set function}}
+}
+
+void testStackArray() {
+  char buf[13];
+  memset(buf, 0, 1); // no-warning
+}
+
+void testHeapSymbol() {
+  char *buf = (char *)malloc(13);
+  memset(buf, 0, 1); // no-warning
+  free(buf);
+}
+
+void testStackArrayOutOfBound() {
+  char buf[1];
+  memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}}
+}
+
+void testHeapSymbolOutOfBound() {
+  char *buf = (char *)malloc(1);
+  memset(buf, 0, 1024); // expected-warning {{Memory set function accesses out-of-bound array element}}
+  free(buf);
+}
+
+void testStackArraySameSize() {
+  char buf[1];
+  memset(buf, 0, sizeof(buf)); // no-warning
+}
+
+void testHeapSymbolSameSize() {
+  char *buf = (char *)malloc(1);
+  memset(buf, 0, 1); // no-warning
+  free(buf);
+}
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -120,6 +120,7 @@
   void evalStdCopy(CheckerContext &C, const CallExpr *CE) const;
   void evalStdCopyBackward(CheckerContext &C, const CallExpr *CE) const;
   void evalStdCopyCommon(CheckerContext &C, const CallExpr *CE) const;
+  void evalMemset(CheckerContext &C, const CallExpr *CE) const;
 
   // Utility methods
   std::pair
@@ -1999,6 +2000,54 @@
   C.addTransition(State);
 }
 
+void CStringChecker::evalMemset(CheckerContext &C, const CallExpr *CE) const {
+  if (CE->getNumArgs() != 3)
+return;
+
+  CurrentFunctionDescription = "memory set function";
+
+  const Expr *Mem = CE->getArg(0);
+  const Expr *Size = CE->getArg(2);
+  ProgramStateRef State = C.getState();
+
+  // See if the size argument is zero.
+  const LocationContext *LCtx = C.getLocationContext();
+  SVal SizeVal = State->getSVal(Size, LCtx);
+  QualType SizeTy = Size->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+assumeZero(C, State, SizeVal, SizeTy);
+
+  // Get the value of the memory area.
+  SVal MemVal = State->getSVal(Mem, LCtx);
+
+  // If the size is zero, there won't be any actual memory access, so
+  // just bind the return value to the Mem buffer and return.
+  if (StateZeroSize && !StateNonZeroSize) {
+StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, MemVal);
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  // Ensure the memory area is not null.
+  // If it is NULL there will be a NULL pointer dereference.
+  State = checkNonNull(C, StateNonZeroSize, Mem, MemVal);
+  if (!State)
+return;
+
+  State = CheckBufferAccess(C, State, Size, Mem);
+  if (!State)
+return;
+  State = InvalidateBuffer(C, State, Mem, C.getSVal(Mem),
+   /*IsSourceBuffer*/false, Size);
+  if (!State)
+return;
+
+  State = State->BindExpr(CE, LCtx, MemVal);
+  C.addTransition(State);
+}
+
 static bool isCPPStdLibraryFunction(const FunctionDecl *FD, StringRef Name) {
   IdentifierInfo *II = FD->getIdentifier();
   if (!II)
@@ -2032,6 +2081,8 @@
 evalFunction =  &CStringChecker::evalMemcmp;
   else if (C.isCLibraryFunction(FDecl, "memmove"))
 evalFunction =  &CStringChecker::evalMemmove;
+  else if (C.isCLibraryFunction(FDecl, "memset"))
+evalFunction =  &CStringChecker::evalMemset;
   else if (C.isCLibraryFunction(FDecl, "strcpy"))
 evalFunction =  &CStringChecker::evalStrcpy;
   else if (C.isCLibrar

[PATCH] D33598: [libclang] [OpenCL] Expose CIndex functions for typedef and address space

2017-06-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks! sorry for the delay.


https://reviews.llvm.org/D33598



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


Re: r284060 - Implement MS _BitScan intrinsics

2017-06-07 Thread Saleem Abdulrasool via cfe-commits
I'm worried about changing this signature all the time.  I suspect that it
will cause the following to be emitted for valid code:

warning: incompatible pointer types passing 'unsigned long *' to parameter
of type 'unsigned int *' [-Wincompatible-pointer-types]

Switching the signature on LP64 sounds much better to me.

On Wed, Jun 7, 2017 at 2:56 PM, Duncan P. N. Exon Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> [... excuse the necromancy...]
>
> Hi Albert (and Reid and David),
>
> This commit is breaking some uses of -fms-extensions on Apple platforms.
> In particular, Brian and Erik (CC'ed) build against a version of the
> Windows SDK on Apple platforms.  _BitScanReverse is expected to be 32-bit,
> matching Windows/LLP64, even though long is 64-bit on Darwin/LP64.
>
> One idea we've had for fixing this is to use "int" instead of "long" for
> these intrinsics, either:
> - all the time, or
> - when in LP64 mode (e.g., Darwin + -fms-extensions).
>
> Any other ideas?
>
> Thanks,
> Duncan
>
> > On Oct 12, 2016, at 15:01, Albert Gutowski via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Author: agutowski
> > Date: Wed Oct 12 17:01:05 2016
> > New Revision: 284060
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=284060&view=rev
> > Log:
> > Implement MS _BitScan intrinsics
> >
> > Summary: _BitScan intrinsics (and some others, for example _Interlocked
> and _bittest) are supposed to work on both ARM and x86. This is an attempt
> to isolate them, avoiding repeating their code or writing separate function
> for each builtin.
> >
> > Reviewers: hans, thakis, rnk, majnemer
> >
> > Subscribers: RKSimon, cfe-commits, aemerson
> >
> > Differential Revision: https://reviews.llvm.org/D25264
> >
> > Modified:
> >cfe/trunk/include/clang/Basic/BuiltinsARM.def
> >cfe/trunk/include/clang/Basic/BuiltinsX86.def
> >cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
> >cfe/trunk/lib/Basic/Targets.cpp
> >cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> >cfe/trunk/lib/CodeGen/CodeGenFunction.h
> >cfe/trunk/lib/Headers/intrin.h
> >cfe/trunk/test/CodeGen/ms-intrinsics.c
> >
> > Modified: cfe/trunk/include/clang/Basic/BuiltinsARM.def
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/BuiltinsARM.def?rev=284060&r1=284059&r2=284060&view=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Basic/BuiltinsARM.def (original)
> > +++ cfe/trunk/include/clang/Basic/BuiltinsARM.def Wed Oct 12 17:01:05
> 2016
> > @@ -18,6 +18,10 @@
> > #   define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE,
> ATTRS)
> > #endif
> >
> > +#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN)
> > +#  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE)
> BUILTIN(ID, TYPE, ATTRS)
> > +#endif
> > +
> > // In libgcc
> > BUILTIN(__clear_cache, "vv*v*", "i")
> >
> > @@ -129,5 +133,11 @@ LANGBUILTIN(_MoveFromCoprocessor2, "UiIU
> > LANGBUILTIN(_MoveToCoprocessor, "vUiIUiIUiIUiIUiIUi", "",
> ALL_MS_LANGUAGES)
> > LANGBUILTIN(_MoveToCoprocessor2, "vUiIUiIUiIUiIUiIUi", "",
> ALL_MS_LANGUAGES)
> >
> > +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h",
> ALL_MS_LANGUAGES, "")
> > +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h",
> ALL_MS_LANGUAGES, "")
> > +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "n",
> "intrin.h", ALL_MS_LANGUAGES, "")
> > +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "n",
> "intrin.h", ALL_MS_LANGUAGES, "")
> > +
> > #undef BUILTIN
> > #undef LANGBUILTIN
> > +#undef TARGET_HEADER_BUILTIN
> >
> > Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/BuiltinsX86.def?rev=284060&r1=284059&r2=284060&view=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> > +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Oct 12 17:01:05
> 2016
> > @@ -2028,6 +2028,10 @@ TARGET_BUILTIN(__builtin_ia32_selectpd_5
> > TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "", "mwaitx")
> > TARGET_BUILTIN(__builtin_ia32_mwaitx, "vUiUiUi", "", "mwaitx")
> >
> > +// MSVC
> > +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h",
> ALL_MS_LANGUAGES, "")
> > +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h",
> ALL_MS_LANGUAGES, "")
> > +
> > TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h",
> ALL_MS_LANGUAGES, "")
> > TARGET_HEADER_BUILTIN(_ReadBarrier,  "v", "nh", "intrin.h",
> ALL_MS_LANGUAGES, "")
> > TARGET_HEADER_BUILTIN(_WriteBarrier, "v", "nh", "intrin.h",
> ALL_MS_LANGUAGES, "")
> >
> > Modified: cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/BuiltinsX86_64.def?rev=284060&r1=284059&r2=284060&view=diff
> > 

r304960 - Simplify.

2017-06-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Jun  7 21:05:55 2017
New Revision: 304960

URL: http://llvm.org/viewvc/llvm-project?rev=304960&view=rev
Log:
Simplify.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=304960&r1=304959&r2=304960&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jun  7 21:05:55 2017
@@ -11843,14 +11843,10 @@ ExprResult Sema::BuildBinOp(Scope *S, So
   std::any_of(OE->decls_begin(), OE->decls_end(), [](NamedDecl *ND) {
 return isa(ND);
   })) {
-if (OE->getQualifier()) {
-  Diag(OE->getQualifierLoc().getBeginLoc(),
-   diag::err_template_kw_missing)
-<< OE->getName().getAsString() << "";
-} else {
-  Diag(OE->getNameLoc(), diag::err_template_kw_missing)
-<< OE->getName().getAsString() << "";
-}
+Diag(OE->getQualifier() ? OE->getQualifierLoc().getBeginLoc()
+: OE->getNameLoc(),
+ diag::err_template_kw_missing)
+  << OE->getName().getAsString() << "";
 return ExprError();
   }
 }


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


Re: r304956 - [ODRHash] Change the fall-back diagnostic error.

2017-06-07 Thread Richard Trieu via cfe-commits
Yes, I will go correct the diagnostic text.

In theory, there is nothing that is supposed to reach this diagnostic or
the one below it.  Except that the hasher isn't complete yet and some
things slip through.  Once things are more stable, these should be replaced
with llvm_unreachable instead.

On Wed, Jun 7, 2017 at 6:05 PM, Richard Smith  wrote:

> On 7 June 2017 at 17:56, Richard Trieu via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rtrieu
>> Date: Wed Jun  7 19:56:21 2017
>> New Revision: 304956
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=304956&view=rev
>> Log:
>> [ODRHash] Change the fall-back diagnostic error.
>>
>> Provide a little more information when a ODR violation is detected, but
>> the
>> specific error could not be diagnosed.
>>
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
>> cfe/trunk/lib/Serialization/ASTReader.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/DiagnosticSerializationKinds.td?rev=304956&r1=304955&
>> r2=304956&view=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
>> (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Wed
>> Jun  7 19:56:21 2017
>> @@ -174,6 +174,13 @@ def note_module_odr_violation_mismatch_d
>>"method %2 with %ordinal3 parameter of type %4%select{| decayed from
>> %6}5|"
>>"method %2 with %ordinal3 parameter named %4}1">;
>>
>> +def err_module_odr_violation_mismatch_decl_unknown : Error<
>> +  "%q0 has different definitions in different modules; first difference
>> is "
>> +  "%select{definition in module '%2'|defined here}1 found different "
>> +  "%select{static assert|field|method|other}3">;
>> +def note_module_odr_violation_mismatch_decl_unknown : Note<
>> +  "but in '%0' found different %select{static
>> assert|field|method|other}1">;
>>
>
> This will produce messages like
>
> "first difference is defined here found different static assert"
> "first difference is definition in module 'X' found different other"
>
> ... which seem pretty confusing. Can this be rephrased so that it forms
> easier-to-read sentences? (Also, can we get some test coverage for this
> diagnostic?)
>
>
>> +
>>  def warn_duplicate_module_file_extension : Warning<
>>"duplicate module file extension block name '%0'">,
>>InGroup;
>>
>> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serializat
>> ion/ASTReader.cpp?rev=304956&r1=304955&r2=304956&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
>> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Jun  7 19:56:21 2017
>> @@ -9753,13 +9753,13 @@ void ASTReader::diagnoseOdrViolations()
>>if (Diagnosed == true)
>>  continue;
>>
>> -  Diag(FirstRecord->getLocation(),
>> -   diag::err_module_odr_violation_different_definitions)
>> -  << FirstRecord << FirstModule.empty() << FirstModule;
>> -
>> -  Diag(SecondRecord->getLocation(),
>> -   diag::note_module_odr_violation_different_definitions)
>> -  << SecondModule;
>> +  Diag(FirstDecl->getLocation(),
>> +   diag::err_module_odr_violation_mismatch_decl_unknown)
>> +  << FirstRecord << FirstModule.empty() << FirstModule <<
>> FirstDiffType
>> +  << FirstDecl->getSourceRange();
>> +  Diag(SecondDecl->getLocation(),
>> +   diag::note_module_odr_violation_mismatch_decl_unknown)
>> +  << SecondModule << FirstDiffType <<
>> SecondDecl->getSourceRange();
>>Diagnosed = true;
>>  }
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r304957 - Weaken restriction in r304862 to allow implicit deduction guides to reference

2017-06-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Jun  7 20:08:50 2017
New Revision: 304957

URL: http://llvm.org/viewvc/llvm-project?rev=304957&view=rev
Log:
Weaken restriction in r304862 to allow implicit deduction guides to reference
the injected-class-name of a specialization that uses a partial / explicit
specialization.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=304957&r1=304956&r2=304957&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jun  7 20:08:50 2017
@@ -7721,7 +7721,8 @@ public:
 const MultiLevelTemplateArgumentList 
&TemplateArgs);
 
   NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
-  const MultiLevelTemplateArgumentList &TemplateArgs);
+  const MultiLevelTemplateArgumentList &TemplateArgs,
+  bool FindingInstantiatedContext = false);
   DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
   const MultiLevelTemplateArgumentList &TemplateArgs);
 

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=304957&r1=304956&r2=304957&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Jun  7 20:08:50 2017
@@ -4807,7 +4807,7 @@ static NamedDecl *findInstantiationOf(AS
 DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC,
   const MultiLevelTemplateArgumentList &TemplateArgs) {
   if (NamedDecl *D = dyn_cast(DC)) {
-Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs);
+Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs, true);
 return cast_or_null(ID);
   } else return DC;
 }
@@ -4839,7 +4839,8 @@ DeclContext *Sema::FindInstantiatedConte
 /// (XKnownValue). \p FindInstantiatedDecl performs
 /// this mapping from within the instantiation of X.
 NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
-  const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const MultiLevelTemplateArgumentList &TemplateArgs,
+  bool FindingInstantiatedContext) {
   DeclContext *ParentDC = D->getDeclContext();
   // FIXME: Parmeters of pointer to functions (y below) that are themselves 
   // parameters (p below) can have their ParentDC set to the translation-unit
@@ -5007,8 +5008,9 @@ NamedDecl *Sema::FindInstantiatedDecl(So
   // meaningless to attempt to find an instantiation of D within the
   // specialization.)
   // FIXME: The standard doesn't say what should happen here.
-  if (usesPartialOrExplicitSpecialization(Loc,
-cast(SubstRecord))) {
+  if (FindingInstantiatedContext &&
+  usesPartialOrExplicitSpecialization(
+  Loc, cast(SubstRecord))) {
 Diag(Loc, diag::err_specialization_not_primary_template)
   << T << (SubstRecord->getTemplateSpecializationKind() ==
TSK_ExplicitSpecialization);

Modified: cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp?rev=304957&r1=304956&r2=304957&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp 
(original)
+++ cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Wed Jun  
7 20:08:50 2017
@@ -271,4 +271,12 @@ namespace tuple_tests {
 template <> class tuple<> {};
 tuple a = {1, 2, 3}; // expected-error {{no viable constructor or 
deduction guide}}
   }
+
+  namespace libcxx_3 {
+template struct scoped_lock {
+  scoped_lock(T...);
+};
+template<> struct scoped_lock<> {};
+scoped_lock l = {};
+  }
 }


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


Re: r304956 - [ODRHash] Change the fall-back diagnostic error.

2017-06-07 Thread Richard Smith via cfe-commits
On 7 June 2017 at 17:56, Richard Trieu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rtrieu
> Date: Wed Jun  7 19:56:21 2017
> New Revision: 304956
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304956&view=rev
> Log:
> [ODRHash] Change the fall-back diagnostic error.
>
> Provide a little more information when a ODR violation is detected, but the
> specific error could not be diagnosed.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
> cfe/trunk/lib/Serialization/ASTReader.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSerializationKinds.td?rev=304956&r1=304955&r2=304956&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
> (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Wed
> Jun  7 19:56:21 2017
> @@ -174,6 +174,13 @@ def note_module_odr_violation_mismatch_d
>"method %2 with %ordinal3 parameter of type %4%select{| decayed from
> %6}5|"
>"method %2 with %ordinal3 parameter named %4}1">;
>
> +def err_module_odr_violation_mismatch_decl_unknown : Error<
> +  "%q0 has different definitions in different modules; first difference
> is "
> +  "%select{definition in module '%2'|defined here}1 found different "
> +  "%select{static assert|field|method|other}3">;
> +def note_module_odr_violation_mismatch_decl_unknown : Note<
> +  "but in '%0' found different %select{static
> assert|field|method|other}1">;
>

This will produce messages like

"first difference is defined here found different static assert"
"first difference is definition in module 'X' found different other"

... which seem pretty confusing. Can this be rephrased so that it forms
easier-to-read sentences? (Also, can we get some test coverage for this
diagnostic?)


> +
>  def warn_duplicate_module_file_extension : Warning<
>"duplicate module file extension block name '%0'">,
>InGroup;
>
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Serialization/ASTReader.cpp?rev=304956&r1=304955&r2=304956&view=diff
> 
> ==
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Jun  7 19:56:21 2017
> @@ -9753,13 +9753,13 @@ void ASTReader::diagnoseOdrViolations()
>if (Diagnosed == true)
>  continue;
>
> -  Diag(FirstRecord->getLocation(),
> -   diag::err_module_odr_violation_different_definitions)
> -  << FirstRecord << FirstModule.empty() << FirstModule;
> -
> -  Diag(SecondRecord->getLocation(),
> -   diag::note_module_odr_violation_different_definitions)
> -  << SecondModule;
> +  Diag(FirstDecl->getLocation(),
> +   diag::err_module_odr_violation_mismatch_decl_unknown)
> +  << FirstRecord << FirstModule.empty() << FirstModule <<
> FirstDiffType
> +  << FirstDecl->getSourceRange();
> +  Diag(SecondDecl->getLocation(),
> +   diag::note_module_odr_violation_mismatch_decl_unknown)
> +  << SecondModule << FirstDiffType <<
> SecondDecl->getSourceRange();
>Diagnosed = true;
>  }
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r304956 - [ODRHash] Change the fall-back diagnostic error.

2017-06-07 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Wed Jun  7 19:56:21 2017
New Revision: 304956

URL: http://llvm.org/viewvc/llvm-project?rev=304956&view=rev
Log:
[ODRHash] Change the fall-back diagnostic error.

Provide a little more information when a ODR violation is detected, but the
specific error could not be diagnosed.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=304956&r1=304955&r2=304956&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Wed Jun  7 
19:56:21 2017
@@ -174,6 +174,13 @@ def note_module_odr_violation_mismatch_d
   "method %2 with %ordinal3 parameter of type %4%select{| decayed from %6}5|"
   "method %2 with %ordinal3 parameter named %4}1">;
 
+def err_module_odr_violation_mismatch_decl_unknown : Error<
+  "%q0 has different definitions in different modules; first difference is "
+  "%select{definition in module '%2'|defined here}1 found different "
+  "%select{static assert|field|method|other}3">;
+def note_module_odr_violation_mismatch_decl_unknown : Note<
+  "but in '%0' found different %select{static 
assert|field|method|other}1">;
+
 def warn_duplicate_module_file_extension : Warning<
   "duplicate module file extension block name '%0'">,
   InGroup;

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=304956&r1=304955&r2=304956&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Jun  7 19:56:21 2017
@@ -9753,13 +9753,13 @@ void ASTReader::diagnoseOdrViolations()
   if (Diagnosed == true)
 continue;
 
-  Diag(FirstRecord->getLocation(),
-   diag::err_module_odr_violation_different_definitions)
-  << FirstRecord << FirstModule.empty() << FirstModule;
-
-  Diag(SecondRecord->getLocation(),
-   diag::note_module_odr_violation_different_definitions)
-  << SecondModule;
+  Diag(FirstDecl->getLocation(),
+   diag::err_module_odr_violation_mismatch_decl_unknown)
+  << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType
+  << FirstDecl->getSourceRange();
+  Diag(SecondDecl->getLocation(),
+   diag::note_module_odr_violation_mismatch_decl_unknown)
+  << SecondModule << FirstDiffType << SecondDecl->getSourceRange();
   Diagnosed = true;
 }
 


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


[libcxx] r304955 - Fix class template deduction for scoped_lock.

2017-06-07 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jun  7 19:38:56 2017
New Revision: 304955

URL: http://llvm.org/viewvc/llvm-project?rev=304955&view=rev
Log:
Fix class template deduction for scoped_lock.

r304862 changed how CTD handles deducing a non-primary class template
using a non-dependent constructor of the primary template. This change
requires libc++ to provide explicit deduction guides to make scoped_lock
work again.

Modified:
libcxx/trunk/include/mutex

Modified: libcxx/trunk/include/mutex
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/mutex?rev=304955&r1=304954&r2=304955&view=diff
==
--- libcxx/trunk/include/mutex (original)
+++ libcxx/trunk/include/mutex Wed Jun  7 19:38:56 2017
@@ -502,7 +502,6 @@ public:
 _LIBCPP_INLINE_VISIBILITY
 explicit scoped_lock(mutex_type& __m, adopt_lock_t) 
_LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
 : __m_(__m) {}
-
 
 scoped_lock(scoped_lock const&) = delete;
 scoped_lock& operator=(scoped_lock const&) = delete;
@@ -547,6 +546,11 @@ private:
 _MutexTuple __t_;
 };
 
+#ifdef __cpp_deduction_guides
+template  explicit scoped_lock(_Mutex&) -> scoped_lock<_Mutex>;
+explicit scoped_lock() -> scoped_lock<>;
+#endif
+
 #endif // _LIBCPP_STD_VER > 14
 #endif // !_LIBCPP_HAS_NO_THREADS
 


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


[PATCH] D33478: [libclang] When getting platform availabilities, merge multiple declarations if possible

2017-06-07 Thread Ronald Wampler via Phabricator via cfe-commits
rdwampler marked an inline comment as done.
rdwampler added inline comments.



Comment at: test/Index/availability.c:20
 // CHECK-2: (macos, introduced=10.4, deprecated=10.5, obsoleted=10.7)
 
 // CHECK-2: EnumConstantDecl=old_enum:6:3 (Definition) (deprecated)

Can we run `FileCheck` once now? I believe the `CHECK-1` and `CHECK-2` were 
added since there were no particular order for the availabilities. With this 
patch the order is guarantee to be stable.



Comment at: tools/libclang/CIndex.cpp:7268
+(!LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()) ||
+(!LHS->getMessage().empty() && !RHS->getMessage().empty()))
+  return false;

arphaman wrote:
> I think that we don't really need the `(!LHS->getMessage().empty() && 
> !RHS->getMessage().empty())` check here since message has to be either in a 
> deprecated or obsoleted clause, so we should already handle that with 
> previous checks.
Agreed.


https://reviews.llvm.org/D33478



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


[PATCH] D34018: Support __float128 on NetBSD libstdc++ x86/x86_64

2017-06-07 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski created this revision.

This adds support for __float128 from GNU libstdc++ with Clang on NetBSD 
x86/x86_64 targets.

This corrects compilation at least of CMake and probably others like Firefox.

In file included from 
/tmp/pkgsrc-tmp/devel/cmake/work/cmake-3.8.2/Source/kwsys/Directory.cxx:4:
In file included from 
/tmp/pkgsrc-tmp/devel/cmake/work/cmake-3.8.2/Source/cmsys/Directory.hxx:8:
In file included from /usr/include/g++/string:40:
In file included from /usr/include/g++/bits/char_traits.h:39:
In file included from /usr/include/g++/bits/stl_algobase.h:64:
In file included from /usr/include/g++/bits/stl_pair.h:59:
In file included from /usr/include/g++/bits/move.h:57:
/usr/include/g++/type_traits:311:39: error: __float128 is not supported on this 
target

  struct __is_floating_point_helper<__float128>
^

Sponsored by 


Repository:
  rL LLVM

https://reviews.llvm.org/D34018

Files:
  lib/Basic/Targets.cpp


Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -514,6 +514,8 @@
 Builder.defineMacro("__ELF__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
 
 switch (Triple.getArch()) {
 default:
@@ -530,6 +532,15 @@
   NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : OSTargetInfo(Triple, Opts) {
 this->MCountName = "_mcount";
+
+switch (Triple.getArch()) {
+default:
+  break;
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  break;
+}
   }
 };
 


Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -514,6 +514,8 @@
 Builder.defineMacro("__ELF__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
 
 switch (Triple.getArch()) {
 default:
@@ -530,6 +532,15 @@
   NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : OSTargetInfo(Triple, Opts) {
 this->MCountName = "_mcount";
+
+switch (Triple.getArch()) {
+default:
+  break;
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  break;
+}
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: r304935 - Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt

2017-06-07 Thread Petar Jovanovic via cfe-commits
I reverted the patch too quickly and have not noticed the file was not
actually deleted. I am reapplying the patch with minor modifications now,
hopefully no issues this time.

Thanks.

Regards,
Petar

From: Simon Dardis
Sent: Wednesday, June 07, 2017 10:36 PM
To: Evgenii Stepanov; Petar Jovanovic
Cc: cfe-commits
Subject: RE: r304935 - Revert r304929 [mips] Add runtime options to 
enable/disable madd/sub.fmt

Appears to be fixed, r304936. I'll keep an eye on the buildbots.

Thanks,
Simon

From: cfe-commits [cfe-commits-boun...@lists.llvm.org] on behalf of Evgenii 
Stepanov via cfe-commits [cfe-commits@lists.llvm.org]
Sent: 07 June 2017 20:53
To: Petar Jovanovic
Cc: cfe-commits
Subject: Re: r304935 - Revert r304929 [mips] Add runtime options to 
enable/disable madd/sub.fmt

You've left an empty file in test/CodeGen/mips-madd4.c

On Wed, Jun 7, 2017 at 11:57 AM, Petar Jovanovic via cfe-commits
 wrote:
> Author: petarj
> Date: Wed Jun  7 13:57:56 2017
> New Revision: 304935
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304935&view=rev
> Log:
> Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt
>
> Revert r304929 since the test broke buildbots.
>
> Original commit:
>
>   [mips] Add runtime options to enable/disable madd.fmt and msub.fmt
>
>   Add options to clang: -mmadd4 and -mno-madd4, use it to enable or disable
>   generation of madd.fmt and similar instructions respectively, as per GCC.
>
>   Patch by Stefan Maksimovic.
>
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
> cfe/trunk/test/CodeGen/mips-madd4.c
> cfe/trunk/test/Preprocessor/init.c
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Wed Jun  7 13:57:56 2017
> @@ -2001,10 +2001,6 @@ def mdspr2 : Flag<["-"], "mdspr2">, Grou
>  def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group;
>  def msingle_float : Flag<["-"], "msingle-float">, Group;
>  def mdouble_float : Flag<["-"], "mdouble-float">, Group;
> -def mmadd4 : Flag<["-"], "mmadd4">, Group,
> -  HelpText<"Enable the generation of 4-operand madd.s, madd.d and related 
> instructions.">;
> -def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
> -  HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
> instructions.">;
>  def mmsa : Flag<["-"], "mmsa">, Group,
>HelpText<"Enable MSA ASE (MIPS only)">;
>  def mno_msa : Flag<["-"], "mno-msa">, Group,
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun  7 13:57:56 2017
> @@ -7737,7 +7737,6 @@ class MipsTargetInfo : public TargetInfo
>  NoDSP, DSP1, DSP2
>} DspRev;
>bool HasMSA;
> -  bool DisableMadd4;
>
>  protected:
>bool HasFP64;
> @@ -7748,7 +7747,7 @@ public:
>: TargetInfo(Triple), IsMips16(false), IsMicromips(false),
>  IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
>  CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
> -HasMSA(false), DisableMadd4(false), HasFP64(false) {
> +HasMSA(false), HasFP64(false) {
>  TheCXXABI.set(TargetCXXABI::GenericMIPS);
>
>  setABI((getTriple().getArch() == llvm::Triple::mips ||
> @@ -7994,9 +7993,6 @@ public:
>  if (HasMSA)
>Builder.defineMacro("__mips_msa", Twine(1));
>
> -if (DisableMadd4)
> -  Builder.defineMacro("__mips_no_madd4", Twine(1));
> -
>  Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
>  Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
>  Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
> @@ -8159,8 +8155,6 @@ public:
>  DspRev = std::max(DspRev, DSP2);
>else if (Feature == "+msa")
>  HasMSA = true;
> -  else if (Feature == "+nomadd4")
> -DisableMadd4 = true;
>else if (Feature == "+fp64")
>  HasFP64 = true;
>else if (Feature == "-fp64")
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jun  7 13:57:56 2017
> @@ -298,13 +298,6

r304953 - Reapply r304929 [mips] Add runtime options to enable/disable madd/sub.fmt

2017-06-07 Thread Petar Jovanovic via cfe-commits
Author: petarj
Date: Wed Jun  7 18:51:52 2017
New Revision: 304953

URL: http://llvm.org/viewvc/llvm-project?rev=304953&view=rev
Log:
Reapply r304929 [mips] Add runtime options to enable/disable madd/sub.fmt

The test in r304929 broke multiple buildbots as it expected mips target to
be registered and available (which is not necessarily true). Updating the
test with this condition.

Original commit:

  [mips] Add runtime options to enable/disable madd.fmt and msub.fmt

  Add options to clang: -mmadd4 and -mno-madd4, use it to enable or disable
  generation of madd.fmt and similar instructions respectively, as per GCC.

  Patch by Stefan Maksimovic.

Added:
cfe/trunk/test/CodeGen/mips-madd4.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=304953&r1=304952&r2=304953&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jun  7 18:51:52 2017
@@ -2001,6 +2001,10 @@ def mdspr2 : Flag<["-"], "mdspr2">, Grou
 def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group;
 def msingle_float : Flag<["-"], "msingle-float">, Group;
 def mdouble_float : Flag<["-"], "mdouble-float">, Group;
+def mmadd4 : Flag<["-"], "mmadd4">, Group,
+  HelpText<"Enable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
+def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
+  HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
   HelpText<"Enable MSA ASE (MIPS only)">;
 def mno_msa : Flag<["-"], "mno-msa">, Group,

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304953&r1=304952&r2=304953&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun  7 18:51:52 2017
@@ -7737,6 +7737,7 @@ class MipsTargetInfo : public TargetInfo
 NoDSP, DSP1, DSP2
   } DspRev;
   bool HasMSA;
+  bool DisableMadd4;
 
 protected:
   bool HasFP64;
@@ -7747,7 +7748,7 @@ public:
   : TargetInfo(Triple), IsMips16(false), IsMicromips(false),
 IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
 CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
-HasMSA(false), HasFP64(false) {
+HasMSA(false), DisableMadd4(false), HasFP64(false) {
 TheCXXABI.set(TargetCXXABI::GenericMIPS);
 
 setABI((getTriple().getArch() == llvm::Triple::mips ||
@@ -7993,6 +7994,9 @@ public:
 if (HasMSA)
   Builder.defineMacro("__mips_msa", Twine(1));
 
+if (DisableMadd4)
+  Builder.defineMacro("__mips_no_madd4", Twine(1));
+
 Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
 Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
 Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
@@ -8155,6 +8159,8 @@ public:
 DspRev = std::max(DspRev, DSP2);
   else if (Feature == "+msa")
 HasMSA = true;
+  else if (Feature == "+nomadd4")
+DisableMadd4 = true;
   else if (Feature == "+fp64")
 HasFP64 = true;
   else if (Feature == "-fp64")

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=304953&r1=304952&r2=304953&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jun  7 18:51:52 2017
@@ -298,6 +298,13 @@ void mips::getMIPSTargetFeatures(const D
 
   AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
options::OPT_modd_spreg, "nooddspreg");
+
+  if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) {
+if (A->getOption().matches(options::OPT_mmadd4))
+  Features.push_back("-nomadd4");
+else
+  Features.push_back("+nomadd4");
+  }
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) {

Added: cfe/trunk/test/CodeGen/mips-madd4.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips-madd4.c?rev=304953&view=auto
==
--- cfe/trunk/test/CodeGen/mips-madd4.c (added)
+++ cfe/trunk/test/CodeGen/mips-madd4.c Wed Jun  7 18:51:52 2017
@@ -0,0 +1,87 @@
+// REQUIRES: mips-registered-target
+// RUN: %clang --target=mips64-unknown-linux -S -mmadd4%s -o -| FileCheck 
%s -check-prefix=MADD4
+// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 %s -o -| 

[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

btw, here's how I built it, in case that matters...

CC=../../4.0.0/build/Release/bin/clang 
CXX=../../4.0.0/build/Release/bin/clang++  \
 cmake ../../llvm/ \
 -GNinja \
 -DLLVM_USE_SANITIZER=Address \
 -DCMAKE_BUILD_TYPE=Debug \
 -DLLVM_TARGETS_TO_BUILD="X86" \
 -DLLVM_PARALLEL_LINK_JOBS=4


https://reviews.llvm.org/D20693



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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

Just ran asan on linux and we have a heap-use-after-free in the std::string 
ctor.

Here's a partial stack dump:

4980==ERROR: AddressSanitizer: heap-use-after-free on address 0x60424328 at 
pc 0x0057ad32 bp 0x7ffd240a7f50 sp 0x7ffd240a7700
-

READ of size 8 at 0x60424328 thread T0

  #0 0x57ad31 in __interceptor_memcpy.part.36 
/home/d80049854/projects/clang/4.0.0/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:655
  #1 0x6c5960 in char* std::string::_S_construct(char const*, char 
const*, std::allocator const&, std::forward_iterator_tag) 
/usr/lib/gcc/x86_64-linux-gnu/6.2.0/../../../../include/c+

+/6.2.0/bits/basic_string.tcc:580:6

  #2 0x7fe7bd7bc98a in std::basic_string, 
std::allocator >::basic_string(char const*, unsigned long, 
std::allocator const&) (/usr/lib/x86_64-linux-gnu/libstdc++.

so.6+0xc598a)

  #3 0x67b89f in llvm::StringRef::str() const 
/home/d80049854/projects/clang/llvm/include/llvm/ADT/StringRef.h:230:14
  #4 0x67b3dd in llvm::StringRef::operator std::string() const 
/home/d80049854/projects/clang/llvm/include/llvm/ADT/StringRef.h:257:14
  #5 0xd679d2 in clang::FixItHint::CreateReplacement(clang::CharSourceRange, 
llvm::StringRef) 
/home/d80049854/projects/clang/llvm/tools/clang/include/clang/Basic/Diagnostic.h:131:25
  #6 0x1213006 in 
clang::tidy::modernize::UseNoexceptCheck::check(clang::ast_matchers::MatchFinder::MatchResult
 const&) 
/home/d80049854/projects/clang/llvm/tools/clang/tools/extra/clang-tidy/modernize/U

$ ../../4.0.0/build/Release/bin/clang -v
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: 
/home/d80049854/projects/clang/build/Debug/../../4.0.0/build/Release/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

stdlibc++ from gcc 6.2:

$ g++-6 -v
Using built-in specs.
COLLECT_GCC=g++-6
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
6.2.0-3ubuntu11~14.04' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs 
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-6 --enable-shared --enable-linker-build-id 
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix 
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=gcc4-compatible --disable-libstdcxx-dual-abi 
--enable-gnu-unique-object --disable-vtable-verify --enable-libmpx 
--enable-plugin --with-system-zlib --disable-browser-plugin 
--enable-java-awt=gtk --enable-gtk-cairo 
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home 
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar 
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib 
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20160901 (Ubuntu 6.2.0-3ubuntu11~14.04)

$ ldd bin/clang-tidy

  linux-vdso.so.1 =>  (0x7ffde1996000)
  libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x7f6104f2a000)
  librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x7f6104d22000)
  libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x7f6104b1e000)
  libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x7f61048f5000)
  libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x7f61045ef000)
  libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 
(0x7f61042dd000)
  libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x7f61040c6000)
  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x7f6103d01000)
  /lib64/ld-linux-x86-64.so.2 (0x7f6105148000)


https://reviews.llvm.org/D20693



___

[PATCH] D17215: [Sema] Fix PR14211 Crash for explicit instantiation of overloaded template function within class template

2017-06-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Sure thing, r304951.


https://reviews.llvm.org/D17215



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


r304951 - When determining the target function of an explicit instantiation, make

2017-06-07 Thread John McCall via cfe-commits
Author: rjmccall
Date: Wed Jun  7 18:00:05 2017
New Revision: 304951

URL: http://llvm.org/viewvc/llvm-project?rev=304951&view=rev
Log:
When determining the target function of an explicit instantiation, make
sure that non-template functions don't end up in the candidate set.

Fixes PR14211.

Patch by Don Hinton!

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=304951&r1=304950&r2=304951&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Jun  7 18:00:05 2017
@@ -8957,7 +8957,8 @@ DeclResult Sema::ActOnExplicitInstantiat
   //   A member function [...] of a class template can be explicitly
   //  instantiated from the member definition associated with its class
   //  template.
-  UnresolvedSet<8> Matches;
+  UnresolvedSet<8> TemplateMatches;
+  FunctionDecl *NonTemplateMatch = nullptr;
   AttributeList *Attr = D.getDeclSpec().getAttributes().getList();
   TemplateSpecCandidateSet FailedCandidates(D.getIdentifierLoc());
   for (LookupResult::iterator P = Previous.begin(), PEnd = Previous.end();
@@ -8968,11 +8969,13 @@ DeclResult Sema::ActOnExplicitInstantiat
 QualType Adjusted = adjustCCAndNoReturn(R, Method->getType(),
 /*AdjustExceptionSpec*/true);
 if (Context.hasSameUnqualifiedType(Method->getType(), Adjusted)) {
-  Matches.clear();
-
-  Matches.addDecl(Method, P.getAccess());
-  if (Method->getTemplateSpecializationKind() == TSK_Undeclared)
-break;
+  if (Method->getPrimaryTemplate()) {
+TemplateMatches.addDecl(Method, P.getAccess());
+  } else {
+// FIXME: Can this assert ever happen?  Needs a test.
+assert(!NonTemplateMatch && "Multiple NonTemplateMatches");
+NonTemplateMatch = Method;
+  }
 }
   }
 }
@@ -9011,22 +9014,25 @@ DeclResult Sema::ActOnExplicitInstantiat
   continue;
 }
 
-Matches.addDecl(Specialization, P.getAccess());
+TemplateMatches.addDecl(Specialization, P.getAccess());
   }
 
-  // Find the most specialized function template specialization.
-  UnresolvedSetIterator Result = getMostSpecialized(
-  Matches.begin(), Matches.end(), FailedCandidates,
-  D.getIdentifierLoc(),
-  PDiag(diag::err_explicit_instantiation_not_known) << Name,
-  PDiag(diag::err_explicit_instantiation_ambiguous) << Name,
-  PDiag(diag::note_explicit_instantiation_candidate));
+  FunctionDecl *Specialization = NonTemplateMatch;
+  if (!Specialization) {
+// Find the most specialized function template specialization.
+UnresolvedSetIterator Result = getMostSpecialized(
+TemplateMatches.begin(), TemplateMatches.end(), FailedCandidates,
+D.getIdentifierLoc(),
+PDiag(diag::err_explicit_instantiation_not_known) << Name,
+PDiag(diag::err_explicit_instantiation_ambiguous) << Name,
+PDiag(diag::note_explicit_instantiation_candidate));
 
-  if (Result == Matches.end())
-return true;
+if (Result == TemplateMatches.end())
+  return true;
 
-  // Ignore access control bits, we don't need them for redeclaration checking.
-  FunctionDecl *Specialization = cast(*Result);
+// Ignore access control bits, we don't need them for redeclaration 
checking.
+Specialization = cast(*Result);
+  }
 
   // C++11 [except.spec]p4
   // In an explicit instantiation an exception-specification may be specified,

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp?rev=304951&r1=304950&r2=304951&view=diff
==
--- cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p5.cpp Wed Jun  7 18:00:05 2017
@@ -77,3 +77,16 @@ void test_X0(X0 x0, const X0 &x0c) {
   x0.operator float *();
   x0c.operator const char*();
 }
+
+namespace PR14211 {
+template  struct X {
+  void foo(U){}
+  template  void foo(T){}
+
+  template  void bar(T){}
+  void bar(U){}
+};
+
+template void X::foo(int);
+template void X::bar(int);
+}


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


[PATCH] D34007: Implement inclusive_scan and transform_inclusive_scan

2017-06-07 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists abandoned this revision.
mclow.lists added a comment.

I don't think that this is a correct implementation. Also, I need tests for 
when the result overwrites the source.
As they say .. I'll be back :-)


https://reviews.llvm.org/D34007



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


[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

2017-06-07 Thread Yan Wang via Phabricator via cfe-commits
yawanng updated this revision to Diff 101834.
yawanng marked an inline comment as done.

https://reviews.llvm.org/D34002

Files:
  clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
  test/clang-tidy/misc-noexcept-move-constructor.cpp


Index: test/clang-tidy/misc-noexcept-move-constructor.cpp
===
--- test/clang-tidy/misc-noexcept-move-constructor.cpp
+++ test/clang-tidy/misc-noexcept-move-constructor.cpp
@@ -1,16 +1,25 @@
-// RUN: %check_clang_tidy %s misc-noexcept-move-constructor %t
+// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- 
-std=c++11 \
+// RUN:   | FileCheck %s -check-prefix=CHECK-EXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- 
-fno-exceptions -std=c++11 \
+// RUN:   | FileCheck %s -allow-empty -check-prefix=CHECK-NONEXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+
 
 class A {
   A(A &&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be 
marked noexcept [misc-noexcept-move-constructor]
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: move constructors should be 
marked noexcept [misc-noexcept-move-constructor]
+  // CHECK-NONEXCEPTIONS-NOT: warning:
   A &operator=(A &&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: move assignment operators 
should
+  // CHECK-NONEXCEPTIONS-NOT: warning:
 };
 
 struct B {
   static constexpr bool kFalse = false;
   B(B &&) noexcept(kFalse);
-  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move 
constructor evaluates to 'false' [misc-noexcept-move-constructor]
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:20: warning: noexcept specifier on the 
move constructor evaluates to 'false' [misc-noexcept-move-constructor]
+  // CHECK-NONEXCEPTIONS-NOT: warning:
 };
 
 class OK {};
Index: clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
===
--- clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
+++ clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
@@ -20,7 +20,7 @@
 void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++11; the functionality currently does not
   // provide any benefit to other languages, despite being benign.
-  if (!getLangOpts().CPlusPlus11)
+  if (!getLangOpts().CPlusPlus11 || !getLangOpts().CXXExceptions)
 return;
 
   Finder->addMatcher(


Index: test/clang-tidy/misc-noexcept-move-constructor.cpp
===
--- test/clang-tidy/misc-noexcept-move-constructor.cpp
+++ test/clang-tidy/misc-noexcept-move-constructor.cpp
@@ -1,16 +1,25 @@
-// RUN: %check_clang_tidy %s misc-noexcept-move-constructor %t
+// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- -std=c++11 \
+// RUN:   | FileCheck %s -check-prefix=CHECK-EXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- -fno-exceptions -std=c++11 \
+// RUN:   | FileCheck %s -allow-empty -check-prefix=CHECK-NONEXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+
 
 class A {
   A(A &&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [misc-noexcept-move-constructor]
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [misc-noexcept-move-constructor]
+  // CHECK-NONEXCEPTIONS-NOT: warning:
   A &operator=(A &&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: move assignment operators should
+  // CHECK-NONEXCEPTIONS-NOT: warning:
 };
 
 struct B {
   static constexpr bool kFalse = false;
   B(B &&) noexcept(kFalse);
-  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [misc-noexcept-move-constructor]
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [misc-noexcept-move-constructor]
+  // CHECK-NONEXCEPTIONS-NOT: warning:
 };
 
 class OK {};
Index: clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
===
--- clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
+++ clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
@@ -20,7 +20,7 @@
 void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++11; the functionality currently does not
   // provide any benefit to other languages, despite being benign.
-  if (!getLangOpts().CPlusPlus11)
+  if (!getLangOpts().CPlusPlus11 || !getLangOpts().CXXExceptions)
 return;
 
   Finder->addMatcher(
___
cfe-commits mailing list
cfe-commits@list

[PATCH] D33735: [DebugInfo] Add ThisOrSelf attribute for emission of FlagObjectPointer.

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



Comment at: include/clang/AST/Decl.h:1387
+IPK_CapturedContext, /// Parameter for captured context
+IPK_GeneralParam,/// General implicit parameter
+  };

ABataev wrote:
> rjmccall wrote:
> > I would just call this "Other" and document it as being for kinds of 
> > implicit parameters that we haven't seen a purpose in categorizing yet.  
> > (Or you could just classify them all, I suppose.)
> > 
> > We can use C++11 features in Clang now, so I would recommend hoisting this 
> > type out of ImplicitParamDecl and making it an enum class.  You can then 
> > drop the "IPK_" prefixes.
> It's hard to classify them, in most cases they just represent some general 
> parameters used for correct codegen of function types and that's it.
That's fair.



Comment at: include/clang/AST/Decl.h:901
+/// member functions.
+unsigned ImplicitParamKind : 3;
   };

ABataev wrote:
> aaron.ballman wrote:
> > ABataev wrote:
> > > aaron.ballman wrote:
> > > > It's a bit strange to me that the non-parameter declaration bits now 
> > > > have a field for implicit parameter information. Why here instead of 
> > > > `ParmVarDeclBits`?
> > > Actually, `ImplicitParamDecl` already uses some bits from the 
> > > `NonParmVarDeclBitfields`, at least it may be marked as `ARCPseudoStrong` 
> > > for ObjC. That's why I had to reuse `NonParmVarDeclBitfields` part.
> > Ew. That's nasty and we should probably fix that (not as part of this 
> > patch). Can you add a FIXME here?
> Ok, I will add FIXME for `ARCPseudoStrong` and for the `ImplicitParamKind` 
> bitfields
The FIXME doesn't make sense because ImplicitParamDecl is not a subclass of 
ParamVarDecl.

The comment here needs to be updated.


https://reviews.llvm.org/D33735



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


[PATCH] D33304: [clang-tidy][Part1] Add a new module Android and three new checks.

2017-06-07 Thread Yan Wang via Phabricator via cfe-commits
yawanng updated this revision to Diff 101831.
yawanng marked an inline comment as done.

https://reviews.llvm.org/D33304

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/android/AndroidTidyModule.cpp
  clang-tidy/android/CMakeLists.txt
  clang-tidy/android/FileOpenFlagCheck.cpp
  clang-tidy/android/FileOpenFlagCheck.h
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/android-file-open-flag.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/android-file-open-flag.cpp
  unittests/clang-tidy/CMakeLists.txt

Index: unittests/clang-tidy/CMakeLists.txt
===
--- unittests/clang-tidy/CMakeLists.txt
+++ unittests/clang-tidy/CMakeLists.txt
@@ -25,6 +25,7 @@
   clangFrontend
   clangLex
   clangTidy
+  clangTidyAndroidModule
   clangTidyGoogleModule
   clangTidyLLVMModule
   clangTidyMiscModule
Index: test/clang-tidy/android-file-open-flag.cpp
===
--- /dev/null
+++ test/clang-tidy/android-file-open-flag.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s android-file-open-flag %t
+
+#define O_RDWR 1
+#define O_EXCL 2
+#define __O_CLOEXEC 3
+#define O_CLOEXEC __O_CLOEXEC
+
+extern "C" int open(const char *fn, int flags, ...);
+extern "C" int open64(const char *fn, int flags, ...);
+extern "C" int openat(int dirfd, const char *pathname, int flags, ...);
+
+void a() {
+  open("filename", O_RDWR);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: open should use O_CLOEXEC where possible [android-file-open-flag]
+  // CHECK-FIXES: O_RDWR | O_CLOEXEC
+  open("filename", O_RDWR | O_EXCL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: open should use O_CLOEXEC where
+  // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
+}
+
+void b() {
+  open64("filename", O_RDWR);
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: open64 should use O_CLOEXEC where possible [android-file-open-flag]
+  // CHECK-FIXES: O_RDWR | O_CLOEXEC
+  open64("filename", O_RDWR | O_EXCL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: open64 should use O_CLOEXEC where
+  // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
+}
+
+void c() {
+  openat(0, "filename", O_RDWR);
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: openat should use O_CLOEXEC where possible [android-file-open-flag]
+  // CHECK-FIXES: O_RDWR | O_CLOEXEC
+  openat(0, "filename", O_RDWR | O_EXCL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: openat should use O_CLOEXEC where
+  // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
+}
+
+void f() {
+  open("filename", 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: open should use O_CLOEXEC where possible [android-file-open-flag]
+  // CHECK-FIXES: 3 | O_CLOEXEC
+  open64("filename", 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: open64 should use O_CLOEXEC where possible [android-file-open-flag]
+  // CHECK-FIXES: 3 | O_CLOEXEC
+  openat(0, "filename", 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: openat should use O_CLOEXEC where possible [android-file-open-flag]
+  // CHECK-FIXES: 3 | O_CLOEXEC
+
+  int flag = 3;
+  open("filename", flag);
+  // CHECK-MESSAGES-NOT: warning:
+  open64("filename", flag);
+  // CHECK-MESSAGES-NOT: warning:
+  openat(0, "filename", flag);
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+namespace i {
+int open(const char *pathname, int flags, ...);
+int open64(const char *pathname, int flags, ...);
+int openat(int dirfd, const char *pathname, int flags, ...);
+
+void d() {
+  open("filename", O_RDWR);
+  // CHECK-MESSAGES-NOT: warning:
+  open64("filename", O_RDWR);
+  // CHECK-MESSAGES-NOT: warning:
+  openat(0, "filename", O_RDWR);
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+} // namespace i
+
+void e() {
+  open("filename", O_CLOEXEC);
+  // CHECK-MESSAGES-NOT: warning:
+  open("filename", O_RDWR | O_CLOEXEC);
+  // CHECK-MESSAGES-NOT: warning:
+  open64("filename", O_CLOEXEC);
+  // CHECK-MESSAGES-NOT: warning:
+  open64("filename", O_RDWR | O_CLOEXEC);
+  // CHECK-MESSAGES-NOT: warning:
+  openat(0, "filename", O_CLOEXEC);
+  // CHECK-MESSAGES-NOT: warning:
+  openat(0, "filename", O_RDWR | O_CLOEXEC);
+  // CHECK-MESSAGES-NOT: warning:
+}
+
+class G {
+public:
+  int open(const char *pathname, int flags, ...);
+  int open64(const char *pathname, int flags, ...);
+  int openat(int dirfd, const char *pathname, int flags, ...);
+
+  void h() {
+open("filename", O_RDWR);
+// CHECK-MESSAGES-NOT: warning:
+open64("filename", O_RDWR);
+// CHECK-MESSAGES-NOT: warning:
+openat(0, "filename", O_RDWR);
+// CHECK-MESSAGES-NOT: warning:
+  }
+};
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -55,6 +55,7 @@
 == =
 Name prefixDescription
 

Re: r284060 - Implement MS _BitScan intrinsics

2017-06-07 Thread Duncan P. N. Exon Smith via cfe-commits
[... excuse the necromancy...]

Hi Albert (and Reid and David),

This commit is breaking some uses of -fms-extensions on Apple platforms.  In 
particular, Brian and Erik (CC'ed) build against a version of the Windows SDK 
on Apple platforms.  _BitScanReverse is expected to be 32-bit, matching 
Windows/LLP64, even though long is 64-bit on Darwin/LP64.

One idea we've had for fixing this is to use "int" instead of "long" for these 
intrinsics, either:
- all the time, or
- when in LP64 mode (e.g., Darwin + -fms-extensions).

Any other ideas?

Thanks,
Duncan

> On Oct 12, 2016, at 15:01, Albert Gutowski via cfe-commits 
>  wrote:
> 
> Author: agutowski
> Date: Wed Oct 12 17:01:05 2016
> New Revision: 284060
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=284060&view=rev
> Log:
> Implement MS _BitScan intrinsics
> 
> Summary: _BitScan intrinsics (and some others, for example _Interlocked and 
> _bittest) are supposed to work on both ARM and x86. This is an attempt to 
> isolate them, avoiding repeating their code or writing separate function for 
> each builtin.
> 
> Reviewers: hans, thakis, rnk, majnemer
> 
> Subscribers: RKSimon, cfe-commits, aemerson
> 
> Differential Revision: https://reviews.llvm.org/D25264
> 
> Modified:
>cfe/trunk/include/clang/Basic/BuiltinsARM.def
>cfe/trunk/include/clang/Basic/BuiltinsX86.def
>cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
>cfe/trunk/lib/Basic/Targets.cpp
>cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>cfe/trunk/lib/CodeGen/CodeGenFunction.h
>cfe/trunk/lib/Headers/intrin.h
>cfe/trunk/test/CodeGen/ms-intrinsics.c
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsARM.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsARM.def?rev=284060&r1=284059&r2=284060&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsARM.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsARM.def Wed Oct 12 17:01:05 2016
> @@ -18,6 +18,10 @@
> #   define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
> #endif
> 
> +#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN)
> +#  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
> BUILTIN(ID, TYPE, ATTRS)
> +#endif
> +
> // In libgcc
> BUILTIN(__clear_cache, "vv*v*", "i")
> 
> @@ -129,5 +133,11 @@ LANGBUILTIN(_MoveFromCoprocessor2, "UiIU
> LANGBUILTIN(_MoveToCoprocessor, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)
> LANGBUILTIN(_MoveToCoprocessor2, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)
> 
> +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +
> #undef BUILTIN
> #undef LANGBUILTIN
> +#undef TARGET_HEADER_BUILTIN
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=284060&r1=284059&r2=284060&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Oct 12 17:01:05 2016
> @@ -2028,6 +2028,10 @@ TARGET_BUILTIN(__builtin_ia32_selectpd_5
> TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "", "mwaitx")
> TARGET_BUILTIN(__builtin_ia32_mwaitx, "vUiUiUi", "", "mwaitx")
> 
> +// MSVC
> +TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +
> TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> TARGET_HEADER_BUILTIN(_ReadBarrier,  "v", "nh", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> TARGET_HEADER_BUILTIN(_WriteBarrier, "v", "nh", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86_64.def?rev=284060&r1=284059&r2=284060&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86_64.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86_64.def Wed Oct 12 17:01:05 2016
> @@ -22,6 +22,9 @@
> #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
> BUILTIN(ID, TYPE, ATTRS)
> #endif
> 
> +TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "n", "intrin.h", 
> ALL_MS_LANGUAGES, "")
> +
> TARGET_HEADER_BUILTIN(__mulh,  "LLiLLiLLi","nch", "intrin.h", 
> ALL_MS_L

[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 101819.
hintonda added a comment.

- Rollback last change.


https://reviews.llvm.org/D20693

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept-opt.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A {};
+class B {};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+template 
+void foo() throw();
+void footest() { foo(); foo(); }
+// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw(...)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void k() throw(int(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void k() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+void baz(int = (throw A(), 0)) throw(A, B) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void baz(int = (throw A(), 0)) noexcept(false) {}
+
+void g(void (*fp)(void) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void g(void (*fp)(void) noexcept);
+
+void f(void (*fp)(void) throw(int)) throw(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'throw(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void f(void (*fp)(void) noexcept(false)) noexcept(false);
+
+#define THROW throw
+void h(void (*fp)(void) THROW(int)) THROW(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'THROW(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'THROW(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void h(void (*fp)(void) noexcept(false)) noexcept(false);
+
+void j() throw(int(int) throw(void(void) throw(int)));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int) throw(void(void) throw(int)))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void j() noexcept(false);
+
+class Y {
+  Y() throw() = default;
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: Y() noexcept = default;
+
+struct Z {
+  void operator delete(void *ptr) throw();
+  void operator delete[](void *ptr) throw(int);
+  ~Z() throw(int) {}
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void operator delete(void *ptr) noexcept;
+// CHECK-FIXES: void operator delete[](void *ptr) noexcept(false);
+// CHECK-FIXES: ~Z() noexcept(false) {}
+
+struct S {
+  void 

r304946 - [c++1z] Support deducing B in noexcept(B).

2017-06-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Jun  7 16:46:22 2017
New Revision: 304946

URL: http://llvm.org/viewvc/llvm-project?rev=304946&view=rev
Log:
[c++1z] Support deducing B in noexcept(B).

This is not required by the standard (yet), but there seems to be reasonable
support for this being a defect according to CWG discussion, and libstdc++ 7.1
relies on it working.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/CXX/drs/dr13xx.cpp
cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p4.cpp
cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp
cfe/trunk/test/SemaTemplate/temp_arg_type.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=304946&r1=304945&r2=304946&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jun  7 16:46:22 2017
@@ -7555,6 +7555,10 @@ public:
 unsigned ThisTypeQuals);
   void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto,
   const MultiLevelTemplateArgumentList &Args);
+  bool SubstExceptionSpec(SourceLocation Loc,
+  FunctionProtoType::ExceptionSpecInfo &ESI,
+  SmallVectorImpl &ExceptionStorage,
+  const MultiLevelTemplateArgumentList &Args);
   ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
 const MultiLevelTemplateArgumentList &TemplateArgs,
 int indexAdjustment,

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=304946&r1=304945&r2=304946&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jun  7 16:46:22 2017
@@ -56,8 +56,12 @@ namespace clang {
 TDF_TopLevelParameterTypeList = 0x10,
 /// \brief Within template argument deduction from overload resolution per
 /// C++ [over.over] allow matching function types that are compatible in
-/// terms of noreturn and default calling convention adjustments.
-TDF_InOverloadResolution = 0x20
+/// terms of noreturn and default calling convention adjustments, or
+/// similarly matching a declared template specialization against a
+/// possible template, per C++ [temp.deduct.decl]. In either case, permit
+/// deduction where the parameter is a function type that can be converted
+/// to the argument type.
+TDF_AllowCompatibleFunctionType = 0x20,
   };
 }
 
@@ -1306,9 +1310,10 @@ DeduceTemplateArgumentsByTypeMatch(Sema
 // If the parameter type is not dependent, there is nothing to deduce.
 if (!Param->isDependentType()) {
   if (!(TDF & TDF_SkipNonDependent)) {
-bool NonDeduced = (TDF & TDF_InOverloadResolution)?
-  !S.isSameOrCompatibleFunctionType(CanParam, CanArg) :
-  Param != Arg;
+bool NonDeduced =
+(TDF & TDF_AllowCompatibleFunctionType)
+? !S.isSameOrCompatibleFunctionType(CanParam, CanArg)
+: Param != Arg;
 if (NonDeduced) {
   return Sema::TDK_NonDeducedMismatch;
 }
@@ -1318,10 +1323,10 @@ DeduceTemplateArgumentsByTypeMatch(Sema
   } else if (!Param->isDependentType()) {
 CanQualType ParamUnqualType = CanParam.getUnqualifiedType(),
 ArgUnqualType = CanArg.getUnqualifiedType();
-bool Success = (TDF & TDF_InOverloadResolution)?
-   S.isSameOrCompatibleFunctionType(ParamUnqualType,
-ArgUnqualType) :
-   ParamUnqualType == ArgUnqualType;
+bool Success =
+(TDF & TDF_AllowCompatibleFunctionType)
+? S.isSameOrCompatibleFunctionType(ParamUnqualType, ArgUnqualType)
+: ParamUnqualType == ArgUnqualType;
 if (Success)
   return Sema::TDK_Success;
   }
@@ -1524,17 +1529,56 @@ DeduceTemplateArgumentsByTypeMatch(Sema
 return Sema::TDK_NonDeducedMismatch;
 
   // Check return types.
-  if (Sema::TemplateDeductionResult Result =
-  DeduceTemplateArgumentsByTypeMatch(
-  S, TemplateParams, FunctionProtoParam->getReturnType(),
-  FunctionProtoArg->getReturnType(), Info, Deduced, 0))
+  if (auto Result = DeduceTemplateArgumentsByTypeMatch(
+  S, TemplateParams, FunctionProtoParam->getReturnType(),
+  FunctionProtoArg->getReturnType(), Info, Deduced, 0))
 return Result;
 
-  return DeduceTemplateArguments(
-  S, Templ

[PATCH] D33094: [ASTMatchers] Add clang-query support for equals matcher

2017-06-07 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn added inline comments.



Comment at: unittests/ASTMatchers/Dynamic/RegistryTest.cpp:545
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("int x = 'x';", CharStmt));
+  EXPECT_FALSE(matches("int x = 120;", CharStmt));

Lekensteyn wrote:
> aaron.ballman wrote:
> > Can you add some tests involving the other character literal types (L, u, 
> > U, u8)?
> will do
Done (except for u8 which is only defined for string literals).


https://reviews.llvm.org/D33094



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


[PATCH] D33094: [ASTMatchers] Add clang-query support for equals matcher

2017-06-07 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn updated this revision to Diff 101817.
Lekensteyn marked 7 inline comments as done.
Lekensteyn added a comment.

diff from previous patch:

  diff --git a/unittests/ASTMatchers/Dynamic/RegistryTest.cpp 
b/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
  index 29fcdec6c1..84e31f721a 100644
  --- a/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
  +++ b/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
  @@ -530,6 +530,8 @@ TEST_F(RegistryTest, EqualsMatcher) {
 "floatLiteral", constructMatcher("equals", VariantValue(1.2)))
 .getTypedMatcher();
 EXPECT_TRUE(matches("double x = 1.2;", DoubleStmt));
  +  EXPECT_TRUE(matches("double x = 1.2f;", DoubleStmt));
  +  EXPECT_TRUE(matches("double x = 1.2l;", DoubleStmt));
 EXPECT_TRUE(matches("double x = 12e-1;", DoubleStmt));
 EXPECT_FALSE(matches("double x = 1.23;", DoubleStmt));
   
  @@ -543,6 +545,9 @@ TEST_F(RegistryTest, EqualsMatcher) {
 "characterLiteral", constructMatcher("equals", VariantValue('x')))
 .getTypedMatcher();
 EXPECT_TRUE(matches("int x = 'x';", CharStmt));
  +  EXPECT_TRUE(matches("int x = L'x';", CharStmt));
  +  EXPECT_TRUE(matches("int x = u'x';", CharStmt));
  +  EXPECT_TRUE(matches("int x = U'x';", CharStmt));
 EXPECT_FALSE(matches("int x = 120;", CharStmt));
   }


https://reviews.llvm.org/D33094

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/Dynamic/RegistryTest.cpp

Index: unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===
--- unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -511,6 +511,46 @@
   EXPECT_FALSE(matches("int i = 1;", Value));
 }
 
+TEST_F(RegistryTest, EqualsMatcher) {
+  Matcher BooleanStmt = constructMatcher(
+  "cxxBoolLiteral", constructMatcher("equals", VariantValue(true)))
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("bool x = true;", BooleanStmt));
+  EXPECT_FALSE(matches("bool x = false;", BooleanStmt));
+  EXPECT_FALSE(matches("bool x = 0;", BooleanStmt));
+
+  BooleanStmt = constructMatcher(
+  "cxxBoolLiteral", constructMatcher("equals", VariantValue(0)))
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("bool x = false;", BooleanStmt));
+  EXPECT_FALSE(matches("bool x = true;", BooleanStmt));
+  EXPECT_FALSE(matches("bool x = 0;", BooleanStmt));
+
+  Matcher DoubleStmt = constructMatcher(
+  "floatLiteral", constructMatcher("equals", VariantValue(1.2)))
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("double x = 1.2;", DoubleStmt));
+  EXPECT_TRUE(matches("double x = 1.2f;", DoubleStmt));
+  EXPECT_TRUE(matches("double x = 1.2l;", DoubleStmt));
+  EXPECT_TRUE(matches("double x = 12e-1;", DoubleStmt));
+  EXPECT_FALSE(matches("double x = 1.23;", DoubleStmt));
+
+  Matcher IntegerStmt = constructMatcher(
+  "integerLiteral", constructMatcher("equals", VariantValue(42)))
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("int x = 42;", IntegerStmt));
+  EXPECT_FALSE(matches("int x = 1;", IntegerStmt));
+
+  Matcher CharStmt = constructMatcher(
+  "characterLiteral", constructMatcher("equals", VariantValue('x')))
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("int x = 'x';", CharStmt));
+  EXPECT_TRUE(matches("int x = L'x';", CharStmt));
+  EXPECT_TRUE(matches("int x = u'x';", CharStmt));
+  EXPECT_TRUE(matches("int x = U'x';", CharStmt));
+  EXPECT_FALSE(matches("int x = 120;", CharStmt));
+}
+
 } // end anonymous namespace
 } // end namespace dynamic
 } // end namespace ast_matchers
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -56,20 +56,24 @@
   registerMatcher(#name, internal::makeMatcherAutoMarshall(\
  ::clang::ast_matchers::name, #name));
 
+#define REGISTER_MATCHER_OVERLOAD(name)\
+  registerMatcher(#name,   \
+  llvm::make_unique(name##Callbacks))
+
 #define SPECIFIC_MATCHER_OVERLOAD(name, Id)\
   static_cast<::clang::ast_matchers::name##_Type##Id>( \
   ::clang::ast_matchers::name)
 
+#define MATCHER_OVERLOAD_ENTRY(name, Id)   \
+internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, Id), \
+  #name)
+
 #define REGISTER_OVERLOADED_2(name)\
   do { \
-std::unique_ptr Callbacks[] = { \
-internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 0),  \
-  #name), 

[PATCH] D33135: [ASTMatchers] Add support for floatLiterals

2017-06-07 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn added a comment.

Rebased patches on latest clang master (trunk), there were no changes in 
ASTMatchers.
boolean literal patch was unchanged, this floating literal patch was updated to 
address comments.




Comment at: include/clang/ASTMatchers/Dynamic/VariantValue.h:335
 unsigned Unsigned;
+double Double;
 bool Boolean;

aaron.ballman wrote:
> Lekensteyn wrote:
> > aaron.ballman wrote:
> > > Lekensteyn wrote:
> > > > aaron.ballman wrote:
> > > > > This may or may not be a good idea, but do we want to put the values 
> > > > > into an APFloat rather than a double? My concern with double is that 
> > > > > (0) it may be subtly different if the user wants a 16- or 32-bit 
> > > > > float explicitly, (1) it won't be able to represent long double 
> > > > > values, or quad double.
> > > > > 
> > > > > I'm thinking this value could be passed directly from the C++ API as 
> > > > > an APFloat, float, or double, or provided using a StringRef for the 
> > > > > dynamic API.
> > > > (32-bit) double values are a superset of (16-bit) float values, that 
> > > > should be OK.
> > > > Long doubles are possible in the AST (e.g. for `0.1L`), but neither C11 
> > > > nor C++14 seem to define a quad double literal type (so that should be 
> > > > of a lesser concern).
> > > > 
> > > > Reasons why I chose for double instead of APFloat:
> > > > - `strtod` is readily available and does not abort the program. By 
> > > > contrast, `APFloat(StringRef)` trips on assertions if the input is 
> > > > invalid.
> > > > - I was not sure if the APFloat class can be used in an union.
> > > The downside to using `strtod()` is that invalid input is silently 
> > > accepted. However, assertions on invalid input is certainly not good 
> > > either. It might be worth modifying `APFloat::convertFromString()` to 
> > > accept invalid input and return an error.
> > > 
> > > I think instead of an `APFloat`, maybe using an `APValue` for both the 
> > > `Unsigned` and `Double` fields might work. At the very least, it should 
> > > give you implementation ideas.
> > > 
> > > There is a quad double literal suffix: `q`. It's only supported on some 
> > > architectures, however. There are also imaginary numbers (`i`) and half 
> > > (`h`).
> > The strtod conversion was based on parseDouble in 
> > lib/Support/CommandLine.cpp, so any conversion issues also exist there.
> > 
> > Same question, can APFloat/APValue be used in a union?
> > 
> > float (or quad-double suffixes) are explicitly not supported now in this 
> > matcher, maybe they can be added later but for now I decided to keep the 
> > grammar simple (that is, do not express double/float data types via the 
> > literal).
> > The strtod conversion was based on parseDouble in 
> > lib/Support/CommandLine.cpp, so any conversion issues also exist there.
> 
> Good to know.
> 
> > Same question, can APFloat/APValue be used in a union?
> 
> I believe so, but I've not tried it myself. Also, as I mentioned, `APValue` 
> demonstrates another implementation strategy in case you cannot use a union 
> directly.
> 
> > float (or quad-double suffixes) are explicitly not supported now in this 
> > matcher, maybe they can be added later but for now I decided to keep the 
> > grammar simple (that is, do not express double/float data types via the 
> > literal).
> 
> That's reasonable for an initial implementation.
I think I'll keep it like this for now and defer eventual conversion to APValue 
for a future patch that also makes uint64_t possible. Is that OK?


https://reviews.llvm.org/D33135



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


[PATCH] D33135: [ASTMatchers] Add support for floatLiterals

2017-06-07 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn updated this revision to Diff 101816.
Lekensteyn marked 8 inline comments as done.
Lekensteyn added a comment.

diff from previous version:

  diff --git a/include/clang/ASTMatchers/Dynamic/Parser.h 
b/include/clang/ASTMatchers/Dynamic/Parser.h
  index 0d0c2ba540..5ec4a9abf4 100644
  --- a/include/clang/ASTMatchers/Dynamic/Parser.h
  +++ b/include/clang/ASTMatchers/Dynamic/Parser.h
  @@ -22,7 +22,7 @@
   ///:=  |  |  | 

   ///  := "quoted string"
   ///:= true | false
  -/// := 1.0 | 2e-3 | 3.45e67
  +/// := [0-9]+.[0-9]* | [0-9]+.[0-9]*[eE][-+]?[0-9]+
   ///   := [0-9]+
   /// := 
   ///  := () |
  diff --git a/lib/ASTMatchers/Dynamic/Parser.cpp 
b/lib/ASTMatchers/Dynamic/Parser.cpp
  index 669e5ca44f..ff5c5fb657 100644
  --- a/lib/ASTMatchers/Dynamic/Parser.cpp
  +++ b/lib/ASTMatchers/Dynamic/Parser.cpp
  @@ -130,8 +130,8 @@ private:
   
   case '0': case '1': case '2': case '3': case '4':
   case '5': case '6': case '7': case '8': case '9':
  -  // Parse an unsigned literal.
  -  consumeUnsignedLiteral(&Result);
  +  // Parse an unsigned and float literal.
  +  consumeNumberLiteral(&Result);
 break;
   
   default:
  @@ -176,8 +176,8 @@ private:
   return Result;
 }
   
  -  /// \brief Consume an unsigned literal.
  -  void consumeUnsignedLiteral(TokenInfo *Result) {
  +  /// \brief Consume an unsigned and float literal.
  +  void consumeNumberLiteral(TokenInfo *Result) {
   bool isFloatingLiteral = false;
   unsigned Length = 1;
   if (Code.size() > 1) {
  @@ -205,8 +205,9 @@ private:
   
   if (isFloatingLiteral) {
 char *end;
  +  errno = 0;
 double doubleValue = strtod(Result->Text.str().c_str(), &end);
  -  if (*end == 0) {
  +  if (*end == 0 && errno == 0) {
   Result->Kind = TokenInfo::TK_Literal;
   Result->Value = doubleValue;
   return;


https://reviews.llvm.org/D33135

Files:
  include/clang/ASTMatchers/Dynamic/Diagnostics.h
  include/clang/ASTMatchers/Dynamic/Parser.h
  include/clang/ASTMatchers/Dynamic/VariantValue.h
  lib/ASTMatchers/Dynamic/Diagnostics.cpp
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Parser.cpp
  lib/ASTMatchers/Dynamic/VariantValue.cpp
  unittests/ASTMatchers/Dynamic/ParserTest.cpp
  unittests/ASTMatchers/Dynamic/VariantValueTest.cpp

Index: unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
===
--- unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
+++ unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
@@ -76,13 +76,15 @@
   EXPECT_EQ("A", Value.getString());
   EXPECT_TRUE(Value.hasValue());
   EXPECT_FALSE(Value.isBoolean());
+  EXPECT_FALSE(Value.isDouble());
   EXPECT_FALSE(Value.isUnsigned());
   EXPECT_FALSE(Value.isMatcher());
   EXPECT_EQ("String", Value.getTypeAsString());
 
   Value = VariantMatcher::SingleMatcher(recordDecl());
   EXPECT_TRUE(Value.hasValue());
   EXPECT_FALSE(Value.isBoolean());
+  EXPECT_FALSE(Value.isDouble());
   EXPECT_FALSE(Value.isUnsigned());
   EXPECT_FALSE(Value.isString());
   EXPECT_TRUE(Value.isMatcher());
@@ -98,17 +100,28 @@
   EXPECT_FALSE(Value.isMatcher());
   EXPECT_FALSE(Value.isString());
 
+  Value = 3.14;
+  EXPECT_TRUE(Value.isDouble());
+  EXPECT_EQ(3.14, Value.getDouble());
+  EXPECT_TRUE(Value.hasValue());
+  EXPECT_FALSE(Value.isBoolean());
+  EXPECT_FALSE(Value.isUnsigned());
+  EXPECT_FALSE(Value.isMatcher());
+  EXPECT_FALSE(Value.isString());
+
   Value = 17;
   EXPECT_TRUE(Value.isUnsigned());
   EXPECT_EQ(17U, Value.getUnsigned());
   EXPECT_FALSE(Value.isBoolean());
+  EXPECT_FALSE(Value.isDouble());
   EXPECT_TRUE(Value.hasValue());
   EXPECT_FALSE(Value.isMatcher());
   EXPECT_FALSE(Value.isString());
 
   Value = VariantValue();
   EXPECT_FALSE(Value.hasValue());
   EXPECT_FALSE(Value.isBoolean());
+  EXPECT_FALSE(Value.isDouble());
   EXPECT_FALSE(Value.isUnsigned());
   EXPECT_FALSE(Value.isString());
   EXPECT_FALSE(Value.isMatcher());
Index: unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -84,6 +84,21 @@
   EXPECT_EQ(false, Sema.Values[1].getBoolean());
 }
 
+TEST(ParserTest, ParseDouble) {
+  MockSema Sema;
+  Sema.parse("1.0");
+  Sema.parse("2.0f");
+  Sema.parse("34.56e-78");
+  Sema.parse("4.E+6");
+  Sema.parse("1");
+  EXPECT_EQ(5U, Sema.Values.size());
+  EXPECT_EQ(1.0, Sema.Values[0].getDouble());
+  EXPECT_EQ("1:1: Error parsing numeric literal: <2.0f>", Sema.Errors[1]);
+  EXPECT_EQ(34.56e-78, Sema.Values[2].getDouble());
+  EXPECT_EQ(4e+6, Sema.Values[3].getDouble());
+  EXPECT_FALSE(Sema.Values[4].isDouble());
+}
+
 TEST(ParserTest, ParseUnsigned) {
   MockSema Sema;
   Sema.parse("0");
@@ -95,8 +110,8 @@
   EXPECT_EQ(0U, Sema.Values[0].getUnsigned());

[PATCH] D33478: [libclang] When getting platform availabilities, merge multiple declarations if possible

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

This looks better, it's almost ready. A couple of small requests:




Comment at: tools/libclang/CIndex.cpp:7262
+LHS->getMessage() == RHS->getMessage() &&
+LHS->getReplacement() == RHS->getReplacement())
+  return true;

We should also have a test that verifies that we merge identical availabilities.



Comment at: tools/libclang/CIndex.cpp:7268
+(!LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()) ||
+(!LHS->getMessage().empty() && !RHS->getMessage().empty()))
+  return false;

I think that we don't really need the `(!LHS->getMessage().empty() && 
!RHS->getMessage().empty())` check here since message has to be either in a 
deprecated or obsoleted clause, so we should already handle that with previous 
checks.


https://reviews.llvm.org/D33478



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


[libcxx] r304942 - Fix compile error with Bionic's PTHREAD_MUTEX_INITIALIZER

2017-06-07 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jun  7 15:47:42 2017
New Revision: 304942

URL: http://llvm.org/viewvc/llvm-project?rev=304942&view=rev
Log:
Fix compile error with Bionic's PTHREAD_MUTEX_INITIALIZER

On Bionic PTHREAD_MUTEX_INITIALIZER contains the expression " & 
",
which causes ADL to perform name lookup for operator&. During this lookup Clang 
decides
that it requires the default member initializer for std::mutex while defining 
the DMI
for std::mutex::__m_.

If I'm not mistaken this is caused by the explicit noexcept declaration on the 
defaulted
constructor.

This patch removes the explicit noexcept and instead allows the compiler to 
declare
the default constructor implicitly noexcept. It also adds a static_assert to 
ensure
that happens.

Unfortunatly because it's not easy to change the value of 
_LIBCPP_MUTEX_INITIALIZER
for a single test there is no good way to test this patch.

The Clang behavior causing the trouble here was introduced in r287713, which 
first
appears in the 4.0 release.

Modified:
libcxx/trunk/include/__mutex_base

libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp

Modified: libcxx/trunk/include/__mutex_base
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__mutex_base?rev=304942&r1=304941&r2=304942&view=diff
==
--- libcxx/trunk/include/__mutex_base (original)
+++ libcxx/trunk/include/__mutex_base Wed Jun  7 15:47:42 2017
@@ -48,7 +48,7 @@ class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SA
 public:
 _LIBCPP_INLINE_VISIBILITY
 #ifndef _LIBCPP_CXX03_LANG
-constexpr mutex() _NOEXCEPT = default;
+constexpr mutex() = default;
 #else
 mutex() _NOEXCEPT {__m_ = (__libcpp_mutex_t)_LIBCPP_MUTEX_INITIALIZER;}
 #endif
@@ -67,6 +67,9 @@ public:
 _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return 
&__m_;}
 };
 
+static_assert(is_nothrow_default_constructible::value,
+  "the default constructor for std::mutex must be nothrow");
+
 struct _LIBCPP_TYPE_VIS defer_lock_t {};
 struct _LIBCPP_TYPE_VIS try_to_lock_t {};
 struct _LIBCPP_TYPE_VIS adopt_lock_t {};

Modified: 
libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp?rev=304942&r1=304941&r2=304942&view=diff
==
--- 
libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp
 Wed Jun  7 15:47:42 2017
@@ -16,8 +16,10 @@
 // mutex();
 
 #include 
+#include 
 
 int main()
 {
+static_assert(std::is_nothrow_default_constructible::value, 
"");
 std::mutex m;
 }


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


[PATCH] D33681: Allow function declaration with empty argument list.

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

LGTM! Thanks!


https://reviews.llvm.org/D33681



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


[PATCH] D33598: [libclang] [OpenCL] Expose CIndex functions for typedef and address space

2017-06-07 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Sam, do you think you have some time to look at this change? Thanks!


https://reviews.llvm.org/D33598



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


RE: r304935 - Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt

2017-06-07 Thread Simon Dardis via cfe-commits
Appears to be fixed, r304936. I'll keep an eye on the buildbots.

Thanks,
Simon

From: cfe-commits [cfe-commits-boun...@lists.llvm.org] on behalf of Evgenii 
Stepanov via cfe-commits [cfe-commits@lists.llvm.org]
Sent: 07 June 2017 20:53
To: Petar Jovanovic
Cc: cfe-commits
Subject: Re: r304935 - Revert r304929 [mips] Add runtime options to 
enable/disable madd/sub.fmt

You've left an empty file in test/CodeGen/mips-madd4.c

On Wed, Jun 7, 2017 at 11:57 AM, Petar Jovanovic via cfe-commits
 wrote:
> Author: petarj
> Date: Wed Jun  7 13:57:56 2017
> New Revision: 304935
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304935&view=rev
> Log:
> Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt
>
> Revert r304929 since the test broke buildbots.
>
> Original commit:
>
>   [mips] Add runtime options to enable/disable madd.fmt and msub.fmt
>
>   Add options to clang: -mmadd4 and -mno-madd4, use it to enable or disable
>   generation of madd.fmt and similar instructions respectively, as per GCC.
>
>   Patch by Stefan Maksimovic.
>
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
> cfe/trunk/test/CodeGen/mips-madd4.c
> cfe/trunk/test/Preprocessor/init.c
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Wed Jun  7 13:57:56 2017
> @@ -2001,10 +2001,6 @@ def mdspr2 : Flag<["-"], "mdspr2">, Grou
>  def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group;
>  def msingle_float : Flag<["-"], "msingle-float">, Group;
>  def mdouble_float : Flag<["-"], "mdouble-float">, Group;
> -def mmadd4 : Flag<["-"], "mmadd4">, Group,
> -  HelpText<"Enable the generation of 4-operand madd.s, madd.d and related 
> instructions.">;
> -def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
> -  HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
> instructions.">;
>  def mmsa : Flag<["-"], "mmsa">, Group,
>HelpText<"Enable MSA ASE (MIPS only)">;
>  def mno_msa : Flag<["-"], "mno-msa">, Group,
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun  7 13:57:56 2017
> @@ -7737,7 +7737,6 @@ class MipsTargetInfo : public TargetInfo
>  NoDSP, DSP1, DSP2
>} DspRev;
>bool HasMSA;
> -  bool DisableMadd4;
>
>  protected:
>bool HasFP64;
> @@ -7748,7 +7747,7 @@ public:
>: TargetInfo(Triple), IsMips16(false), IsMicromips(false),
>  IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
>  CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
> -HasMSA(false), DisableMadd4(false), HasFP64(false) {
> +HasMSA(false), HasFP64(false) {
>  TheCXXABI.set(TargetCXXABI::GenericMIPS);
>
>  setABI((getTriple().getArch() == llvm::Triple::mips ||
> @@ -7994,9 +7993,6 @@ public:
>  if (HasMSA)
>Builder.defineMacro("__mips_msa", Twine(1));
>
> -if (DisableMadd4)
> -  Builder.defineMacro("__mips_no_madd4", Twine(1));
> -
>  Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
>  Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
>  Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
> @@ -8159,8 +8155,6 @@ public:
>  DspRev = std::max(DspRev, DSP2);
>else if (Feature == "+msa")
>  HasMSA = true;
> -  else if (Feature == "+nomadd4")
> -DisableMadd4 = true;
>else if (Feature == "+fp64")
>  HasFP64 = true;
>else if (Feature == "-fp64")
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jun  7 13:57:56 2017
> @@ -298,13 +298,6 @@ void mips::getMIPSTargetFeatures(const D
>
>AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
> options::OPT_modd_spreg, "nooddspreg");
> -
> -  if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) 
> {
> -if (A->getOption().matches(options::OPT_mmadd4))
> -  Features.push_back("-nomadd4");
> -else
> -  Features.push_back("+nomadd4");
> -  }
>  }
>
>  mips::NanEncoding mips

[PATCH] D33493: Speed up preamble loading

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



Comment at: lib/Frontend/ASTUnit.cpp:1152
+  else
+SrcLocCache.clear();
 

yvvan wrote:
> arphaman wrote:
> > Why is `clear` in an `else` here? We always create a new `SourceManager` in 
> > this function, so the previously cached locations will be invalid, so 
> > shouldn't we always clear the cache before `TranslateStoredDiagnostics`?
> When we load diagnostics that means that preamble has not changed. Doesn't 
> that mean that source locations can be reused? What can cause them to become 
> invalid?
> When preamble is invalidated - cache is cleared.
> 
> I can keep cache only during TranslateStoredDiagnostics calls but in that 
> case performance improvement is way less.
> 
> But if you say that current solution is invalid I will do that
You're right actually, we can reuse them. We already do make that assumption 
that the preamble's source locations can be reused in `checkAndSanitizeDiags`. 
This code is fine then, sorry about the confusion.

You should mention in the comment for the `SrcLocCache` that we cache only the 
source locations from the preamble as we can guarantee that they will stay 
valid when the source manager is re-created.



https://reviews.llvm.org/D33493



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


[PATCH] D34007: Implement inclusive_scan and transform_inclusive_scan

2017-06-07 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

Re-reading this, I may have implemented `exclusive_scan` instead of 
`inclusive_scan` here.


https://reviews.llvm.org/D34007



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


r304936 - Finish revert of "r304929, [mips] Add runtime options to enable/disable madd/sub.fmt"

2017-06-07 Thread Simon Dardis via cfe-commits
Author: sdardis
Date: Wed Jun  7 15:02:24 2017
New Revision: 304936

URL: http://llvm.org/viewvc/llvm-project?rev=304936&view=rev
Log:
Finish revert of "r304929, [mips] Add runtime options to enable/disable 
madd/sub.fmt"

The r304935 missed deleting the test case.


Removed:
cfe/trunk/test/CodeGen/mips-madd4.c

Removed: cfe/trunk/test/CodeGen/mips-madd4.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips-madd4.c?rev=304935&view=auto
==
(empty)


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


[PATCH] D33944: git-clang-format: Add --cached option to format index

2017-06-07 Thread Kevin Locke via Phabricator via cfe-commits
kevinoid updated this revision to Diff 101799.
kevinoid added a comment.

Fixed handling of case when no formatting changes are made but `old_tree != 
new_tree` in `apply_changes`.


https://reviews.llvm.org/D33944

Files:
  tools/clang-format/git-clang-format

Index: tools/clang-format/git-clang-format
===
--- tools/clang-format/git-clang-format
+++ tools/clang-format/git-clang-format
@@ -92,6 +92,8 @@
   p.add_argument('--binary',
  default=config.get('clangformat.binary', 'clang-format'),
  help='path to clang-format'),
+  p.add_argument('--cached', action='store_true',
+ help='format index instead of working directory'),
   p.add_argument('--commit',
  default=config.get('clangformat.commit', 'HEAD'),
  help='default commit to use if none is specified'),
@@ -129,10 +131,12 @@
   if len(commits) > 1:
 if not opts.diff:
   die('--diff is required when two commits are given')
+if opts.cached:
+  die('--cached is not applicable when two commits are given')
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
-  changed_lines = compute_diff_and_extract_lines(commits, files)
+  changed_lines = compute_diff_and_extract_lines(commits, files, opts.cached)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)
   filter_by_extension(changed_lines, opts.extensions.lower().split(','))
@@ -154,15 +158,17 @@
   cd_to_toplevel()
   if len(commits) > 1:
 old_tree = commits[1]
-new_tree = run_clang_format_and_save_to_tree(changed_lines,
- revision=commits[1],
- binary=opts.binary,
- style=opts.style)
+fmt_tree = commits[1]
+  elif opts.cached:
+old_tree = run('git', 'write-tree')
+fmt_tree = old_tree
   else:
 old_tree = create_tree_from_workdir(changed_lines)
-new_tree = run_clang_format_and_save_to_tree(changed_lines,
- binary=opts.binary,
- style=opts.style)
+fmt_tree = None
+  new_tree = run_clang_format_and_save_to_tree(changed_lines,
+   revision=fmt_tree,
+   binary=opts.binary,
+   style=opts.style)
   if opts.verbose >= 1:
 print('old tree: %s' % old_tree)
 print('new tree: %s' % new_tree)
@@ -173,7 +179,7 @@
 print_diff(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
-  patch_mode=opts.patch)
+  patch_mode=opts.patch, cached=opts.cached)
 if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
   print('changed files:')
   for filename in changed_files:
@@ -261,9 +267,9 @@
   return convert_string(stdout.strip())
 
 
-def compute_diff_and_extract_lines(commits, files):
+def compute_diff_and_extract_lines(commits, files, cached=False):
   """Calls compute_diff() followed by extract_lines()."""
-  diff_process = compute_diff(commits, files)
+  diff_process = compute_diff(commits, files, cached)
   changed_lines = extract_lines(diff_process.stdout)
   diff_process.stdout.close()
   diff_process.wait()
@@ -273,7 +279,7 @@
   return changed_lines
 
 
-def compute_diff(commits, files):
+def compute_diff(commits, files, cached=False):
   """Return a subprocess object producing the diff from `commits`.
 
   The return value's `stdin` file object will produce a patch with the
@@ -283,7 +289,11 @@
   git_tool = 'diff-index'
   if len(commits) > 1:
 git_tool = 'diff-tree'
-  cmd = ['git', git_tool, '-p', '-U0'] + commits + ['--']
+  cmd = ['git', git_tool, '-p', '-U0']
+  if cached:
+cmd.append('--cached')
+  cmd.extend(commits)
+  cmd.append('--')
   cmd.extend(files)
   p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
   p.stdin.close()
@@ -487,23 +497,43 @@
  '--'])
 
 
-def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
-  """Apply the changes in `new_tree` to the working directory.
+def apply_changes(old_tree, new_tree, force=False, patch_mode=False,
+  cached=False):
+  """Apply the changes in `new_tree` to the working directory or index.
 
   Bails if there are local changes in those files and not `force`.  If
-  `patch_mode`, runs `git checkout --patch` to select hunks interactively."""
+  `patch_mode`, adds `--patch` option to select hunks interactively."""
   changed_files = run('git', 'diff-tree', '--diff-filter=M', '-r', '-z',
   '--name-only', old_tree,
   new_tree).rstrip('\0').split('\0')
+  if changed_files == ['']:
+

[PATCH] D34010: clang-format: Add --cached option to format index

2017-06-07 Thread Kevin Locke via Phabricator via cfe-commits
kevinoid abandoned this revision.
kevinoid added a comment.

Meant to update diff for https://reviews.llvm.org/D33944.  My mistake.  Closing.


https://reviews.llvm.org/D34010



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


[PATCH] D34010: clang-format: Add --cached option to format index

2017-06-07 Thread Kevin Locke via Phabricator via cfe-commits
kevinoid created this revision.

Add --cached option to git-clang-format which behaves analogously to the
use of --cached for other git subcommands, by causing the operation to
work against the index state rather than the working directory state.

This can be particularly useful for hook scripts which need to check or
change the formatting of the index state before commit.

Patch by Kevin Locke.


https://reviews.llvm.org/D34010

Files:
  tools/clang-format/git-clang-format

Index: tools/clang-format/git-clang-format
===
--- tools/clang-format/git-clang-format
+++ tools/clang-format/git-clang-format
@@ -92,6 +92,8 @@
   p.add_argument('--binary',
  default=config.get('clangformat.binary', 'clang-format'),
  help='path to clang-format'),
+  p.add_argument('--cached', action='store_true',
+ help='format index instead of working directory'),
   p.add_argument('--commit',
  default=config.get('clangformat.commit', 'HEAD'),
  help='default commit to use if none is specified'),
@@ -129,10 +131,12 @@
   if len(commits) > 1:
 if not opts.diff:
   die('--diff is required when two commits are given')
+if opts.cached:
+  die('--cached is not applicable when two commits are given')
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
-  changed_lines = compute_diff_and_extract_lines(commits, files)
+  changed_lines = compute_diff_and_extract_lines(commits, files, opts.cached)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)
   filter_by_extension(changed_lines, opts.extensions.lower().split(','))
@@ -154,15 +158,17 @@
   cd_to_toplevel()
   if len(commits) > 1:
 old_tree = commits[1]
-new_tree = run_clang_format_and_save_to_tree(changed_lines,
- revision=commits[1],
- binary=opts.binary,
- style=opts.style)
+fmt_tree = commits[1]
+  elif opts.cached:
+old_tree = run('git', 'write-tree')
+fmt_tree = old_tree
   else:
 old_tree = create_tree_from_workdir(changed_lines)
-new_tree = run_clang_format_and_save_to_tree(changed_lines,
- binary=opts.binary,
- style=opts.style)
+fmt_tree = None
+  new_tree = run_clang_format_and_save_to_tree(changed_lines,
+   revision=fmt_tree,
+   binary=opts.binary,
+   style=opts.style)
   if opts.verbose >= 1:
 print('old tree: %s' % old_tree)
 print('new tree: %s' % new_tree)
@@ -173,7 +179,7 @@
 print_diff(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
-  patch_mode=opts.patch)
+  patch_mode=opts.patch, cached=opts.cached)
 if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
   print('changed files:')
   for filename in changed_files:
@@ -261,9 +267,9 @@
   return convert_string(stdout.strip())
 
 
-def compute_diff_and_extract_lines(commits, files):
+def compute_diff_and_extract_lines(commits, files, cached=False):
   """Calls compute_diff() followed by extract_lines()."""
-  diff_process = compute_diff(commits, files)
+  diff_process = compute_diff(commits, files, cached)
   changed_lines = extract_lines(diff_process.stdout)
   diff_process.stdout.close()
   diff_process.wait()
@@ -273,7 +279,7 @@
   return changed_lines
 
 
-def compute_diff(commits, files):
+def compute_diff(commits, files, cached=False):
   """Return a subprocess object producing the diff from `commits`.
 
   The return value's `stdin` file object will produce a patch with the
@@ -283,7 +289,11 @@
   git_tool = 'diff-index'
   if len(commits) > 1:
 git_tool = 'diff-tree'
-  cmd = ['git', git_tool, '-p', '-U0'] + commits + ['--']
+  cmd = ['git', git_tool, '-p', '-U0']
+  if cached:
+cmd.append('--cached')
+  cmd.extend(commits)
+  cmd.append('--')
   cmd.extend(files)
   p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
   p.stdin.close()
@@ -487,23 +497,43 @@
  '--'])
 
 
-def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
-  """Apply the changes in `new_tree` to the working directory.
+def apply_changes(old_tree, new_tree, force=False, patch_mode=False,
+  cached=False):
+  """Apply the changes in `new_tree` to the working directory or index.
 
   Bails if there are local changes in those files and not `force`.  If
-  `patch_mode`, runs `git checkout --patch` to select hunks interactively."""
+  `patch_mode`, adds `--patch` option to select hunks interactiv

Re: r304935 - Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt

2017-06-07 Thread Evgenii Stepanov via cfe-commits
You've left an empty file in test/CodeGen/mips-madd4.c

On Wed, Jun 7, 2017 at 11:57 AM, Petar Jovanovic via cfe-commits
 wrote:
> Author: petarj
> Date: Wed Jun  7 13:57:56 2017
> New Revision: 304935
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304935&view=rev
> Log:
> Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt
>
> Revert r304929 since the test broke buildbots.
>
> Original commit:
>
>   [mips] Add runtime options to enable/disable madd.fmt and msub.fmt
>
>   Add options to clang: -mmadd4 and -mno-madd4, use it to enable or disable
>   generation of madd.fmt and similar instructions respectively, as per GCC.
>
>   Patch by Stefan Maksimovic.
>
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
> cfe/trunk/test/CodeGen/mips-madd4.c
> cfe/trunk/test/Preprocessor/init.c
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Wed Jun  7 13:57:56 2017
> @@ -2001,10 +2001,6 @@ def mdspr2 : Flag<["-"], "mdspr2">, Grou
>  def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group;
>  def msingle_float : Flag<["-"], "msingle-float">, Group;
>  def mdouble_float : Flag<["-"], "mdouble-float">, Group;
> -def mmadd4 : Flag<["-"], "mmadd4">, Group,
> -  HelpText<"Enable the generation of 4-operand madd.s, madd.d and related 
> instructions.">;
> -def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
> -  HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
> instructions.">;
>  def mmsa : Flag<["-"], "mmsa">, Group,
>HelpText<"Enable MSA ASE (MIPS only)">;
>  def mno_msa : Flag<["-"], "mno-msa">, Group,
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun  7 13:57:56 2017
> @@ -7737,7 +7737,6 @@ class MipsTargetInfo : public TargetInfo
>  NoDSP, DSP1, DSP2
>} DspRev;
>bool HasMSA;
> -  bool DisableMadd4;
>
>  protected:
>bool HasFP64;
> @@ -7748,7 +7747,7 @@ public:
>: TargetInfo(Triple), IsMips16(false), IsMicromips(false),
>  IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
>  CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
> -HasMSA(false), DisableMadd4(false), HasFP64(false) {
> +HasMSA(false), HasFP64(false) {
>  TheCXXABI.set(TargetCXXABI::GenericMIPS);
>
>  setABI((getTriple().getArch() == llvm::Triple::mips ||
> @@ -7994,9 +7993,6 @@ public:
>  if (HasMSA)
>Builder.defineMacro("__mips_msa", Twine(1));
>
> -if (DisableMadd4)
> -  Builder.defineMacro("__mips_no_madd4", Twine(1));
> -
>  Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
>  Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
>  Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
> @@ -8159,8 +8155,6 @@ public:
>  DspRev = std::max(DspRev, DSP2);
>else if (Feature == "+msa")
>  HasMSA = true;
> -  else if (Feature == "+nomadd4")
> -DisableMadd4 = true;
>else if (Feature == "+fp64")
>  HasFP64 = true;
>else if (Feature == "-fp64")
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jun  7 13:57:56 2017
> @@ -298,13 +298,6 @@ void mips::getMIPSTargetFeatures(const D
>
>AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
> options::OPT_modd_spreg, "nooddspreg");
> -
> -  if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) 
> {
> -if (A->getOption().matches(options::OPT_mmadd4))
> -  Features.push_back("-nomadd4");
> -else
> -  Features.push_back("+nomadd4");
> -  }
>  }
>
>  mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) {
>
> Modified: cfe/trunk/test/CodeGen/mips-madd4.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips-madd4.c?rev=304935&r1=304934&r2=304935&view=diff
> ==
> --- cfe/trunk/test/CodeGen/mips-madd4.c (original)
> +++ cfe/trunk/test/CodeGen/mips-madd4.c Wed Jun  7 13:57:5

[PATCH] D33841: [clang-tidy] redundant keyword check

2017-06-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.



Comment at: docs/clang-tidy/checks/readability-redundant-keyword.rst:8
+
+`extern` is redundant in function declarations
+

Could you explain, why you think `extern` is redundant in function declarations?


Repository:
  rL LLVM

https://reviews.llvm.org/D33841



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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D20693#775197, @hintonda wrote:

> I have not, as yet, been able to reproduce the buildbot failures.  They were 
> essentially intermittent seg-faults, and corrupt diag output.
>
> I will work on creating a test that can reproduce the problem.


As I said, we could re-submit the patch (without speculative fixes) and see 
whether the buildbots break again. One more suggestion is to run the tests with 
asan. Have you tried this?


https://reviews.llvm.org/D20693



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


[PATCH] D34007: Implement inclusive_scan and transform_inclusive_scan

2017-06-07 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.

Like https://reviews.llvm.org/D33997, this implements the non-parallel versions 
of these algorithms

https://reviews.llvm.org/D33997 implemented `reduce` and `transform_reduce`, 
this adds `inclusive_scan` and `transform_inclusive_scan`.

There will be another patch that adds `exclusive_scan` and 
`transform_exclusive_scan`


https://reviews.llvm.org/D34007

Files:
  include/numeric
  
test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_iter_iter_iter.pass.cpp
  
test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_iter_iter_iter_op.pass.cpp
  
test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_iter_iter_iter_op_init.pass.cpp
  
test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_iter_iter_iter_bop_uop.pass.cpp
  
test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_iter_iter_iter_bop_uop_init.pass.cpp

Index: test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_iter_iter_iter_bop_uop_init.pass.cpp
===
--- test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_iter_iter_iter_bop_uop_init.pass.cpp
+++ test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_iter_iter_iter_bop_uop_init.pass.cpp
@@ -0,0 +1,101 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+// UNSUPPORTED: c++98, c++03, c++11, C++14
+
+// template
+//   OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
+//   OutputIterator result,
+//   BinaryOperation binary_op,
+//   UnaryOperation unary_op, T init);
+
+
+#include 
+#include 
+#include 
+// #include 
+
+#include "test_iterators.h"
+
+template 
+struct identity : std::unary_function<_Tp, _Tp>
+{
+constexpr const _Tp& operator()(const _Tp& __x) const { return __x;}
+};
+
+template <>
+struct identity
+{
+template 
+constexpr auto operator()(_Tp&& __x) const
+_NOEXCEPT_(noexcept(_VSTD::forward<_Tp>(__x)))
+-> decltype(_VSTD::forward<_Tp>(__x))
+{ return_VSTD::forward<_Tp>(__x); }
+};
+
+template 
+void
+test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, Iter2 rFirst, Iter2 rLast)
+{
+	std::vector::value_type> v;
+	std::transform_inclusive_scan(first, last, std::back_inserter(v), bop, uop, init);
+// 	std::cout << v.size() << " vs " << std::distance(rFirst, rLast) << std::endl;
+// 	std::copy(v.begin(), v.end(), std::ostream_iterator(std::cout, " "));
+// 	std::cout << std::endl;
+	assert(std::equal(v.begin(), v.end(), rFirst, rLast));
+}
+
+
+template 
+void
+test()
+{
+  int ia[] = { 1,  3,   5,   7, 9};
+const int pResI0[] = { 0,  1,  4,   9,  16,25};		// with identity
+const int mResI0[] = { 0,  0,  0,   0,   0, 0};		
+const int pResN0[] = { 0, -1, -4,  -9, -16,   -25};		// with negate
+const int mResN0[] = { 0,  0,  0,   0,   0, 0};
+const int pResI2[] = { 2,  3,  6,  11,  18,27};		// with identity
+const int mResI2[] = { 2,  2,  6,  30, 210,  1890};		
+const int pResN2[] = { 2,  1, -2,  -7, -14,   -23};		// with negate
+const int mResN2[] = { 2, -2,  6, -30, 210, -1890};
+unsigned sa = sizeof(ia) / sizeof(ia[0]);
+assert(sa + 1 == sizeof(pResI0) / sizeof(pResI0[0]));   // just to be sure
+assert(sa + 1 == sizeof(mResI0) / sizeof(mResI0[0]));   // just to be sure
+assert(sa + 1 == sizeof(pResN0) / sizeof(pResN0[0]));   // just to be sure
+assert(sa + 1 == sizeof(mResN0) / sizeof(mResN0[0]));   // just to be sure
+assert(sa + 1 == sizeof(pResI2) / sizeof(pResI2[0]));   // just to be sure
+assert(sa + 1 == sizeof(mResI2) / sizeof(mResI2[0]));   // just to be sure
+assert(sa + 1 == sizeof(pResN2) / sizeof(pResN2[0]));   // just to be sure
+assert(sa + 1 == sizeof(mResN2) / sizeof(mResN2[0]));   // just to be sure
+
+	for (unsigned int i = 0; i < sa; ++i ) {
+	test(Iter(ia), Iter(ia + i), std::plus<>(),   identity<>(),0, pResI0, pResI0 + i + 1);
+	test(Iter(ia), Iter(ia + i), std::multiplies<>(), identity<>(),0, mResI0, mResI0 + i + 1);
+	test(Iter(ia), Iter(ia + i), std::plus<>(),   std::negate<>(), 0, pResN0, pResN0 + i + 1);
+	test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 0, mResN0, mResN0 + i + 1);
+	test(Iter(ia), Iter(ia + i), std::plus<>(),   identity<>(),2, pResI2, pResI2 + i + 1);
+	test(Iter(ia), Iter(ia + i), std::

[PATCH] D33478: [libclang] When getting platform availabilities, merge multiple declarations if possible

2017-06-07 Thread Ronald Wampler via Phabricator via cfe-commits
rdwampler updated this revision to Diff 101787.
rdwampler marked 6 inline comments as done.
rdwampler added a comment.

This should resolve the bug (a conditional was inverted) in the last revision 
along with the other changes requested.


https://reviews.llvm.org/D33478

Files:
  test/Index/availability.c
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7200,15 +7200,11 @@
   return Out;
 }
 
-static int getCursorPlatformAvailabilityForDecl(const Decl *D,
-int *always_deprecated,
-CXString *deprecated_message,
-int *always_unavailable,
-CXString *unavailable_message,
-   CXPlatformAvailability *availability,
-int availability_size) {
+static void getCursorPlatformAvailabilityForDecl(
+const Decl *D, int *always_deprecated, CXString *deprecated_message,
+int *always_unavailable, CXString *unavailable_message,
+SmallVectorImpl &AvailabilityAttrs) {
   bool HadAvailAttr = false;
-  int N = 0;
   for (auto A : D->attrs()) {
 if (DeprecatedAttr *Deprecated = dyn_cast(A)) {
   HadAvailAttr = true;
@@ -7220,7 +7216,7 @@
   }
   continue;
 }
-
+
 if (UnavailableAttr *Unavailable = dyn_cast(A)) {
   HadAvailAttr = true;
   if (always_unavailable)
@@ -7231,38 +7227,72 @@
   }
   continue;
 }
-
+
 if (AvailabilityAttr *Avail = dyn_cast(A)) {
+  AvailabilityAttrs.push_back(Avail);
   HadAvailAttr = true;
-  if (N < availability_size) {
-availability[N].Platform
-  = cxstring::createDup(Avail->getPlatform()->getName());
-availability[N].Introduced = convertVersion(Avail->getIntroduced());
-availability[N].Deprecated = convertVersion(Avail->getDeprecated());
-availability[N].Obsoleted = convertVersion(Avail->getObsoleted());
-availability[N].Unavailable = Avail->getUnavailable();
-availability[N].Message = cxstring::createDup(Avail->getMessage());
-  }
-  ++N;
 }
   }
 
   if (!HadAvailAttr)
 if (const EnumConstantDecl *EnumConst = dyn_cast(D))
   return getCursorPlatformAvailabilityForDecl(
-cast(EnumConst->getDeclContext()),
-  always_deprecated,
-  deprecated_message,
-  always_unavailable,
-  unavailable_message,
-  availability,
-  availability_size);
-  
-  return N;
+  cast(EnumConst->getDeclContext()), always_deprecated,
+  deprecated_message, always_unavailable, unavailable_message,
+  AvailabilityAttrs);
+
+  if (AvailabilityAttrs.empty())
+return;
+
+  std::sort(AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
+[](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
+  return LHS->getPlatform() > RHS->getPlatform();
+});
+  ASTContext &Ctx = D->getASTContext();
+  auto It = std::unique(
+  AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
+  [&Ctx](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
+if (LHS->getPlatform() != RHS->getPlatform())
+  return false;
+
+if (LHS->getIntroduced() == RHS->getIntroduced() &&
+LHS->getDeprecated() == RHS->getDeprecated() &&
+LHS->getObsoleted() == RHS->getObsoleted() &&
+LHS->getMessage() == RHS->getMessage() &&
+LHS->getReplacement() == RHS->getReplacement())
+  return true;
+
+if ((!LHS->getIntroduced().empty() && !RHS->getIntroduced().empty()) ||
+(!LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) ||
+(!LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()) ||
+(!LHS->getMessage().empty() && !RHS->getMessage().empty()))
+  return false;
+
+if (LHS->getIntroduced().empty() && !RHS->getIntroduced().empty())
+  LHS->setIntroduced(Ctx, RHS->getIntroduced());
+
+if (LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) {
+  LHS->setDeprecated(Ctx, RHS->getDeprecated());
+  if (LHS->getMessage().empty())
+LHS->setMessage(Ctx, RHS->getMessage());
+  if (LHS->getReplacement().empty())
+LHS->setReplacement(Ctx, RHS->getReplacement());
+}
+
+if (LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()) {
+  LHS->setObsoleted(Ctx, RHS->getObsoleted());
+

r304935 - Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt

2017-06-07 Thread Petar Jovanovic via cfe-commits
Author: petarj
Date: Wed Jun  7 13:57:56 2017
New Revision: 304935

URL: http://llvm.org/viewvc/llvm-project?rev=304935&view=rev
Log:
Revert r304929 [mips] Add runtime options to enable/disable madd/sub.fmt

Revert r304929 since the test broke buildbots.

Original commit:

  [mips] Add runtime options to enable/disable madd.fmt and msub.fmt

  Add options to clang: -mmadd4 and -mno-madd4, use it to enable or disable
  generation of madd.fmt and similar instructions respectively, as per GCC.

  Patch by Stefan Maksimovic.

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
cfe/trunk/test/CodeGen/mips-madd4.c
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=304935&r1=304934&r2=304935&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jun  7 13:57:56 2017
@@ -2001,10 +2001,6 @@ def mdspr2 : Flag<["-"], "mdspr2">, Grou
 def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group;
 def msingle_float : Flag<["-"], "msingle-float">, Group;
 def mdouble_float : Flag<["-"], "mdouble-float">, Group;
-def mmadd4 : Flag<["-"], "mmadd4">, Group,
-  HelpText<"Enable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
-def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
-  HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
   HelpText<"Enable MSA ASE (MIPS only)">;
 def mno_msa : Flag<["-"], "mno-msa">, Group,

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304935&r1=304934&r2=304935&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun  7 13:57:56 2017
@@ -7737,7 +7737,6 @@ class MipsTargetInfo : public TargetInfo
 NoDSP, DSP1, DSP2
   } DspRev;
   bool HasMSA;
-  bool DisableMadd4;
 
 protected:
   bool HasFP64;
@@ -7748,7 +7747,7 @@ public:
   : TargetInfo(Triple), IsMips16(false), IsMicromips(false),
 IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
 CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
-HasMSA(false), DisableMadd4(false), HasFP64(false) {
+HasMSA(false), HasFP64(false) {
 TheCXXABI.set(TargetCXXABI::GenericMIPS);
 
 setABI((getTriple().getArch() == llvm::Triple::mips ||
@@ -7994,9 +7993,6 @@ public:
 if (HasMSA)
   Builder.defineMacro("__mips_msa", Twine(1));
 
-if (DisableMadd4)
-  Builder.defineMacro("__mips_no_madd4", Twine(1));
-
 Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
 Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
 Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
@@ -8159,8 +8155,6 @@ public:
 DspRev = std::max(DspRev, DSP2);
   else if (Feature == "+msa")
 HasMSA = true;
-  else if (Feature == "+nomadd4")
-DisableMadd4 = true;
   else if (Feature == "+fp64")
 HasFP64 = true;
   else if (Feature == "-fp64")

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=304935&r1=304934&r2=304935&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jun  7 13:57:56 2017
@@ -298,13 +298,6 @@ void mips::getMIPSTargetFeatures(const D
 
   AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
options::OPT_modd_spreg, "nooddspreg");
-
-  if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) {
-if (A->getOption().matches(options::OPT_mmadd4))
-  Features.push_back("-nomadd4");
-else
-  Features.push_back("+nomadd4");
-  }
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) {

Modified: cfe/trunk/test/CodeGen/mips-madd4.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips-madd4.c?rev=304935&r1=304934&r2=304935&view=diff
==
--- cfe/trunk/test/CodeGen/mips-madd4.c (original)
+++ cfe/trunk/test/CodeGen/mips-madd4.c Wed Jun  7 13:57:56 2017
@@ -1,86 +0,0 @@
-// RUN: %clang --target=mips64-unknown-linux -S -mmadd4%s -o -| FileCheck 
%s -check-prefix=MADD4
-// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 %s -o -| FileCheck 
%s -check-prefix=NOMADD4
-// RUN: %clang --target=mips64-unknown-linux -S -mmadd4-fno-honor-nans %s 
-o -| FileCheck %s -check-prefi

[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

2017-06-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from one minor nit, LGTM




Comment at: clang-tidy/misc/NoexceptMoveConstructorCheck.cpp:23
   // provide any benefit to other languages, despite being benign.
-  if (!getLangOpts().CPlusPlus11)
+  if ((!getLangOpts().CPlusPlus11) || (!getLangOpts().CXXExceptions))
 return;

You can remove the spurious parens.


Repository:
  rL LLVM

https://reviews.llvm.org/D34002



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


[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

2017-06-07 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

LGTM, leave this to alexfh's approval.


Repository:
  rL LLVM

https://reviews.llvm.org/D34002



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


[PATCH] D33493: Speed up preamble loading

2017-06-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added inline comments.



Comment at: include/clang/Frontend/ASTUnit.h:192
+  /// of that loading
+  std::map SrcLocCache;
+

arphaman wrote:
> You can use an `llvm::StringMap` instead.
I will change that



Comment at: lib/Frontend/ASTUnit.cpp:1152
+  else
+SrcLocCache.clear();
 

arphaman wrote:
> Why is `clear` in an `else` here? We always create a new `SourceManager` in 
> this function, so the previously cached locations will be invalid, so 
> shouldn't we always clear the cache before `TranslateStoredDiagnostics`?
When we load diagnostics that means that preamble has not changed. Doesn't that 
mean that source locations can be reused? What can cause them to become invalid?
When preamble is invalidated - cache is cleared.

I can keep cache only during TranslateStoredDiagnostics calls but in that case 
performance improvement is way less.

But if you say that current solution is invalid I will do that


https://reviews.llvm.org/D33493



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


[clang-tools-extra] r304931 - [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

2017-06-07 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Wed Jun  7 12:41:59 2017
New Revision: 304931

URL: http://llvm.org/viewvc/llvm-project?rev=304931&view=rev
Log:
[clang-tidy]  When" -fno-exceptions is used", this warning is better to be 
suppressed.

Summary: clang-tidy is better not to issues this warning, which checks where 
the initializer for the object may throw an exception, when "-fno-exceptions" 
is used.

Reviewers: chh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp

Modified: clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp?rev=304931&r1=304930&r2=304931&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp Wed 
Jun  7 12:41:59 2017
@@ -19,7 +19,7 @@ namespace tidy {
 namespace cert {
 
 void StaticObjectExceptionCheck::registerMatchers(MatchFinder *Finder) {
-  if (!getLangOpts().CPlusPlus)
+  if ((!getLangOpts().CPlusPlus) || (!getLangOpts().CXXExceptions))
 return;
 
   // Match any static or thread_local variable declaration that has an

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp?rev=304931&r1=304930&r2=304931&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
Wed Jun  7 12:41:59 2017
@@ -1,4 +1,9 @@
-// RUN: %check_clang_tidy %s cert-err58-cpp %t -- -- -std=c++11 -target 
x86_64-pc-linux-gnu
+// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -std=c++11 -target 
x86_64-pc-linux-gnu \
+// RUN:   | FileCheck %s -check-prefix=CHECK-EXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -fno-exceptions 
-std=c++11 -target x86_64-pc-linux-gnu \
+// RUN:   | FileCheck %s -allow-empty -check-prefix=CHECK-NONEXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
 
 struct S {
   S() noexcept(false);
@@ -52,39 +57,49 @@ UserConv_Bad some_bad_func() noexcept;
 UserConv_Good some_good_func() noexcept;
 
 S s;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 's' with static 
storage duration may throw an exception that cannot be caught [cert-err58-cpp]
-// CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 's' with 
static storage duration may throw an exception that cannot be caught 
[cert-err58-cpp]
+// CHECK-EXCEPTIONS: 9:3: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 T t; // ok
 U u;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'u' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 12:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'u' with 
static storage duration may throw an exception that cannot be caught
+// CHECK-EXCEPTIONS: 17:3: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 V v("v");
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'v' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'v' with 
static storage duration may throw an exception that cannot be caught
+// CHECK-EXCEPTIONS: 21:12: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 W w;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'w' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 24:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'w' with 
static storage duration may throw an exception that cannot be caught
+// CHECK-EXCEPTIONS: 29:3: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 X x1(S{});
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'x1' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]

[PATCH] D33401: [mips] Add runtime options to enable/disable generation of madd.fmt, msub.fmt

2017-06-07 Thread Petar Jovanovic via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304929: [mips] Add runtime options to enable/disable 
madd.fmt and msub.fmt (authored by petarj).

Changed prior to commit:
  https://reviews.llvm.org/D33401?vs=101562&id=101767#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33401

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
  cfe/trunk/test/CodeGen/mips-madd4.c
  cfe/trunk/test/Preprocessor/init.c

Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2001,6 +2001,10 @@
 def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group;
 def msingle_float : Flag<["-"], "msingle-float">, Group;
 def mdouble_float : Flag<["-"], "mdouble-float">, Group;
+def mmadd4 : Flag<["-"], "mmadd4">, Group,
+  HelpText<"Enable the generation of 4-operand madd.s, madd.d and related instructions.">;
+def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
+  HelpText<"Disable the generation of 4-operand madd.s, madd.d and related instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
   HelpText<"Enable MSA ASE (MIPS only)">;
 def mno_msa : Flag<["-"], "mno-msa">, Group,
Index: cfe/trunk/test/Preprocessor/init.c
===
--- cfe/trunk/test/Preprocessor/init.c
+++ cfe/trunk/test/Preprocessor/init.c
@@ -4664,6 +4664,16 @@
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS-MSA %s
 // MIPS-MSA:#define __mips_msa 1
 //
+// RUN: %clang_cc1 -target-feature +nomadd4 \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS-NOMADD4 %s
+// MIPS-NOMADD4:#define __mips_no_madd4 1
+//
+// RUN: %clang_cc1 \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS-MADD4 %s
+// MIPS-MADD4-NOT:#define __mips_no_madd4 1
+//
 // RUN: %clang_cc1 -target-cpu mips32r3 -target-feature +nan2008 \
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS-NAN2008 %s
Index: cfe/trunk/test/CodeGen/mips-madd4.c
===
--- cfe/trunk/test/CodeGen/mips-madd4.c
+++ cfe/trunk/test/CodeGen/mips-madd4.c
@@ -0,0 +1,86 @@
+// RUN: %clang --target=mips64-unknown-linux -S -mmadd4%s -o -| FileCheck %s -check-prefix=MADD4
+// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 %s -o -| FileCheck %s -check-prefix=NOMADD4
+// RUN: %clang --target=mips64-unknown-linux -S -mmadd4-fno-honor-nans %s -o -| FileCheck %s -check-prefix=MADD4-NONAN
+// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 -fno-honor-nans %s -o -| FileCheck %s -check-prefix=NOMADD4-NONAN
+ 
+float madd_s (float f, float g, float h)
+{
+  return (f * g) + h;
+}
+// MADD4:   madd.s
+// NOMADD4: mul.s
+// NOMADD4: add.s
+
+float msub_s (float f, float g, float h)
+{
+  return (f * g) - h;
+}
+// MADD4:   msub.s
+// NOMADD4: mul.s
+// NOMADD4: sub.s
+
+double madd_d (double f, double g, double h)
+{
+  return (f * g) + h;
+}
+// MADD4:   madd.d
+// NOMADD4: mul.d
+// NOMADD4: add.d
+
+double msub_d (double f, double g, double h)
+{
+  return (f * g) - h;
+}
+// MADD4:   msub.d
+// NOMADD4: mul.d
+// NOMADD4: sub.d
+
+
+float nmadd_s (float f, float g, float h)
+{
+  // FIXME: Zero has been explicitly placed to force generation of a positive
+  // zero in IR until pattern used to match this instruction is changed to
+  // comply with negative zero as well.
+  return 0-((f * g) + h);
+}
+// MADD4-NONAN:   nmadd.s
+// NOMADD4-NONAN: mul.s
+// NOMADD4-NONAN: add.s
+// NOMADD4-NONAN: sub.s
+
+float nmsub_s (float f, float g, float h)
+{
+  // FIXME: Zero has been explicitly placed to force generation of a positive
+  // zero in IR until pattern used to match this instruction is changed to
+  // comply with negative zero as well.
+  return 0-((f * g) - h);
+}
+// MADD4-NONAN:   nmsub.s
+// NOMADD4-NONAN: mul.s
+// NOMADD4-NONAN: sub.s
+// NOMADD4-NONAN: sub.s
+
+double nmadd_d (double f, double g, double h)
+{
+  // FIXME: Zero has been explicitly placed to force generation of a positive
+  // zero in IR until pattern used to match this instruction is changed to
+  // comply with negative zero as well.
+  return 0-((f * g) + h);
+}
+// MADD4-NONAN:   nmadd.d
+// NOMADD4-NONAN: mul.d
+// NOMADD4-NONAN: add.d
+// NOMADD4-NONAN: sub.d
+
+double nmsub_d (double f, double g, double h)
+{
+  // FIXME: Zero has been explicitly placed to force generation of a positive
+  // zero in IR until pattern used to match this instruction is changed to
+  // comply with negative zero as well.
+  return 0-((f * g) - h);
+}
+// MADD4-NONAN:   nmsub.d
+// NOMADD4-NONAN: mul.d
+// NOMADD4-NONAN: sub.d
+// NOMADD4-NONAN: sub.d
+
Index: cfe/tru

r304929 - [mips] Add runtime options to enable/disable madd.fmt and msub.fmt

2017-06-07 Thread Petar Jovanovic via cfe-commits
Author: petarj
Date: Wed Jun  7 12:17:57 2017
New Revision: 304929

URL: http://llvm.org/viewvc/llvm-project?rev=304929&view=rev
Log:
[mips] Add runtime options to enable/disable madd.fmt and msub.fmt

Add options to clang: -mmadd4 and -mno-madd4, use it to enable or disable
generation of madd.fmt and similar instructions respectively, as per GCC.

Patch by Stefan Maksimovic.

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

Added:
cfe/trunk/test/CodeGen/mips-madd4.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=304929&r1=304928&r2=304929&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jun  7 12:17:57 2017
@@ -2001,6 +2001,10 @@ def mdspr2 : Flag<["-"], "mdspr2">, Grou
 def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group;
 def msingle_float : Flag<["-"], "msingle-float">, Group;
 def mdouble_float : Flag<["-"], "mdouble-float">, Group;
+def mmadd4 : Flag<["-"], "mmadd4">, Group,
+  HelpText<"Enable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
+def mno_madd4 : Flag<["-"], "mno-madd4">, Group,
+  HelpText<"Disable the generation of 4-operand madd.s, madd.d and related 
instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group,
   HelpText<"Enable MSA ASE (MIPS only)">;
 def mno_msa : Flag<["-"], "mno-msa">, Group,

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=304929&r1=304928&r2=304929&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Jun  7 12:17:57 2017
@@ -7737,6 +7737,7 @@ class MipsTargetInfo : public TargetInfo
 NoDSP, DSP1, DSP2
   } DspRev;
   bool HasMSA;
+  bool DisableMadd4;
 
 protected:
   bool HasFP64;
@@ -7747,7 +7748,7 @@ public:
   : TargetInfo(Triple), IsMips16(false), IsMicromips(false),
 IsNan2008(false), IsSingleFloat(false), IsNoABICalls(false),
 CanUseBSDABICalls(false), FloatABI(HardFloat), DspRev(NoDSP),
-HasMSA(false), HasFP64(false) {
+HasMSA(false), DisableMadd4(false), HasFP64(false) {
 TheCXXABI.set(TargetCXXABI::GenericMIPS);
 
 setABI((getTriple().getArch() == llvm::Triple::mips ||
@@ -7993,6 +7994,9 @@ public:
 if (HasMSA)
   Builder.defineMacro("__mips_msa", Twine(1));
 
+if (DisableMadd4)
+  Builder.defineMacro("__mips_no_madd4", Twine(1));
+
 Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
 Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
 Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
@@ -8155,6 +8159,8 @@ public:
 DspRev = std::max(DspRev, DSP2);
   else if (Feature == "+msa")
 HasMSA = true;
+  else if (Feature == "+nomadd4")
+DisableMadd4 = true;
   else if (Feature == "+fp64")
 HasFP64 = true;
   else if (Feature == "-fp64")

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=304929&r1=304928&r2=304929&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jun  7 12:17:57 2017
@@ -298,6 +298,13 @@ void mips::getMIPSTargetFeatures(const D
 
   AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
options::OPT_modd_spreg, "nooddspreg");
+
+  if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) {
+if (A->getOption().matches(options::OPT_mmadd4))
+  Features.push_back("-nomadd4");
+else
+  Features.push_back("+nomadd4");
+  }
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) {

Added: cfe/trunk/test/CodeGen/mips-madd4.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips-madd4.c?rev=304929&view=auto
==
--- cfe/trunk/test/CodeGen/mips-madd4.c (added)
+++ cfe/trunk/test/CodeGen/mips-madd4.c Wed Jun  7 12:17:57 2017
@@ -0,0 +1,86 @@
+// RUN: %clang --target=mips64-unknown-linux -S -mmadd4%s -o -| FileCheck 
%s -check-prefix=MADD4
+// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 %s -o -| FileCheck 
%s -check-prefix=NOMADD4
+// RUN: %clang --target=mips64-unknown-linux -S -mmadd4-fno-honor-nans %s 
-o -| FileCheck %s -check-prefix=MADD4-NONAN
+// RUN: %clang --target=mips64-unknown-linux -S -mno-madd4 -fno-honor-nans %s 
-o -| FileCheck %

[PATCH] D26065: Improve diagnostics if friend function redefines file-level function.

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

LGTM.


https://reviews.llvm.org/D26065



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


[PATCH] D33304: [clang-tidy][Part1] Add a new module Android and three new checks.

2017-06-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D33304#771493, @alexfh wrote:

> IIUC, these checks enforce a certain - Android-specific - way of using POSIX 
> APIs. I'm not sure if the recommendations are universally useful. Or am I 
> mistaken?


OK, that makes sense. I may miss some background context.




Comment at: docs/clang-tidy/index.rst:58
 == 
=
+``android``
 ``boost-`` Checks related to Boost library.

Add some words explaining this module?


https://reviews.llvm.org/D33304



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


[PATCH] D31956: Implement (part of) LWG2857: `{variant, optional, any}::emplace` should return the constructed value

2017-06-07 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists closed this revision.
mclow.lists added a comment.

Landed as r300123


https://reviews.llvm.org/D31956



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


[PATCH] D33305: [ubsan] Add a check for pointer overflow UB

2017-06-07 Thread John Regehr via Phabricator via cfe-commits
regehr added a comment.

Well, my second program should subtract a multiple of sizeof(T). But anyway, my 
view is that this is a real overflow and a nasty consequence of the unsigned 
size_t and the usual arithmetic conversions and I don't think we want to try to 
poke a hole in UBSan to allow this idiom unless it turns out to be extremely 
common.

I think it would be better style to cast the sizeof() to a ptrdiff_t rather 
than to an int, but as long as d is a ptrdiff_t this won't matter.


Repository:
  rL LLVM

https://reviews.llvm.org/D33305



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


[PATCH] D33997: Implement the non-execution policy versions of `reduce` and `transform_reduce` for C++17

2017-06-07 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: include/numeric:98
 #include  // for numeric_limits
+#include 
 

I don't like adding this dependency; but the standard requires the use of 
`std::plus` and `std::multiplies`


https://reviews.llvm.org/D33997



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


[PATCH] D33997: Implement the non-execution policy versions of `reduce` and `transform_reduce` for C++17

2017-06-07 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.

There are versions of `reduce` and `transform_reduce` that take an execution 
policy, and those that do not.
This implements the ones that do not.


https://reviews.llvm.org/D33997

Files:
  include/numeric
  test/std/numerics/numeric.ops/reduce/reduce_iter_iter.pass.cpp
  test/std/numerics/numeric.ops/reduce/reduce_iter_iter_T.pass.cpp
  test/std/numerics/numeric.ops/reduce/reduce_iter_iter_T_op.pass.cpp
  
test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp
  
test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
  
test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp

Index: test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp
===
--- test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp
+++ test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp
@@ -0,0 +1,97 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+// UNSUPPORTED: c++98, c++03, c++11, C++14
+
+// template 
+//T transform_reduce(InputIterator1 first1, InputIterator1 last1,
+//   InputIterator2 first2, T init,
+//   BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
+//  
+  
+#include 
+#include 
+
+#include "test_iterators.h"
+
+template 
+void
+test(Iter1 first1, Iter1 last1, Iter2 first2, T init, Op1 op1, Op2 op2, T x)
+{
+static_assert( std::is_same::value, "" );
+assert(std::transform_reduce(first1, last1, first2, init, op1, op2) == x);
+}
+
+template 
+void
+test()
+{
+int ia[]  = {1, 2, 3, 4, 5, 6};
+unsigned int ua[] = {2, 4, 6, 8, 10,12};
+unsigned sa = sizeof(ia) / sizeof(ia[0]);
+assert(sa == sizeof(ua) / sizeof(ua[0]));   // just to be sure
+
+test(SIter(ia), SIter(ia),UIter(ua), 0, std::plus<>(), std::multiplies<>(),   0);
+test(UIter(ua), UIter(ua),SIter(ia), 1, std::multiplies<>(), std::plus<>(),   1);
+test(SIter(ia), SIter(ia+1),  UIter(ua), 0, std::multiplies<>(), std::plus<>(),   0);
+test(UIter(ua), UIter(ua+1),  SIter(ia), 2, std::plus<>(), std::multiplies<>(),   4);
+test(SIter(ia), SIter(ia+2),  UIter(ua), 0, std::plus<>(), std::multiplies<>(),  10);
+test(UIter(ua), UIter(ua+2),  SIter(ia), 3, std::multiplies<>(), std::plus<>(),  54);
+test(SIter(ia), SIter(ia+sa), UIter(ua), 4, std::multiplies<>(), std::plus<>(), 2099520);
+test(UIter(ua), UIter(ua+sa), SIter(ia), 4, std::plus<>(), std::multiplies<>(), 186);
+}
+
+template 
+void test_return_type()
+{
+T *p = nullptr;
+static_assert( std::is_same(), std::multiplies<>()))>::value, "" );
+}
+
+int main()
+{
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+test_return_type();
+
+//  All the iterator categories
+test, input_iterator >();
+test, forward_iterator   >();
+test, bidirectional_iterator >();
+test, random_access_iterator >();
+
+test, input_iterator >();
+test, forward_iterator   >();
+test, bidirectional_iterator >();
+test, random_access_iterator >();
+
+test, input_iterator >();
+test, forward_iterator   >();
+test, bidirectional_iterator >();
+test, random_access_iterator >();
+
+test, input_iterator >();
+test, forward_iterator   >();
+test, bidirectional_iterator >();
+test, random_access_iterator >();
+
+//  just plain pointers (const vs. non-const, too)
+test();
+test();
+test<  int*, const unsigned int *>();
+test<  int*,   unsigned int *>();
+}
Index: test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
===
--- test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
+++ test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
@@ -0,0 +1,95 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--

[PATCH] D33493: Speed up preamble loading

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



Comment at: include/clang/Frontend/ASTUnit.h:192
+  /// of that loading
+  std::map SrcLocCache;
+

You can use an `llvm::StringMap` instead.



Comment at: lib/Frontend/ASTUnit.cpp:1152
+  else
+SrcLocCache.clear();
 

Why is `clear` in an `else` here? We always create a new `SourceManager` in 
this function, so the previously cached locations will be invalid, so shouldn't 
we always clear the cache before `TranslateStoredDiagnostics`?


https://reviews.llvm.org/D33493



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


[PATCH] D33735: [DebugInfo] Add ThisOrSelf attribute for emission of FlagObjectPointer.

2017-06-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 101751.
ABataev added a comment.

Update after review


https://reviews.llvm.org/D33735

Files:
  include/clang/AST/Decl.h
  lib/AST/ASTImporter.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclObjC.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGCXXABI.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaStmt.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGen/captured-statements.c
  test/CodeGenCXX/captured-statements.cpp

Index: test/CodeGenCXX/captured-statements.cpp
===
--- test/CodeGenCXX/captured-statements.cpp
+++ test/CodeGenCXX/captured-statements.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -emit-llvm %s -o %t
+// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -emit-llvm %s -o %t -debug-info-kind=limited
 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-1
 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-2
 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-3
@@ -194,3 +194,18 @@
 void call_test_captured_linkage() {
   test_captured_linkage();
 }
+
+// CHECK-1-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK-1-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
+// CHECK-2-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK-2-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
+// CHECK-3-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK-3-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
+// CHECK-4-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK-4-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
+// CHECK-5-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK-5-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
+// CHECK-6-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK-6-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
+// CHECK-7-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK-7-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
Index: test/CodeGen/captured-statements.c
===
--- test/CodeGen/captured-statements.c
+++ test/CodeGen/captured-statements.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o %t
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o %t -debug-info-kind=limited
 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-GLOBALS
 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-1
 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-2
@@ -98,3 +98,8 @@
 // CHECK-GLOBALS:   load i32, i32* @global
 // CHECK-GLOBALS:   load i32, i32* @
 // CHECK-GLOBALS:   load i32, i32* @e
+
+// CHECK-GLOBALS-NOT: DIFlagObjectPointer
+// CHECK-1-NOT: DIFlagObjectPointer
+// CHECK-2-NOT: DIFlagObjectPointer
+// CHECK-3-NOT: DIFlagObjectPointer
Index: lib/Serialization/ASTWriterDecl.cpp
===
--- lib/Serialization/ASTWriterDecl.cpp
+++ lib/Serialization/ASTWriterDecl.cpp
@@ -915,6 +915,10 @@
 Record.push_back(D->isConstexpr());
 Record.push_back(D->isInitCapture());
 Record.push_back(D->isPreviousDeclInSameBlockScope());
+if (auto *IPD = dyn_cast(D))
+  Record.push_back(static_cast(IPD->getParameterKind()));
+else
+  Record.push_back(0);
   }
   Record.push_back(D->getLinkageInternal());
 
@@ -1989,6 +1993,7 @@
   Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
   Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
   Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
+  Abv->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // IsInitICE (local)
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1229,6 +1229,7 @@
 VD->NonParmVarDeclBits.IsConstexpr = Reco

[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

I have not, as yet, been able to reproduce the buildbot failures.  They were 
essentially intermittent seg-faults, and corrupt diag output.

I will work on creating a test that can reproduce the problem.


https://reviews.llvm.org/D20693



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


[PATCH] D33305: [ubsan] Add a check for pointer overflow UB

2017-06-07 Thread John Regehr via Phabricator via cfe-commits
regehr added a comment.

Sorry, let's go with this example instead, which makes it clear that the 
program is attempting to do something completely sensible:

  #include 
  
  typedef struct {
int x[2];
  } T;
  
  int main(void) {
T f[1000];
T *p = &f[500];
ptrdiff_t d = -10;
p += d / sizeof(T);
return 0;
  }


Repository:
  rL LLVM

https://reviews.llvm.org/D33305



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


Re: [PATCH] D33750: CGCleanup: (NFC) add a test that used to trigger broken IR

2017-06-07 Thread Gor Nishanov via cfe-commits
Sure thing. I'll expand the test to verify that frontend emit expected IR
for this case.
Thank you for the feedback

On Mon, Jun 5, 2017 at 9:58 AM, David Blaikie  wrote:

>
>
> On Wed, May 31, 2017 at 5:45 PM Gor Nishanov via Phabricator via
> cfe-commits  wrote:
>
>> GorNishanov created this revision.
>>
>> Coroutine related test that used to trigger broken IR prior to r304335.
>>
>>
>> https://reviews.llvm.org/D33750
>>
>> Files:
>>   test/CodeGenCoroutines/coro-await-domination.cpp
>>
>>
>> Index: test/CodeGenCoroutines/coro-await-domination.cpp
>> ===
>> --- /dev/null
>> +++ test/CodeGenCoroutines/coro-await-domination.cpp
>> @@ -0,0 +1,38 @@
>> +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts
>> -std=c++14 -emit-llvm %s -o - | FileCheck %s
>
> +#include "Inputs/coroutine.h"
>> +
>> +using namespace std::experimental;
>> +
>> +struct coro {
>> +  struct promise_type {
>> +coro get_return_object();
>> +suspend_never initial_suspend();
>> +suspend_never final_suspend();
>> +void return_void();
>> +static void unhandled_exception();
>> +  };
>> +};
>> +
>> +struct A {
>> +  ~A();
>> +  bool await_ready();
>> +  int await_resume() { return 8; }
>> +  template  void await_suspend(F);
>> +};
>> +
>> +extern "C" void consume(int);
>> +
>> +// Verifies that domination is properly built during cleanup.
>> +// Without CGCleanup.cpp fix verifier was reporting:
>> +// Instruction does not dominate all uses!
>> +//  %tmp.exprcleanup = alloca i32*, align 8
>> +//  store i32* %x, i32** %tmp.exprcleanup, align 8
>> +
>> +
>> +// CHECK-LABEL: f(
>>
>
> This doesn't seem to check much. Should this test check that the IR
> instructions have the 'good' layout, more than that the verifier doesn't
> fail?
>
> Or is that already tested by the test case added in r304335? In that case
> I wouldn't add this test. If the change can/is tested in isolation in
> Clang, that should be sufficient/tends to be how testing is done in the
> regression test suites in the LLVM project. (the test-suite is the place
> for broader/end-to-end testing)
>
>
>> +extern "C" coro f(int) {
>> +  int x = 42;
>> +  x = co_await A{};
>> +  consume(x);
>> +}
>> +
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33305: [ubsan] Add a check for pointer overflow UB

2017-06-07 Thread John Regehr via Phabricator via cfe-commits
regehr added a comment.

I'm taking a look. For reference here's the test program I'm using.

  #include 
  
  typedef struct {
int x[2];
  } T;
  
  int main(void) {
T f;
T *p = &f;
ptrdiff_t d = -3293184;
p += d / sizeof(T);
return 0;
  }


Repository:
  rL LLVM

https://reviews.llvm.org/D33305



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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D20693#775153, @alexfh wrote:

> In https://reviews.llvm.org/D20693#775014, @hintonda wrote:
>
> > - Only pass %2 parameter if %2 is included in format.
>
>
> I thought, DiagnosticsBuilder handles placeholders in conditional parts 
> correctly. Did you find an evidence of the opposite? Can you add a test that 
> consistently fails?


(without your latest change that is)


https://reviews.llvm.org/D20693



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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D20693#775014, @hintonda wrote:

> - Only pass %2 parameter if %2 is included in format.


I thought, DiagnosticsBuilder handles placeholders in conditional parts 
correctly. Did you find an evidence of the opposite? Can you add a test that 
consistently fails?




Comment at: clang-tidy/modernize/UseNoexceptCheck.h:42
+  const std::string NoexceptMacro;
+  bool UseNoexceptFalse;
+};

This can also be `const` for consistency with how options are handled in this 
and other checks.


https://reviews.llvm.org/D20693



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


[PATCH] D33735: [DebugInfo] Add ThisOrSelf attribute for emission of FlagObjectPointer.

2017-06-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: include/clang/AST/Decl.h:901
+/// member functions.
+unsigned ImplicitParamKind : 3;
   };

aaron.ballman wrote:
> ABataev wrote:
> > aaron.ballman wrote:
> > > It's a bit strange to me that the non-parameter declaration bits now have 
> > > a field for implicit parameter information. Why here instead of 
> > > `ParmVarDeclBits`?
> > Actually, `ImplicitParamDecl` already uses some bits from the 
> > `NonParmVarDeclBitfields`, at least it may be marked as `ARCPseudoStrong` 
> > for ObjC. That's why I had to reuse `NonParmVarDeclBitfields` part.
> Ew. That's nasty and we should probably fix that (not as part of this patch). 
> Can you add a FIXME here?
Ok, I will add FIXME for `ARCPseudoStrong` and for the `ImplicitParamKind` 
bitfields


https://reviews.llvm.org/D33735



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


[PATCH] D33735: [DebugInfo] Add ThisOrSelf attribute for emission of FlagObjectPointer.

2017-06-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/AST/Decl.h:901
+/// member functions.
+unsigned ImplicitParamKind : 3;
   };

ABataev wrote:
> aaron.ballman wrote:
> > It's a bit strange to me that the non-parameter declaration bits now have a 
> > field for implicit parameter information. Why here instead of 
> > `ParmVarDeclBits`?
> Actually, `ImplicitParamDecl` already uses some bits from the 
> `NonParmVarDeclBitfields`, at least it may be marked as `ARCPseudoStrong` for 
> ObjC. That's why I had to reuse `NonParmVarDeclBitfields` part.
Ew. That's nasty and we should probably fix that (not as part of this patch). 
Can you add a FIXME here?


https://reviews.llvm.org/D33735



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


[PATCH] D33735: [DebugInfo] Add ThisOrSelf attribute for emission of FlagObjectPointer.

2017-06-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: include/clang/AST/Decl.h:901
+/// member functions.
+unsigned ImplicitParamKind : 3;
   };

aaron.ballman wrote:
> It's a bit strange to me that the non-parameter declaration bits now have a 
> field for implicit parameter information. Why here instead of 
> `ParmVarDeclBits`?
Actually, `ImplicitParamDecl` already uses some bits from the 
`NonParmVarDeclBitfields`, at least it may be marked as `ARCPseudoStrong` for 
ObjC. That's why I had to reuse `NonParmVarDeclBitfields` part.



Comment at: include/clang/AST/Decl.h:1383
 class ImplicitParamDecl : public VarDecl {
+public:
+  /// Defines the kind of the implicit parameter: is this an implicit parameter

aaron.ballman wrote:
> Rather than use three access specifiers, can you reorder this?
> ```
> class ... {
>   void anchor() override;
> 
> public:
>   ...
> };
> ```
Ok



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3467
   ImplicitParamDecl TaskPrivatesArg(
-  C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
-  C.getPointerType(PrivatesQTy).withConst().withRestrict());
+  C, C.getPointerType(PrivatesQTy).withConst().withRestrict(),
+  ImplicitParamDecl::Other);

aaron.ballman wrote:
> This no longer sets the SourceLocation -- is that intended?
Just missed this after some reworks, will return it back


https://reviews.llvm.org/D33735



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


[PATCH] D33735: [DebugInfo] Add ThisOrSelf attribute for emission of FlagObjectPointer.

2017-06-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/AST/Decl.h:901
+/// member functions.
+unsigned ImplicitParamKind : 3;
   };

It's a bit strange to me that the non-parameter declaration bits now have a 
field for implicit parameter information. Why here instead of `ParmVarDeclBits`?



Comment at: include/clang/AST/Decl.h:1383
 class ImplicitParamDecl : public VarDecl {
+public:
+  /// Defines the kind of the implicit parameter: is this an implicit parameter

Rather than use three access specifiers, can you reorder this?
```
class ... {
  void anchor() override;

public:
  ...
};
```



Comment at: lib/CodeGen/CGDebugInfo.cpp:3471
+  // then give it an object pointer flag.
+  if (auto *IPD = dyn_cast(VD)) {
+if (IPD->getParameterKind() == ImplicitParamDecl::CXXThis ||

`const auto *` please.



Comment at: lib/CodeGen/CGDebugInfo.cpp:3586
   // block. Mark it as the object pointer.
-  if (isa(VD) && VD->getName() == "self")
-Ty = CreateSelfType(VD->getType(), Ty);
+  if (auto *IPD = dyn_cast(VD))
+if (IPD->getParameterKind() == ImplicitParamDecl::ObjCSelf)

`const auto *`



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3467
   ImplicitParamDecl TaskPrivatesArg(
-  C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
-  C.getPointerType(PrivatesQTy).withConst().withRestrict());
+  C, C.getPointerType(PrivatesQTy).withConst().withRestrict(),
+  ImplicitParamDecl::Other);

This no longer sets the SourceLocation -- is that intended?



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3479-3480
+ImplicitParamDecl::Other);
+IPD->setLocation(Loc);
+Args.push_back(IPD);
 auto *VD = cast(cast(E)->getDecl());

This code would be cleaner if ImplicitParamDecl::Create() took a SourceLocation 
as it originally did. Perhaps the last param could be a default argument that 
defaults to `SourceLocation{}`?



Comment at: lib/CodeGen/CGStmtOpenMP.cpp:284
 }
-Args.push_back(ImplicitParamDecl::Create(getContext(), nullptr,
- FD->getLocation(), II, ArgType));
+auto *IPD = ImplicitParamDecl::Create(getContext(), /*DC=*/nullptr,
+  FD->getLocation(), II, ArgType,

Why use a local variable here?



Comment at: lib/CodeGen/ItaniumCXXABI.cpp:1411
 QualType T = Context.getPointerType(Context.VoidPtrTy);
-ImplicitParamDecl *VTTDecl
-  = ImplicitParamDecl::Create(Context, nullptr, MD->getLocation(),
-  &Context.Idents.get("vtt"), T);
+ImplicitParamDecl *VTTDecl = ImplicitParamDecl::Create(
+Context, nullptr, MD->getLocation(), &Context.Idents.get("vtt"), T,

Can use `auto *` here.



Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:1416
   if (isa(MD) && MD->getParent()->getNumVBases()) {
-ImplicitParamDecl *IsMostDerived
-  = ImplicitParamDecl::Create(Context, nullptr,
-  CGF.CurGD.getDecl()->getLocation(),
-  &Context.Idents.get("is_most_derived"),
-  Context.IntTy);
+ImplicitParamDecl *IsMostDerived = ImplicitParamDecl::Create(
+Context, /*DC=*/nullptr, CGF.CurGD.getDecl()->getLocation(),

`auto *`



Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:1429
   } else if (isDeletingDtor(CGF.CurGD)) {
-ImplicitParamDecl *ShouldDelete
-  = ImplicitParamDecl::Create(Context, nullptr,
-  CGF.CurGD.getDecl()->getLocation(),
-  &Context.Idents.get("should_call_delete"),
-  Context.IntTy);
+ImplicitParamDecl *ShouldDelete = ImplicitParamDecl::Create(
+Context, /*DC=*/nullptr, CGF.CurGD.getDecl()->getLocation(),

`auto *`



Comment at: lib/Sema/SemaStmt.cpp:3959
   QualType ParamType = Context.getPointerType(Context.getTagDeclType(RD));
-  ImplicitParamDecl *Param
-= ImplicitParamDecl::Create(Context, DC, Loc, ParamName, ParamType);
+  ImplicitParamDecl *Param =
+  ImplicitParamDecl::Create(Context, DC, Loc, ParamName, ParamType,

`auto *` (and elsewhere, I'll stop posting about them.)



Comment at: lib/Serialization/ASTWriterDecl.cpp:918
 Record.push_back(D->isPreviousDeclInSameBlockScope());
+if (auto *IPD = dyn_cast(D))
+  Record.push_back(static_cast(IPD->getParameterKind()));

`const auto *`


https://reviews.llvm.org/D33735



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


[PATCH] D33982: [clang-format] Fix alignment of preprocessor trailing comments

2017-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304912: [clang-format] Fix alignment of preprocessor 
trailing comments (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D33982?vs=101734&id=101736#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33982

Files:
  cfe/trunk/lib/Format/WhitespaceManager.cpp
  cfe/trunk/unittests/Format/FormatTestComments.cpp


Index: cfe/trunk/lib/Format/WhitespaceManager.cpp
===
--- cfe/trunk/lib/Format/WhitespaceManager.cpp
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp
@@ -100,14 +100,52 @@
   Changes[0].PreviousEndOfTokenColumn = 0;
   Change *LastOutsideTokenChange = &Changes[0];
   for (unsigned i = 1, e = Changes.size(); i != e; ++i) {
-unsigned OriginalWhitespaceStart =
-SourceMgr.getFileOffset(Changes[i].OriginalWhitespaceRange.getBegin());
-unsigned PreviousOriginalWhitespaceEnd = SourceMgr.getFileOffset(
-Changes[i - 1].OriginalWhitespaceRange.getEnd());
-Changes[i - 1].TokenLength = OriginalWhitespaceStart -
- PreviousOriginalWhitespaceEnd +
- Changes[i].PreviousLinePostfix.size() +
- Changes[i - 1].CurrentLinePrefix.size();
+SourceLocation OriginalWhitespaceStart =
+Changes[i].OriginalWhitespaceRange.getBegin();
+SourceLocation PreviousOriginalWhitespaceEnd =
+Changes[i - 1].OriginalWhitespaceRange.getEnd();
+unsigned OriginalWhitespaceStartOffset =
+SourceMgr.getFileOffset(OriginalWhitespaceStart);
+unsigned PreviousOriginalWhitespaceEndOffset =
+SourceMgr.getFileOffset(PreviousOriginalWhitespaceEnd);
+assert(PreviousOriginalWhitespaceEndOffset <=
+   OriginalWhitespaceStartOffset);
+const char *const PreviousOriginalWhitespaceEndData =
+SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd);
+StringRef Text(PreviousOriginalWhitespaceEndData,
+   SourceMgr.getCharacterData(OriginalWhitespaceStart) -
+   PreviousOriginalWhitespaceEndData);
+// Usually consecutive changes would occur in consecutive tokens. This is
+// not the case however when analyzing some preprocessor runs of the
+// annotated lines. For example, in this code:
+//
+// #if A // line 1
+// int i = 1;
+// #else B // line 2
+// int i = 2;
+// #endif // line 3
+//
+// one of the runs will produce the sequence of lines marked with line 1, 2
+// and 3. So the two consecutive whitespace changes just before '// line 2'
+// and before '#endif // line 3' span multiple lines and tokens:
+//
+// #else B{change X}[// line 2
+// int i = 2;
+// ]{change Y}#endif // line 3
+//
+// For this reason, if the text between consecutive changes spans multiple
+// newlines, the token length must be adjusted to the end of the original
+// line of the token.
+auto NewlinePos = Text.find_first_of('\n');
+if (NewlinePos == StringRef::npos) {
+  Changes[i - 1].TokenLength = OriginalWhitespaceStartOffset -
+   PreviousOriginalWhitespaceEndOffset +
+   Changes[i].PreviousLinePostfix.size() +
+   Changes[i - 1].CurrentLinePrefix.size();
+} else {
+  Changes[i - 1].TokenLength =
+  NewlinePos + Changes[i - 1].CurrentLinePrefix.size();
+}
 
 // If there are multiple changes in this token, sum up all the changes 
until
 // the end of the line.
Index: cfe/trunk/unittests/Format/FormatTestComments.cpp
===
--- cfe/trunk/unittests/Format/FormatTestComments.cpp
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp
@@ -1052,6 +1052,30 @@
"}", getLLVMStyleWithColumns(80));
 }
 
+TEST_F(FormatTestComments, AlignsPPElseEndifComments) {
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ; // CC\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  EXPECT_EQ("#if A\n"
+"#else  // A1\n"
+"   // A2\n"
+"int ii;\n"
+"#endif // B",
+format("#if A\n"
+   "#else  // A1\n"
+   "   // A2\n"
+   "int ii;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20)));
+}
+
 TEST_F(FormatTestComments, CommentsInStaticInitializers) {
   EXPECT_EQ(
   "static SomeType type = {, /* comment */\n"


Index: cfe/trunk/lib/Format/WhitespaceManager.cpp

r304912 - [clang-format] Fix alignment of preprocessor trailing comments

2017-06-07 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Jun  7 09:05:06 2017
New Revision: 304912

URL: http://llvm.org/viewvc/llvm-project?rev=304912&view=rev
Log:
[clang-format] Fix alignment of preprocessor trailing comments

Summary:
This patch is a follow-up of https://reviews.llvm.org/rL304687, which fixed an
overflow in the comment alignment code in clang-format. The token length of
trailing comments of preprocessor directives is calculated incorrectly by
including the text between consecutive directives. That causes them to not being
aligned.

For example, in this code with column limit 20
```
#if A
#else  // A
int ;
#endif // B
```
the length of the token `// A` was wrongly calculated as 14 = 5 (the size of 
`// A\n`) plus 9 (the size of `int ;`) and so `// A` wouldn't be aligned 
with `// B` and this was produced:
```
#if A
#else // A
int ;
#endif // B
```

This patch fixes this case.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=304912&r1=304911&r2=304912&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Wed Jun  7 09:05:06 2017
@@ -100,14 +100,52 @@ void WhitespaceManager::calculateLineBre
   Changes[0].PreviousEndOfTokenColumn = 0;
   Change *LastOutsideTokenChange = &Changes[0];
   for (unsigned i = 1, e = Changes.size(); i != e; ++i) {
-unsigned OriginalWhitespaceStart =
-SourceMgr.getFileOffset(Changes[i].OriginalWhitespaceRange.getBegin());
-unsigned PreviousOriginalWhitespaceEnd = SourceMgr.getFileOffset(
-Changes[i - 1].OriginalWhitespaceRange.getEnd());
-Changes[i - 1].TokenLength = OriginalWhitespaceStart -
- PreviousOriginalWhitespaceEnd +
- Changes[i].PreviousLinePostfix.size() +
- Changes[i - 1].CurrentLinePrefix.size();
+SourceLocation OriginalWhitespaceStart =
+Changes[i].OriginalWhitespaceRange.getBegin();
+SourceLocation PreviousOriginalWhitespaceEnd =
+Changes[i - 1].OriginalWhitespaceRange.getEnd();
+unsigned OriginalWhitespaceStartOffset =
+SourceMgr.getFileOffset(OriginalWhitespaceStart);
+unsigned PreviousOriginalWhitespaceEndOffset =
+SourceMgr.getFileOffset(PreviousOriginalWhitespaceEnd);
+assert(PreviousOriginalWhitespaceEndOffset <=
+   OriginalWhitespaceStartOffset);
+const char *const PreviousOriginalWhitespaceEndData =
+SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd);
+StringRef Text(PreviousOriginalWhitespaceEndData,
+   SourceMgr.getCharacterData(OriginalWhitespaceStart) -
+   PreviousOriginalWhitespaceEndData);
+// Usually consecutive changes would occur in consecutive tokens. This is
+// not the case however when analyzing some preprocessor runs of the
+// annotated lines. For example, in this code:
+//
+// #if A // line 1
+// int i = 1;
+// #else B // line 2
+// int i = 2;
+// #endif // line 3
+//
+// one of the runs will produce the sequence of lines marked with line 1, 2
+// and 3. So the two consecutive whitespace changes just before '// line 2'
+// and before '#endif // line 3' span multiple lines and tokens:
+//
+// #else B{change X}[// line 2
+// int i = 2;
+// ]{change Y}#endif // line 3
+//
+// For this reason, if the text between consecutive changes spans multiple
+// newlines, the token length must be adjusted to the end of the original
+// line of the token.
+auto NewlinePos = Text.find_first_of('\n');
+if (NewlinePos == StringRef::npos) {
+  Changes[i - 1].TokenLength = OriginalWhitespaceStartOffset -
+   PreviousOriginalWhitespaceEndOffset +
+   Changes[i].PreviousLinePostfix.size() +
+   Changes[i - 1].CurrentLinePrefix.size();
+} else {
+  Changes[i - 1].TokenLength =
+  NewlinePos + Changes[i - 1].CurrentLinePrefix.size();
+}
 
 // If there are multiple changes in this token, sum up all the changes 
until
 // the end of the line.

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=304912&r1=304911&r2=304912&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Jun  7 09:05:0

[PATCH] D33982: [clang-format] Fix alignment of preprocessor trailing comments

2017-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 101734.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D33982

Files:
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTestComments.cpp


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -1052,6 +1052,30 @@
"}", getLLVMStyleWithColumns(80));
 }
 
+TEST_F(FormatTestComments, AlignsPPElseEndifComments) {
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ; // CC\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  EXPECT_EQ("#if A\n"
+"#else  // A1\n"
+"   // A2\n"
+"int ii;\n"
+"#endif // B",
+format("#if A\n"
+   "#else  // A1\n"
+   "   // A2\n"
+   "int ii;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20)));
+}
+
 TEST_F(FormatTestComments, CommentsInStaticInitializers) {
   EXPECT_EQ(
   "static SomeType type = {, /* comment */\n"
Index: lib/Format/WhitespaceManager.cpp
===
--- lib/Format/WhitespaceManager.cpp
+++ lib/Format/WhitespaceManager.cpp
@@ -100,14 +100,52 @@
   Changes[0].PreviousEndOfTokenColumn = 0;
   Change *LastOutsideTokenChange = &Changes[0];
   for (unsigned i = 1, e = Changes.size(); i != e; ++i) {
-unsigned OriginalWhitespaceStart =
-SourceMgr.getFileOffset(Changes[i].OriginalWhitespaceRange.getBegin());
-unsigned PreviousOriginalWhitespaceEnd = SourceMgr.getFileOffset(
-Changes[i - 1].OriginalWhitespaceRange.getEnd());
-Changes[i - 1].TokenLength = OriginalWhitespaceStart -
- PreviousOriginalWhitespaceEnd +
- Changes[i].PreviousLinePostfix.size() +
- Changes[i - 1].CurrentLinePrefix.size();
+SourceLocation OriginalWhitespaceStart =
+Changes[i].OriginalWhitespaceRange.getBegin();
+SourceLocation PreviousOriginalWhitespaceEnd =
+Changes[i - 1].OriginalWhitespaceRange.getEnd();
+unsigned OriginalWhitespaceStartOffset =
+SourceMgr.getFileOffset(OriginalWhitespaceStart);
+unsigned PreviousOriginalWhitespaceEndOffset =
+SourceMgr.getFileOffset(PreviousOriginalWhitespaceEnd);
+assert(PreviousOriginalWhitespaceEndOffset <=
+   OriginalWhitespaceStartOffset);
+const char *const PreviousOriginalWhitespaceEndData =
+SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd);
+StringRef Text(PreviousOriginalWhitespaceEndData,
+   SourceMgr.getCharacterData(OriginalWhitespaceStart) -
+   PreviousOriginalWhitespaceEndData);
+// Usually consecutive changes would occur in consecutive tokens. This is
+// not the case however when analyzing some preprocessor runs of the
+// annotated lines. For example, in this code:
+//
+// #if A // line 1
+// int i = 1;
+// #else B // line 2
+// int i = 2;
+// #endif // line 3
+//
+// one of the runs will produce the sequence of lines marked with line 1, 2
+// and 3. So the two consecutive whitespace changes just before '// line 2'
+// and before '#endif // line 3' span multiple lines and tokens:
+//
+// #else B{change X}[// line 2
+// int i = 2;
+// ]{change Y}#endif // line 3
+//
+// For this reason, if the text between consecutive changes spans multiple
+// newlines, the token length must be adjusted to the end of the original
+// line of the token.
+auto NewlinePos = Text.find_first_of('\n');
+if (NewlinePos == StringRef::npos) {
+  Changes[i - 1].TokenLength = OriginalWhitespaceStartOffset -
+   PreviousOriginalWhitespaceEndOffset +
+   Changes[i].PreviousLinePostfix.size() +
+   Changes[i - 1].CurrentLinePrefix.size();
+} else {
+  Changes[i - 1].TokenLength =
+  NewlinePos + Changes[i - 1].CurrentLinePrefix.size();
+}
 
 // If there are multiple changes in this token, sum up all the changes 
until
 // the end of the line.


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -1052,6 +1052,30 @@
"}", getLLVMStyleWithColumns(80));
 }
 
+TEST_F(FormatTestComments, AlignsPPElseEndifComments) {
+  verifyFormat("#if A\n"
+   "#el

[PATCH] D33726: [driver][netbsd] Build and pass `-L` arguments to the linker

2017-06-07 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

In https://reviews.llvm.org/D33726#774105, @ruiu wrote:

> I'm totally against adding per-OS path knowledge to our linker. Compilers 
> already know include paths and I don't want to maintain another list of paths 
> in the linker. Also this can be more confusing than useful when you are doing 
> cross-linking.


The only reason for compilers to maintain that list is for finding crt*.o. They 
otherwise don't care about the library paths at all. There is no confusion for 
cross-linking as long as proper sysroot support is used. Which we have been 
doing on NetBSD for ages.

> For all OSes other than NetBSD, LLD works fine with the clang driver as the 
> driver passes include paths to the linker. I don't see any reason not to do 
> the same thing for NetBSD. That stands even if the linker has to have a list 
> of include paths.

Sorry, but this is again ignorant and wrong. The very same problem of build 
systems calling ld directly apply on most other systems. Even then, the list of 
linker paths is not the only OS-specific knowledge. Things like the DT_RPATH vs 
DT_RUNPATH mess, init vs init_array all belong into this category. The list 
goes on.


Repository:
  rL LLVM

https://reviews.llvm.org/D33726



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


[PATCH] D33305: [ubsan] Add a check for pointer overflow UB

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

Just a heads up that I ran into an arguably somewhat unexpected instance of 
this with (a copy of the Graphite project included in) LibreOffice, see the 
commit message of 
https://cgit.freedesktop.org/libreoffice/core/commit/?id=681b4a49d797996229513d3e842d2a431030730a
 "external/graphite: Avoid -fsanitize=pointer-overflow" for details.  (In 
short,  "ptrdiff_t d = ...; T * p += d / sizeof(T);" can trigger an overflow 
warning when d is negative.)


Repository:
  rL LLVM

https://reviews.llvm.org/D33305



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


[PATCH] D31972: Do not force the frame pointer by default for ARM EABI

2017-06-07 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Actually, for NetBSD we want to use -fomit-frame-pointer by default whenever 
the implicit -funwind-tables is also present. In general, that should be the 
justification for the default behavior: "Can I reliably unwind a binary with 
the available information?" Performance of stack unwinding is IMO secondary and 
users of sanitizers can disable it where necessary.


https://reviews.llvm.org/D31972



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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 101722.
hintonda added a comment.



- Only pass %2 parameter if %2 is included in format.


https://reviews.llvm.org/D20693

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept-opt.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A {};
+class B {};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+template 
+void foo() throw();
+void footest() { foo(); foo(); }
+// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw(...)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void k() throw(int(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void k() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+void baz(int = (throw A(), 0)) throw(A, B) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void baz(int = (throw A(), 0)) noexcept(false) {}
+
+void g(void (*fp)(void) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void g(void (*fp)(void) noexcept);
+
+void f(void (*fp)(void) throw(int)) throw(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'throw(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void f(void (*fp)(void) noexcept(false)) noexcept(false);
+
+#define THROW throw
+void h(void (*fp)(void) THROW(int)) THROW(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'THROW(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'THROW(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void h(void (*fp)(void) noexcept(false)) noexcept(false);
+
+void j() throw(int(int) throw(void(void) throw(int)));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int) throw(void(void) throw(int)))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void j() noexcept(false);
+
+class Y {
+  Y() throw() = default;
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: Y() noexcept = default;
+
+struct Z {
+  void operator delete(void *ptr) throw();
+  void operator delete[](void *ptr) throw(int);
+  ~Z() throw(int) {}
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void operator delete(void *ptr) noexcept;
+// CHECK-FIXES: void operator delete[](void *ptr) noexcept(false);
+// CHECK-FIXES: ~Z() noexcept(

[PATCH] D33989: [OpenCL] Allow targets to select address space per type

2017-06-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.

Generalize getOpenCLImageAddrSpace into getOpenCLTypeAddrSpace, such
that targets can select the address space per type.

No functional changes intended.  In particular, this is already
covered by test/CodeGenOpenCL/opencl_types.cl .

Patch by Simon Perretta.


https://reviews.llvm.org/D33989

Files:
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp

Index: lib/CodeGen/CGOpenCLRuntime.cpp
===
--- lib/CodeGen/CGOpenCLRuntime.cpp
+++ lib/CodeGen/CGOpenCLRuntime.cpp
@@ -35,32 +35,39 @@
  "Not an OpenCL specific type!");
 
   llvm::LLVMContext& Ctx = CGM.getLLVMContext();
-  uint32_t ImgAddrSpc = CGM.getContext().getTargetAddressSpace(
-CGM.getTarget().getOpenCLImageAddrSpace());
   switch (cast(T)->getKind()) {
   default:
 llvm_unreachable("Unexpected opencl builtin type!");
 return nullptr;
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
   case BuiltinType::Id: \
 return llvm::PointerType::get( \
 llvm::StructType::create(Ctx, "opencl." #ImgType "_" #Suffix "_t"), \
-ImgAddrSpc);
+CGM.getContext().getTargetAddressSpace( \
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::Id)));
 #include "clang/Basic/OpenCLImageTypes.def"
   case BuiltinType::OCLSampler:
 return getSamplerType();
   case BuiltinType::OCLEvent:
-return llvm::PointerType::get(llvm::StructType::create(
-   Ctx, "opencl.event_t"), 0);
+return llvm::PointerType::get(
+llvm::StructType::create(Ctx, "opencl.event_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLEvent)));
   case BuiltinType::OCLClkEvent:
 return llvm::PointerType::get(
-llvm::StructType::create(Ctx, "opencl.clk_event_t"), 0);
+llvm::StructType::create(Ctx, "opencl.clk_event_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLClkEvent)));
   case BuiltinType::OCLQueue:
 return llvm::PointerType::get(
-llvm::StructType::create(Ctx, "opencl.queue_t"), 0);
+llvm::StructType::create(Ctx, "opencl.queue_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLQueue)));
   case BuiltinType::OCLReserveID:
 return llvm::PointerType::get(
-llvm::StructType::create(Ctx, "opencl.reserve_id_t"), 0);
+llvm::StructType::create(Ctx, "opencl.reserve_id_t"),
+CGM.getContext().getTargetAddressSpace(
+CGM.getTarget().getOpenCLTypeAddrSpace(BuiltinType::OCLReserveID)));
   }
 }
 
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2364,8 +2364,17 @@
 }
   }
 
-  LangAS::ID getOpenCLImageAddrSpace() const override {
+  virtual LangAS::ID
+  getOpenCLTypeAddrSpace(BuiltinType::Kind K) const override {
+switch (K) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   \
+  case BuiltinType::Id:\
 return LangAS::opencl_constant;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+default:
+  return LangAS::Default;
+}
   }
 
   /// \returns Target specific vtbl ptr address space.
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -1624,6 +1624,7 @@
   uint64_t Width = 0;
   unsigned Align = 8;
   bool AlignIsRequired = false;
+  unsigned AS = 0;
   switch (T->getTypeClass()) {
 #define TYPE(Class, Base)
 #define ABSTRACT_TYPE(Class, Base)
@@ -1771,7 +1772,7 @@
   Align = Target->getPointerAlign(0);
   break;
 case BuiltinType::OCLSampler: {
-  auto AS = getTargetAddressSpace(LangAS::opencl_constant);
+  AS = getTargetAddressSpace(LangAS::opencl_constant);
   Width = Target->getPointerWidth(AS);
   Align = Target->getPointerAlign(AS);
   break;
@@ -1785,10 +1786,10 @@
   Align = Target->getPointerAlign(0);
   break;
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-case BuiltinType::Id:
+case BuiltinType::Id: \
+  AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(BuiltinType::Id));
 #include "clang/Basic/OpenCLImageTypes.def"
   {
-auto AS = getTargetAddressSpace(Target->getOpenCLImageAddrSpace());
 Width = Target->getPointerWidth(AS);
 Align = Target->getPointerAlign(AS);
   }
@@ -1799,24 +1800,22 @@
 Align = Target->getPointerAlign(0);
 break;
   case Type::BlockPointer: {
-unsigned AS = getTargetAddressSpace(
-cast(T)->getPointeeType());
+AS = getTargetAddressSpace(cast(T)->getPointeeType());
 Width = Targ

[PATCH] D33982: [clang-format] Fix alignment of preprocessor trailing comments

2017-06-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG




Comment at: lib/Format/WhitespaceManager.cpp:112
+assert(PreviousOriginalWhitespaceEndOffset <= 
OriginalWhitespaceStartOffset);
+StringRef Text(SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd),
+   SourceMgr.getCharacterData(OriginalWhitespaceStart) -

I'd pull `SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd)` out to a 
variable.


https://reviews.llvm.org/D33982



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


r304904 - clang-format: [JS] recognize exported type definitions.

2017-06-07 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Wed Jun  7 07:53:22 2017
New Revision: 304904

URL: http://llvm.org/viewvc/llvm-project?rev=304904&view=rev
Log:
clang-format: [JS] recognize exported type definitions.

Summary: Support "export type T = {...};", in addition to just "type T = 
{...};".

Reviewers: klimek

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=304904&r1=304903&r2=304904&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jun  7 07:53:22 2017
@@ -135,8 +135,11 @@ private:
 if (Left->is(TT_OverloadedOperatorLParen)) {
   Contexts.back().IsExpression = false;
 } else if (Style.Language == FormatStyle::LK_JavaScript &&
-   Line.startsWith(Keywords.kw_type, tok::identifier)) {
+   (Line.startsWith(Keywords.kw_type, tok::identifier) ||
+Line.startsWith(tok::kw_export, Keywords.kw_type,
+tok::identifier))) {
   // type X = (...);
+  // export type X = (...);
   Contexts.back().IsExpression = false;
 } else if (Left->Previous &&
 (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_decltype,
@@ -979,9 +982,12 @@ private:
   void modifyContext(const FormatToken &Current) {
 if (Current.getPrecedence() == prec::Assignment &&
 !Line.First->isOneOf(tok::kw_template, tok::kw_using, tok::kw_return) 
&&
-// Type aliases use `type X = ...;` in TypeScript.
+// Type aliases use `type X = ...;` in TypeScript and can be exported
+// using `export type ...`.
 !(Style.Language == FormatStyle::LK_JavaScript &&
-  Line.startsWith(Keywords.kw_type, tok::identifier)) &&
+  (Line.startsWith(Keywords.kw_type, tok::identifier) ||
+   Line.startsWith(tok::kw_export, Keywords.kw_type,
+   tok::identifier))) &&
 (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
   Contexts.back().IsExpression = true;
   if (!Line.startsWith(TT_UnaryOperator)) {

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=304904&r1=304903&r2=304904&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Jun  7 07:53:22 2017
@@ -1226,6 +1226,12 @@ TEST_F(FormatTestJS, UnionIntersectionTy
   verifyFormat("let x: Bar|Baz;");
   verifyFormat("let x: Bar|Baz;");
   verifyFormat("let x: (Foo|Bar)[];");
+  verifyFormat("type X = {\n"
+   "  a: Foo|Bar;\n"
+   "};");
+  verifyFormat("export type X = {\n"
+   "  a: Foo|Bar;\n"
+   "};");
 }
 
 TEST_F(FormatTestJS, ClassDeclarations) {


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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

Unfortunately, the logs are no longer available, and I don't have copies.

However, I think I know what's going on, so I'll try to submit a fix later 
today.


https://reviews.llvm.org/D20693



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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-06-07 Thread don hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 101708.
hintonda added a comment.

- Rollback to previous version: rebased + r293218 and r293234.


https://reviews.llvm.org/D20693

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept-opt.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A {};
+class B {};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+template 
+void foo() throw();
+void footest() { foo(); foo(); }
+// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: dynamic exception specification 'throw(...)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void k() throw(int(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void k() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:15: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+void baz(int = (throw A(), 0)) throw(A, B) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: dynamic exception specification 'throw(A, B)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void baz(int = (throw A(), 0)) noexcept(false) {}
+
+void g(void (*fp)(void) throw());
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void g(void (*fp)(void) noexcept);
+
+void f(void (*fp)(void) throw(int)) throw(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'throw(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void f(void (*fp)(void) noexcept(false)) noexcept(false);
+
+#define THROW throw
+void h(void (*fp)(void) THROW(int)) THROW(char);
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: dynamic exception specification 'THROW(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: dynamic exception specification 'THROW(char)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void h(void (*fp)(void) noexcept(false)) noexcept(false);
+
+void j() throw(int(int) throw(void(void) throw(int)));
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: dynamic exception specification 'throw(int(int) throw(void(void) throw(int)))' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void j() noexcept(false);
+
+class Y {
+  Y() throw() = default;
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: Y() noexcept = default;
+
+struct Z {
+  void operator delete(void *ptr) throw();
+  void operator delete[](void *ptr) throw(int);
+  ~Z() throw(int) {}
+};
+// CHECK-MESSAGES: :[[@LINE-4]]:35: warning: dynamic exception specification 'throw()' is deprecated; consider using 'noexcept' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:37: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-MESSAGES: :[[@LINE-4]]:8: warning: dynamic exception specification 'throw(int)' is deprecated; consider using 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void operator delete(void *ptr) noexcept;
+// CHECK-FIXES: void operator delete[](void *ptr) noexcept(false);
+// CHECK-FIXES: ~Z() no

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

2017-06-07 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun marked 2 inline comments as done.
xazax.hun added a comment.

In https://reviews.llvm.org/D30691#731617, @zaks.anna wrote:

> I agree that scan-build or scan-build-py integration is an important issue to 
> resolve here. What I envision is that users will just call scan-build and 
> pass -whole-project as an option to it. Everything else will happen 
> automagically:)


We contacted Laszlo and we have a pull request into scan-build that is under 
review. He is very helpful and supports the idea of scan-build-py supporting 
CTU analysis.

> I do not quite understand why AST serialization is needed at all. Can we 
> instead recompile the translation units on demand into a separate ASTContext 
> and then ASTImport?

We did a prototype implementation of on-demand reparsing. On the C projects we 
tested, the runtime is increased by 10-30% compared to dumping the ASTs. Note 
that, it is relatively fast to parse C, I would expect a much bigger delta in 
case of C++ projects. Unfortunately, we weren't able to test that setting due 
to the ASTImporter limitations.




Comment at: include/clang/AST/Mangle.h:59
+  // the static analyzer.
+  bool ShouldForceMangleProto;
 

xazax.hun wrote:
> dcoughlin wrote:
> > I'm pretty worried about using C++ mangling for C functions. It doesn't 
> > ever seem appropriate to do so and it sounds like it is papering over 
> > problems with the design.
> > 
> > Some questions:
> > - How do you handle when two translation units have different C functions 
> > with the same type signatures? Is there a collision? This can arise because 
> > of two-level namespacing or when building multiple targets with the same 
> > CTU directory.
> > - How do you handle when a C function has the same signature as a C++ 
> > function. Is there a collision when you mangle the C function?
> I agree that using C++ mangling for C+ is not the nicest solution, and I had 
> to circumvent a problem in the name mangler for C prototypes.
> 
> In case a mangled name is found in multiple source files, it will not be 
> imported. This is the way how collisions handled regardless of being C or C++ 
> functions. 
> The target arch is appended to the mangled name to support the cross 
> compilation scenario. Currently we do not add the full triple, but this could 
> be done.
> 
> An alternative solution would be to use USRs instead of mangled names but we 
> did not explore this option in depth yet. 
Note that the newest version of this patch does not use name mangling, it uses 
USRs instead. This turned out to be a perfectly viable alternative and we did 
not see any behavioral changes on the project we tested after the transition.


https://reviews.llvm.org/D30691



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


[PATCH] D33981: Only print registered targets for `--version`

2017-06-07 Thread Dimitry Andric via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304899: Only print registered targets for `--version` 
(authored by dim).

Changed prior to commit:
  https://reviews.llvm.org/D33981?vs=101690&id=101697#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33981

Files:
  cfe/trunk/lib/Driver/Driver.cpp


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1117,10 +1117,6 @@
 
   // Print out the install directory.
   OS << "InstalledDir: " << InstalledDir << '\n';
-
-  // Print registered targets.
-  OS << '\n';
-  llvm::TargetRegistry::printRegisteredTargetsForVersion(OS);
 }
 
 /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories
@@ -1166,6 +1162,10 @@
   if (C.getArgs().hasArg(options::OPT__version)) {
 // Follow gcc behavior and use stdout for --version and stderr for -v.
 PrintVersion(C, llvm::outs());
+
+// Print registered targets.
+llvm::outs() << '\n';
+llvm::TargetRegistry::printRegisteredTargetsForVersion(llvm::outs());
 return false;
   }
 


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1117,10 +1117,6 @@
 
   // Print out the install directory.
   OS << "InstalledDir: " << InstalledDir << '\n';
-
-  // Print registered targets.
-  OS << '\n';
-  llvm::TargetRegistry::printRegisteredTargetsForVersion(OS);
 }
 
 /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories
@@ -1166,6 +1162,10 @@
   if (C.getArgs().hasArg(options::OPT__version)) {
 // Follow gcc behavior and use stdout for --version and stderr for -v.
 PrintVersion(C, llvm::outs());
+
+// Print registered targets.
+llvm::outs() << '\n';
+llvm::TargetRegistry::printRegisteredTargetsForVersion(llvm::outs());
 return false;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r304899 - Only print registered targets for `--version`

2017-06-07 Thread Dimitry Andric via cfe-commits
Author: dim
Date: Wed Jun  7 07:05:41 2017
New Revision: 304899

URL: http://llvm.org/viewvc/llvm-project?rev=304899&view=rev
Log:
Only print registered targets for `--version`

Summary:
In D33900, I added printing of the registered targets in clang's
`PrintVersion` function, which is not only used for `--version` output,
but also for `-v` (verbose mode) and `-###`.  Especially the latter
seems to trip up some test cases, so it is probably better to only print
the registered targets for `--version`.

Reviewers: nemanjai, mehdi_amini

Reviewed By: nemanjai

Subscribers: cfe-commits

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

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

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=304899&r1=304898&r2=304899&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Jun  7 07:05:41 2017
@@ -1117,10 +1117,6 @@ void Driver::PrintVersion(const Compilat
 
   // Print out the install directory.
   OS << "InstalledDir: " << InstalledDir << '\n';
-
-  // Print registered targets.
-  OS << '\n';
-  llvm::TargetRegistry::printRegisteredTargetsForVersion(OS);
 }
 
 /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories
@@ -1166,6 +1162,10 @@ bool Driver::HandleImmediateArgs(const C
   if (C.getArgs().hasArg(options::OPT__version)) {
 // Follow gcc behavior and use stdout for --version and stderr for -v.
 PrintVersion(C, llvm::outs());
+
+// Print registered targets.
+llvm::outs() << '\n';
+llvm::TargetRegistry::printRegisteredTargetsForVersion(llvm::outs());
 return false;
   }
 


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


  1   2   >