r290539 - [inline-asm]No error for conflict between inputs\outputs and clobber list

2016-12-26 Thread Marina Yatsina via cfe-commits
Author: myatsina
Date: Mon Dec 26 06:23:42 2016
New Revision: 290539

URL: http://llvm.org/viewvc/llvm-project?rev=290539&view=rev
Log:
[inline-asm]No error for conflict between inputs\outputs and clobber list

According to extended asm syntax, a case where the clobber list includes a 
variable from the inputs or outputs should be an error - conflict.
for example:

const long double a = 0.0;
int main()
{

char b;
double t1 = a;
__asm__ ("fucompp": "=a" (b) : "u" (t1), "t" (t1) : "cc", "st", "st(1)");

return 0;
}

This should conflict with the output - t1 which is st, and st which is st 
aswell.
The patch fixes it.

Commit on behald of Ziv Izhar.

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/lib/Sema/SemaStmtAsm.cpp
cfe/trunk/test/Sema/asm.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=290539&r1=290538&r2=290539&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Dec 26 06:23:42 
2016
@@ -7069,6 +7069,10 @@ let CategoryName = "Inline Assembly Issu
 "constraint '%0' is already present here">;
 }
 
+  def error_inoutput_conflict_with_clobber : Error<
+"asm-specifier for input or output variable conflicts with asm"
+" clobber list">;
+
 let CategoryName = "Semantic Issue" in {
 
 def err_invalid_conversion_between_vectors : Error<

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=290539&r1=290538&r2=290539&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Mon Dec 26 06:23:42 2016
@@ -605,8 +605,16 @@ public:
 
   /// \brief Returns the "normalized" GCC register name.
   ///
-  /// For example, on x86 it will return "ax" when "eax" is passed in.
-  StringRef getNormalizedGCCRegisterName(StringRef Name) const;
+  /// ReturnCannonical true will return the register name without any additions
+  /// such as "{}" or "%" in it's canonical form, for example:
+  /// ReturnCanonical = true and Name = "rax", will return "ax".
+  StringRef getNormalizedGCCRegisterName(StringRef Name,
+ bool ReturnCanonical = false) const;
+ 
+  virtual StringRef getConstraintRegister(const StringRef &Constraint,
+  const StringRef &Expression) const {
+return "";
+  }
 
   struct ConstraintInfo {
 enum {

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=290539&r1=290538&r2=290539&view=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Mon Dec 26 06:23:42 2016
@@ -410,8 +410,8 @@ bool TargetInfo::isValidGCCRegisterName(
   return false;
 }
 
-StringRef
-TargetInfo::getNormalizedGCCRegisterName(StringRef Name) const {
+StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name,
+   bool ReturnCanonical) const 
{
   assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
 
   // Get rid of any register prefix.
@@ -436,7 +436,7 @@ TargetInfo::getNormalizedGCCRegisterName
   // Make sure the register that the additional name is for is within
   // the bounds of the register names from above.
   if (AN == Name && ARN.RegNum < Names.size())
-return Name;
+return ReturnCanonical ? Names[ARN.RegNum] : Name;
 }
 
   // Now check aliases.

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=290539&r1=290538&r2=290539&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Dec 26 06:23:42 2016
@@ -2789,6 +2789,40 @@ public:
   const char *getClobbers() const override {
 return "~{dirflag},~{fpsr},~{flags}";
   }
+
+  StringRef getConstraintRegister(const StringRef &Constraint,
+  const StringRef &Expression) const override {
+StringRef::iterator I, E;
+for (I = Constraint.begin(), E = Constraint.end(); I != E; ++I) {
+  if (isalpha(*I))
+break;
+}
+if (I == E)
+  return "";
+switch (*I) {
+// For the register constraints, return the match

[PATCH] D15075: No error for conflict between inputs\outputs and clobber list

2016-12-26 Thread Marina Yatsina via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290539: [inline-asm]No error for conflict between 
inputs\outputs and clobber list (authored by myatsina).

Changed prior to commit:
  https://reviews.llvm.org/D15075?vs=74500&id=82495#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D15075

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/Headers/intrin.h
  cfe/trunk/lib/Sema/SemaStmtAsm.cpp
  cfe/trunk/test/Sema/asm.c

Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -605,8 +605,16 @@
 
   /// \brief Returns the "normalized" GCC register name.
   ///
-  /// For example, on x86 it will return "ax" when "eax" is passed in.
-  StringRef getNormalizedGCCRegisterName(StringRef Name) const;
+  /// ReturnCannonical true will return the register name without any additions
+  /// such as "{}" or "%" in it's canonical form, for example:
+  /// ReturnCanonical = true and Name = "rax", will return "ax".
+  StringRef getNormalizedGCCRegisterName(StringRef Name,
+ bool ReturnCanonical = false) const;
+ 
+  virtual StringRef getConstraintRegister(const StringRef &Constraint,
+  const StringRef &Expression) const {
+return "";
+  }
 
   struct ConstraintInfo {
 enum {
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7069,6 +7069,10 @@
 "constraint '%0' is already present here">;
 }
 
+  def error_inoutput_conflict_with_clobber : Error<
+"asm-specifier for input or output variable conflicts with asm"
+" clobber list">;
+
 let CategoryName = "Semantic Issue" in {
 
 def err_invalid_conversion_between_vectors : Error<
Index: cfe/trunk/test/Sema/asm.c
===
--- cfe/trunk/test/Sema/asm.c
+++ cfe/trunk/test/Sema/asm.c
@@ -28,6 +28,16 @@
   asm ("nop" : : : "204"); // expected-error {{unknown register name '204' in asm}}
   asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}}
   asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}}
+  register void *clobber_conflict asm ("%rcx");
+  register void *no_clobber_conflict asm ("%rax");
+  int a,b,c;
+  asm ("nop" : "=r" (no_clobber_conflict) : "r" (clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+  asm ("nop" : "=r" (clobber_conflict) : "r" (no_clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+  asm ("nop" : "=r" (clobber_conflict) : "r" (clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+  asm ("nop" : "=c" (a) : "r" (no_clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+  asm ("nop" : "=r" (no_clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+  asm ("nop" : "=r" (clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+  asm ("nop" : "=a" (a) : "b" (b) : "%rcx", "%rbx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}} 
 }
 
 // rdar://6094010
Index: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
===
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp
@@ -22,6 +22,7 @@
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/MC/MCParser/MCAsmParser.h"
 using namespace clang;
 using namespace sema;
@@ -137,6 +138,57 @@
   return false;
 }
 
+// Extracting the register name from the Expression value,
+// if there is no register name to extract, returns ""
+static StringRef extractRegisterName(const Expr *Expression,
+ const TargetInfo &Target) {
+  Expression = Expression->IgnoreImpCasts();
+  if (const DeclRefExpr *AsmDeclRef = dyn_cast(Expression)) {
+// Handle cases where the expression is a variable
+const VarDecl *Variable = dyn_cast(AsmDeclRef->getDecl());
+if (Variable && Variable->getStorageClass() == SC_Register) {
+  if (AsmLabelAttr *Attr = Variable->getAttr())
+if (Target.i

r290541 - Fix build error caused by r290539.

2016-12-26 Thread Marina Yatsina via cfe-commits
Author: myatsina
Date: Mon Dec 26 07:16:40 2016
New Revision: 290541

URL: http://llvm.org/viewvc/llvm-project?rev=290541&view=rev
Log:
Fix build error caused by r290539.


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

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=290541&r1=290540&r2=290541&view=diff
==
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Mon Dec 26 07:16:40 2016
@@ -164,9 +164,8 @@ getClobberConflictLocation(MultiExprArg
const TargetInfo &Target, ASTContext &Cont) {
   llvm::StringSet<> InOutVars;
   // Collect all the input and output registers from the extended asm
-  // statement
-  // in order to check for conflicts with the clobber list
-  for (int i = 0; i < Exprs.size(); ++i) {
+  // statement in order to check for conflicts with the clobber list
+  for (unsigned int i = 0; i < Exprs.size(); ++i) {
 StringRef Constraint = Constraints[i]->getString();
 StringRef InOutReg = Target.getConstraintRegister(
 Constraint, extractRegisterName(Exprs[i], Target));


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


r290547 - Wdocumentation fix

2016-12-26 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Mon Dec 26 12:11:49 2016
New Revision: 290547

URL: http://llvm.org/viewvc/llvm-project?rev=290547&view=rev
Log:
Wdocumentation fix

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

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=290547&r1=290546&r2=290547&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Dec 26 12:11:49 2016
@@ -2196,7 +2196,7 @@ ConvertDeducedTemplateArgument(Sema &S,
 Sema::InstantiatingTemplate Inst(S, Template->getLocation(), Template,
  NTTP, Output,
  Template->getSourceRange());
-if (Inst.isInvalid() || 
+if (Inst.isInvalid() ||
 S.SubstType(NTTP->getType(), Args, NTTP->getLocation(),
 NTTP->getDeclName()).isNull())
   return true;
@@ -4572,7 +4572,7 @@ UnresolvedSetIterator Sema::getMostSpeci
 /// Determine whether one partial specialization, P1, is at least as
 /// specialized than another, P2.
 ///
-/// \param PartialSpecializationDecl The kind of P2, which must be a
+/// \tparam PartialSpecializationDecl The kind of P2, which must be a
 /// {Class,Var}TemplatePartialSpecializationDecl.
 /// \param T1 The injected-class-name of P1 (faked for a variable template).
 /// \param T2 The injected-class-name of P2 (faked for a variable template).


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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 82513.
madsravn added a comment.

Updated according to comments.

I have decided to keep the fixit for match1 a FIXME.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,121 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator>
+class basic_string {
+public:
+  basic_string();
+  basic_string(const C *, unsigned int size);
+  int compare(const basic_string &str) const;
+  int compare(const C *) const;
+  int compare(int, int, const basic_string &str) const;
+  bool empty();
+};
+bool operator==(const basic_string &lhs, const basic_string &rhs);
+bool operator!=(const basic_string &lhs, const basic_string &rhs);
+bool operator==(const basic_string &lhs, const char *&rhs);
+typedef basic_string string;
+}
+
+void func(bool b);
+
+std::string comp() {
+  std::string str("a", 1);
+  return str;
+}
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if (str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (!str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (str1.compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == str2) {
+  if (str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 != str2) {
+  if (str1.compare("foo") == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == "foo") {
+  if (0 == str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == str1) {
+  if (0 != str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 != str1) {
+  func(str1.compare(str2));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings;
+  if (str2.empty() || str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2.empty() || str1 != str2) {
+  std::string *str3 = &str1;
+  if (str3->compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  if (str3->compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (*str3 == str2) {
+  if (str2.compare(*str3) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == *str3) {
+  if (comp().compare(str1) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (comp() == str1) {
+  if (str1.compare(comp()) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == comp()) {
+  if (str1.compare(comp())) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  if (str1.compare(str2) == 1) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: 'compare' is not guaranteed to return -1 or 1; check for bigger or smaller than 0 instead
+  if (str1.compare(str2) == -1) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: 'compare' is not guaranteed to return -1 or 1;
+}
+
+void Valid() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+  if (str1 == str2) {
+  }
+  if (str1 != str2) {
+  }
+  if (str1.compare(str2) == str1.compare(str2)) {
+  }
+  if (0 == 0) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(1, 3, str2)) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(str2) < 0) {
+  }
+  if (str1.compare(str2) == 2) {
+  }
+  if (str1.compare(str2) == -3) {
+  }
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
=

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:25
+"operator instead";
+static const StringRef GuaranteeMessage = "'compare' is not guaranteed to "
+  "return -1 or 1; check for bigger or 
"

misc-suspicious-string-compare warns about suspicious `strcmp()`; maybe it 
should handle `string::compare()` too.



Comment at: clang-tidy/misc/StringCompareCheck.h:23
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/misc-string-compare-check.html
+class StringCompareCheck : public ClangTidyCheck {

Change filename to misc-string-compare.html



Comment at: docs/ReleaseNotes.rst:81
+
+  Warns about using ``compare`` to test for string equality or ineqaulity.
+

typo. ineqaulity -> inequality


https://reviews.llvm.org/D27210



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Mads Ravn via Phabricator via cfe-commits
madsravn marked 2 inline comments as done.
madsravn added inline comments.



Comment at: clang-tidy/misc/MiscStringCompareCheck.h:24
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/misc-string-compare-check.html
+class MiscStringCompareCheck : public ClangTidyCheck {
+public:

malcolm.parsons wrote:
> Remove `Misc`.
> 
> Did you use add_new_check.py to add this check?
No, but the files I was looking at had the same naming convention. Maybe 
something has changed in that regards recently? 

I will fix it.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:25
+"operator instead";
+static const StringRef GuaranteeMessage = "'compare' is not guaranteed to "
+  "return -1 or 1; check for bigger or 
"

malcolm.parsons wrote:
> misc-suspicious-string-compare warns about suspicious `strcmp()`; maybe it 
> should handle `string::compare()` too.
Do you suggest that I move this check to misc-suspicious-string-compare? Or 
should we just remove it from here? 



Comment at: docs/clang-tidy/checks/misc-string-compare.rst:10
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns ``-1``, ``0`` or ``1`` depending on the 
lexicographical 
+relationship between the strings compared. If an equality or inequality check

xazax.hun wrote:
> As far as I remember this is not true. The  ``compare`` method can return any 
> integer number, only the sign is defined. It is not guaranteed to return -1 
> or 1 in case of inequality.
This is true. I checked it - it is just some implementations which tend to use 
-1, 0 and 1. However, the specification says negative, 0 and positive. I will 
correct it. Thanks



Comment at: test/clang-tidy/misc-string-compare.cpp:9
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test 
equality of strings; use the string equality operator instead 
[misc-string-compare]

malcolm.parsons wrote:
> Some other test ideas:
> 
> ```
> if (str1.compare("foo")) {}
> 
> return str1.compare(str2) == 0;
> 
> func(str1.compare(str2) != 0);
> 
> if (str2.empty() || str1.compare(str2) != 0) {}
> ```
None of those fit the ast match. 

I think it's fine as it is now. If the matcher will be expanded to check for 
some of those cases, I think more test cases are needed.


https://reviews.llvm.org/D27210



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


Re: [PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Mads Ravn via cfe-commits
Hi,

The last mail was only meant to contain the question about the comment to
misc-suspicious-string-compare check.

Do you reckon I should remove that match from my check? Or should we move
it?

Best regards,
Mads Ravn

On Mon, Dec 26, 2016 at 8:48 PM Mads Ravn via Phabricator <
revi...@reviews.llvm.org> wrote:

> madsravn marked 2 inline comments as done.
> madsravn added inline comments.
>
>
> 
> Comment at: clang-tidy/misc/MiscStringCompareCheck.h:24
> +///
> http://clang.llvm.org/extra/clang-tidy/checks/misc-string-compare-check.html
> +class MiscStringCompareCheck : public ClangTidyCheck {
> +public:
> 
> malcolm.parsons wrote:
> > Remove `Misc`.
> >
> > Did you use add_new_check.py to add this check?
> No, but the files I was looking at had the same naming convention. Maybe
> something has changed in that regards recently?
>
> I will fix it.
>
>
> 
> Comment at: clang-tidy/misc/StringCompareCheck.cpp:25
> +"operator instead";
> +static const StringRef GuaranteeMessage = "'compare' is not guaranteed to
> "
> +  "return -1 or 1; check for
> bigger or "
> 
> malcolm.parsons wrote:
> > misc-suspicious-string-compare warns about suspicious `strcmp()`; maybe
> it should handle `string::compare()` too.
> Do you suggest that I move this check to misc-suspicious-string-compare?
> Or should we just remove it from here?
>
>
> 
> Comment at: docs/clang-tidy/checks/misc-string-compare.rst:10
> +equality or inequality operators. The compare method is intended for
> sorting
> +functions and thus returns ``-1``, ``0`` or ``1`` depending on the
> lexicographical
> +relationship between the strings compared. If an equality or inequality
> check
> 
> xazax.hun wrote:
> > As far as I remember this is not true. The  ``compare`` method can
> return any integer number, only the sign is defined. It is not guaranteed
> to return -1 or 1 in case of inequality.
> This is true. I checked it - it is just some implementations which tend to
> use -1, 0 and 1. However, the specification says negative, 0 and positive.
> I will correct it. Thanks
>
>
> 
> Comment at: test/clang-tidy/misc-string-compare.cpp:9
> +
> +  if(str1.compare(str2)) {}
> +  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test
> equality of strings; use the string equality operator instead
> [misc-string-compare]
> 
> malcolm.parsons wrote:
> > Some other test ideas:
> >
> > ```
> > if (str1.compare("foo")) {}
> >
> > return str1.compare(str2) == 0;
> >
> > func(str1.compare(str2) != 0);
> >
> > if (str2.empty() || str1.compare(str2) != 0) {}
> > ```
> None of those fit the ast match.
>
> I think it's fine as it is now. If the matcher will be expanded to check
> for some of those cases, I think more test cases are needed.
>
>
> https://reviews.llvm.org/D27210
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-26 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang-tidy/obvious/InvalidRangeCheck.cpp:62
+  auto CallsAlgorithm = hasDeclaration(
+  functionDecl(Names.size() > 0 ? hasAnyName(Names) : anything()));
+

Prazek wrote:
> alexfh wrote:
> >  Does this check make sense without the names whitelist? What will is the 
> > use case?
> I would guess most of the functions that would be called like
> foo(v.begin(), v2.end(), ...) would take range as 2 first arguments. at least 
> I never saw code that this would be valid 
> (other case is something like foo(v.begin(), v2.begin(), ...), but I look 
> only for ranges [begin, end())
I wonder if there is any hope that STL implementations might one day carry 
source-level annotations as to what is expected to be a range and what isn't. 
That is, something like
```
template
inline void
sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
__attribute__((__expect_range__(__first, __last)))
```
similar to how we have `__attribute__((__format__))` for printf-style format 
strings, and `__attribute__((__sentinel__))` for null sentinels, and so on. 
Then you could eliminate the heuristics concerned with detecting "what formal 
parameters expect a range" and just work on the heuristics for "what actual 
arguments are a range". (E.g., v.end() and v.begin() are unlikely to make a 
valid range in that order. v.begin() and v2.end() are unlikely to make a valid 
range together. And so on.)



Comment at: docs/ReleaseNotes.rst:120
+  code.
+- New `obvious-invalid-range
+  `_ 
check

Prazek wrote:
> alexfh wrote:
> > The idea of the `obvious` module is interesting, but I'm not sure this 
> > check belongs here. At least, I would like to run it on our code and see 
> > whether it finds anything before calling this "obvious" ;)
> I runned it on LLVM and clang and as expected it didn't find anything (the 
> code would crash or would be dead)
As discussed more thoroughly in https://reviews.llvm.org/D27815 — I continue to 
think that this is a misuse of the word "obvious". Particularly, the phrase 
"while looking for an obvious bug" is an oxymoron: if the bug were obvious, you 
wouldn't need the compiler to help you look for it.
I'll pick the thread back up in D27815 rather than reopen it here.



Comment at: test/clang-tidy/obvious-invalid-range.cpp:35
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}

I would expect this same check to warn on

std::copy(v.begin(), v.begin(), v2.begin());
std::copy(v.end(), v.begin(), v2.begin());

Mind you, I'm not sure *any* of these three warnings will come up in practice 
enough to be useful to anyone; for all the code it takes to implement them, it 
might be higher ROI to invest in a general-purpose 
common-subexpression-detector and/or trying to track "rangeness" through a 
dataflow analysis.



Comment at: test/clang-tidy/obvious-invalid-range.cpp:45
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();

I would expect a warning on this line, in that the result of std::move() is 
unused.


https://reviews.llvm.org/D27806



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


[PATCH] D27815: [clang-tidy] Add obvious module for obvious bugs

2016-12-26 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

PVS-Studio implements tons of checks of this variety. See e.g.
http://www.viva64.com/en/b/0299/#ID0E4KBM
They don't have a catchy name for the category either, but perhaps 
"suspicious-" or "copypaste-" would do.

I agree with Aaron that "thinko-" would be a little inappropriate for a 
user-facing name, and besides, I personally would not call this kind of error a 
"thinko". A thinko stems from a "brain fart", i.e. when you momentarily believe 
something that in hindsight is obviously false; e.g. writing code for a case 
that can't ever be hit in practice, or choosing the wrong algorithm because you 
misunderstood the problem to be solved. The kind of error I'm thinking of in 
//this// case stems from //not thinking at all//, e.g. incomplete copy-pasting, 
or writing `(ch != 'A' || ch != 'a')`, or whatever.


https://reviews.llvm.org/D27815



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a reviewer: malcolm.parsons.
malcolm.parsons added inline comments.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:25
+"operator instead";
+static const StringRef GuaranteeMessage = "'compare' is not guaranteed to "
+  "return -1 or 1; check for bigger or 
"

madsravn wrote:
> malcolm.parsons wrote:
> > misc-suspicious-string-compare warns about suspicious `strcmp()`; maybe it 
> > should handle `string::compare()` too.
> Do you suggest that I move this check to misc-suspicious-string-compare? Or 
> should we just remove it from here? 
Remove from here and add to misc-suspicious-string-compare in another patch.


https://reviews.llvm.org/D27210



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 82518.
madsravn added a comment.

Reviews based on comments. Removed check for suspicious string compare.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,119 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator>
+class basic_string {
+public:
+  basic_string();
+  basic_string(const C *, unsigned int size);
+  int compare(const basic_string &str) const;
+  int compare(const C *) const;
+  int compare(int, int, const basic_string &str) const;
+  bool empty();
+};
+bool operator==(const basic_string &lhs, const basic_string &rhs);
+bool operator!=(const basic_string &lhs, const basic_string &rhs);
+bool operator==(const basic_string &lhs, const char *&rhs);
+typedef basic_string string;
+}
+
+void func(bool b);
+
+std::string comp() {
+  std::string str("a", 1);
+  return str;
+}
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if (str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (!str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (str1.compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == str2) {
+  if (str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 != str2) {
+  if (str1.compare("foo") == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == "foo") {
+  if (0 == str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == str1) {
+  if (0 != str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 != str1) {
+  func(str1.compare(str2));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings;
+  if (str2.empty() || str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2.empty() || str1 != str2) {
+  std::string *str3 = &str1;
+  if (str3->compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  if (str3->compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (*str3 == str2) {
+  if (str2.compare(*str3) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == *str3) {
+  if (comp().compare(str1) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (comp() == str1) {
+  if (str1.compare(comp()) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == comp()) {
+  if (str1.compare(comp())) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+}
+
+void Valid() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+  if (str1 == str2) {
+  }
+  if (str1 != str2) {
+  }
+  if (str1.compare(str2) == str1.compare(str2)) {
+  }
+  if (0 == 0) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(1, 3, str2)) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(str2) < 0) {
+  }
+  if (str1.compare(str2) == 2) {
+  }
+  if (str1.compare(str2) == -3) {
+  }
+  if (str1.compare(str2) == 1) {
+  }
+  if (str1.compare(str2) == -1) {
+  }
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,54 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:25
+"operator instead";
+static const StringRef GuaranteeMessage = "'compare' is not guaranteed to "
+  "return -1 or 1; check for bigger or 
"

This message is not used.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:37
+  hasArgument(0, expr().bind("str2")), argumentCountIs(1),
+  callee(memberExpr(has(implicitCastExpr(anyOf(
+  
has(callExpr(has(implicitCastExpr(has(declRefExpr().bind("str1")),

Do you really care what the callee expression is? 
Use `isArrow()` on the `MemberExpr` to check if it's a pointer.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:67
+
+if (const auto *zero = Result.Nodes.getNodeAs("zero")) {
+  const auto *str1 = Result.Nodes.getNodeAs("str1");

All variables should start with a capital letter.


https://reviews.llvm.org/D27210



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


r290552 - Update comment to match dr1770.

2016-12-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Dec 26 16:28:29 2016
New Revision: 290552

URL: http://llvm.org/viewvc/llvm-project?rev=290552&view=rev
Log:
Update comment to match dr1770.

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

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=290552&r1=290551&r2=290552&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Dec 26 16:28:29 2016
@@ -5041,14 +5041,13 @@ ExprResult Sema::CheckTemplateArgument(N
 
   if (CTAK == CTAK_Deduced &&
   !Context.hasSameUnqualifiedType(ParamType, Arg->getType())) {
-// C++ [temp.deduct.type]p17:
-//   If, in the declaration of a function template with a non-type
-//   template-parameter, the non-type template-parameter is used
-//   in an expression in the function parameter-list and, if the
-//   corresponding template-argument is deduced, the
-//   template-argument type shall match the type of the
-//   template-parameter exactly, except that a template-argument
-//   deduced from an array bound may be of any integral type.
+// C++ [temp.deduct.type]p17: (DR1770)
+//   If P has a form that contains , and if the type of i differs from
+//   the type of the corresponding template parameter of the template named
+//   by the enclosing simple-template-id, deduction fails.
+//
+// Note that CTAK will be CTAK_DeducedFromArrayBound if the form was [i]
+// rather than .
 Diag(StartLoc, diag::err_deduced_non_type_template_arg_type_mismatch)
   << Arg->getType().getUnqualifiedType()
   << ParamType.getUnqualifiedType();


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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Mads Ravn via Phabricator via cfe-commits
madsravn added inline comments.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:37
+  hasArgument(0, expr().bind("str2")), argumentCountIs(1),
+  callee(memberExpr(has(implicitCastExpr(anyOf(
+  
has(callExpr(has(implicitCastExpr(has(declRefExpr().bind("str1")),

malcolm.parsons wrote:
> Do you really care what the callee expression is? 
> Use `isArrow()` on the `MemberExpr` to check if it's a pointer.
How else would I get str1? Using the below snippet, I only get str1.compare and 
str1->compare instead of str1. 
Given a MemberExpr (str1.compare) is there an easy way to extract str1? 

```
const auto StrCompare = cxxMemberCallExpr(
  callee(cxxMethodDecl(hasName("compare"),
   ofClass(classTemplateSpecializationDecl(
   hasName("::std::basic_string"),
  hasArgument(0, expr().bind("str2")), argumentCountIs(1),
  callee(memberExpr().bind("str1")))
```


https://reviews.llvm.org/D27210



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:37
+  hasArgument(0, expr().bind("str2")), argumentCountIs(1),
+  callee(memberExpr(has(implicitCastExpr(anyOf(
+  
has(callExpr(has(implicitCastExpr(has(declRefExpr().bind("str1")),

madsravn wrote:
> malcolm.parsons wrote:
> > Do you really care what the callee expression is? 
> > Use `isArrow()` on the `MemberExpr` to check if it's a pointer.
> How else would I get str1? Using the below snippet, I only get str1.compare 
> and str1->compare instead of str1. 
> Given a MemberExpr (str1.compare) is there an easy way to extract str1? 
> 
> ```
> const auto StrCompare = cxxMemberCallExpr(
>   callee(cxxMethodDecl(hasName("compare"),
>ofClass(classTemplateSpecializationDecl(
>hasName("::std::basic_string"),
>   hasArgument(0, expr().bind("str2")), argumentCountIs(1),
>   callee(memberExpr().bind("str1")))
> ```
`getBase()`


https://reviews.llvm.org/D27210



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-26 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 82521.
madsravn added a comment.

Changes based on comments. 
Shortened the ast matcher.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,119 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator>
+class basic_string {
+public:
+  basic_string();
+  basic_string(const C *, unsigned int size);
+  int compare(const basic_string &str) const;
+  int compare(const C *) const;
+  int compare(int, int, const basic_string &str) const;
+  bool empty();
+};
+bool operator==(const basic_string &lhs, const basic_string &rhs);
+bool operator!=(const basic_string &lhs, const basic_string &rhs);
+bool operator==(const basic_string &lhs, const char *&rhs);
+typedef basic_string string;
+}
+
+void func(bool b);
+
+std::string comp() {
+  std::string str("a", 1);
+  return str;
+}
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if (str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (!str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (str1.compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == str2) {
+  if (str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 != str2) {
+  if (str1.compare("foo") == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == "foo") {
+  if (0 == str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == str1) {
+  if (0 != str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 != str1) {
+  func(str1.compare(str2));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings;
+  if (str2.empty() || str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2.empty() || str1 != str2) {
+  std::string *str3 = &str1;
+  if (str3->compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  if (str3->compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (*str3 == str2) {
+  if (str2.compare(*str3) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == *str3) {
+  if (comp().compare(str1) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (comp() == str1) {
+  if (str1.compare(comp()) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == comp()) {
+  if (str1.compare(comp())) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+}
+
+void Valid() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+  if (str1 == str2) {
+  }
+  if (str1 != str2) {
+  }
+  if (str1.compare(str2) == str1.compare(str2)) {
+  }
+  if (0 == 0) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(1, 3, str2)) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(str2) < 0) {
+  }
+  if (str1.compare(str2) == 2) {
+  }
+  if (str1.compare(str2) == -3) {
+  }
+  if (str1.compare(str2) == 1) {
+  }
+  if (str1.compare(str2) == -1) {
+  }
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,54 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds

r290558 - [PH] Teach the new PM code path to support -disable-llvm-passes.

2016-12-26 Thread Chandler Carruth via cfe-commits
Author: chandlerc
Date: Mon Dec 26 18:13:09 2016
New Revision: 290558

URL: http://llvm.org/viewvc/llvm-project?rev=290558&view=rev
Log:
[PH] Teach the new PM code path to support -disable-llvm-passes.

This is kind of funny because I specifically did work to make this easy
and then it didn't actually get implemented.

I've also ported a set of tests that rely on this functionality to run
with the new PM as well as the old PM so that we don't mess this up in
the future.

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/CodeGen/inline.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=290558&r1=290557&r2=290558&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Dec 26 18:13:09 2016
@@ -780,17 +780,20 @@ void EmitAssemblyHelper::EmitAssemblyWit
   PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
 
   ModulePassManager MPM;
-  if (CodeGenOpts.OptimizationLevel == 0) {
-// Build a minimal pipeline based on the semantics required by Clang, which
-// is just that always inlining occurs.
-MPM.addPass(AlwaysInlinerPass());
-  } else {
-// Otherwise, use the default pass pipeline. We also have to map our
-// optimization levels into one of the distinct levels used to configure
-// the pipeline.
-PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
 
-MPM = PB.buildPerModuleDefaultPipeline(Level);
+  if (!CodeGenOpts.DisableLLVMPasses) {
+if (CodeGenOpts.OptimizationLevel == 0) {
+  // Build a minimal pipeline based on the semantics required by Clang,
+  // which is just that always inlining occurs.
+  MPM.addPass(AlwaysInlinerPass());
+} else {
+  // Otherwise, use the default pass pipeline. We also have to map our
+  // optimization levels into one of the distinct levels used to configure
+  // the pipeline.
+  PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
+
+  MPM = PB.buildPerModuleDefaultPipeline(Level);
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We

Modified: cfe/trunk/test/CodeGen/inline.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/inline.c?rev=290558&r1=290557&r2=290558&view=diff
==
--- cfe/trunk/test/CodeGen/inline.c (original)
+++ cfe/trunk/test/CodeGen/inline.c Mon Dec 26 18:13:09 2016
@@ -1,5 +1,6 @@
 // RUN: echo "GNU89 tests:"
 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O1 -disable-llvm-passes 
-emit-llvm -o - -std=gnu89 | FileCheck %s --check-prefix=CHECK1
+// RUN: %clang_cc1 %s -triple i386-unknown-unknown 
-fexperimental-new-pass-manager -O1 -disable-llvm-passes -emit-llvm -o - 
-std=gnu89 | FileCheck %s --check-prefix=CHECK1
 // CHECK1-LABEL: define i32 @foo()
 // CHECK1-LABEL: define i32 @bar()
 // CHECK1-LABEL: define void @unreferenced1()
@@ -22,6 +23,7 @@
 
 // RUN: echo "C99 tests:"
 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O1 -disable-llvm-passes 
-emit-llvm -o - -std=gnu99 | FileCheck %s --check-prefix=CHECK2
+// RUN: %clang_cc1 %s -triple i386-unknown-unknown 
-fexperimental-new-pass-manager -O1 -disable-llvm-passes -emit-llvm -o - 
-std=gnu99 | FileCheck %s --check-prefix=CHECK2
 // CHECK2-LABEL: define i32 @ei()
 // CHECK2-LABEL: define i32 @bar()
 // CHECK2-NOT: unreferenced1
@@ -44,6 +46,7 @@
 
 // RUN: echo "C++ tests:"
 // RUN: %clang_cc1 -x c++ %s -triple i386-unknown-unknown -O1 
-disable-llvm-passes -emit-llvm -o - -std=c++98 | FileCheck %s 
--check-prefix=CHECK3
+// RUN: %clang_cc1 -x c++ %s -triple i386-unknown-unknown 
-fexperimental-new-pass-manager -O1 -disable-llvm-passes -emit-llvm -o - 
-std=c++98 | FileCheck %s --check-prefix=CHECK3
 // CHECK3-LABEL: define i32 @_Z3barv()
 // CHECK3-LABEL: define linkonce_odr i32 @_Z3foov()
 // CHECK3-NOT: unreferenced
@@ -54,6 +57,7 @@
 
 // RUN: echo "MS C Mode tests:"
 // RUN: %clang_cc1 %s -triple i386-pc-win32 -O1 -disable-llvm-passes 
-emit-llvm -o - -std=c99 | FileCheck %s --check-prefix=CHECK4
+// RUN: %clang_cc1 %s -triple i386-pc-win32 -fexperimental-new-pass-manager 
-O1 -disable-llvm-passes -emit-llvm -o - -std=c99 | FileCheck %s 
--check-prefix=CHECK4
 // CHECK4-NOT: define weak_odr void @_Exit(
 // CHECK4-LABEL: define weak_odr i32 @ei()
 // CHECK4-LABEL: define i32 @bar()


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


r290560 - [PM] The new pass manager requires a registered target for these, and

2016-12-26 Thread Chandler Carruth via cfe-commits
Author: chandlerc
Date: Mon Dec 26 18:31:34 2016
New Revision: 290560

URL: http://llvm.org/viewvc/llvm-project?rev=290560&view=rev
Log:
[PM] The new pass manager requires a registered target for these, and
given that they hard code specific triples that seems reasonable so add
the REQUIRES.

Modified:
cfe/trunk/test/CodeGen/inline.c

Modified: cfe/trunk/test/CodeGen/inline.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/inline.c?rev=290560&r1=290559&r2=290560&view=diff
==
--- cfe/trunk/test/CodeGen/inline.c (original)
+++ cfe/trunk/test/CodeGen/inline.c Mon Dec 26 18:31:34 2016
@@ -1,3 +1,5 @@
+// REQUIRES: x86-registered-target
+//
 // RUN: echo "GNU89 tests:"
 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O1 -disable-llvm-passes 
-emit-llvm -o - -std=gnu89 | FileCheck %s --check-prefix=CHECK1
 // RUN: %clang_cc1 %s -triple i386-unknown-unknown 
-fexperimental-new-pass-manager -O1 -disable-llvm-passes -emit-llvm -o - 
-std=gnu89 | FileCheck %s --check-prefix=CHECK1


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


r290561 - [DOXYGEN] Improved doxygen comments for x86 intrinsics.

2016-12-26 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Mon Dec 26 18:49:38 2016
New Revision: 290561

URL: http://llvm.org/viewvc/llvm-project?rev=290561&view=rev
Log:
[DOXYGEN] Improved doxygen comments for x86 intrinsics.

Improved doxygen comments for the following intrinsics headers:  
__wmmintrin_pclmul.h, bmiintrin.h, emmintrin.h, f16cintrin.h, immintrin.h, 
mmintrin.h, pmmintrin.h, tmmintrin.h

Added \n commands to insert a line breaks where necessary, since one long line 
of documentation is nearly unreadable.
Formatted comments to fit into 80 chars.
In some cases added \a command in front of the parameter names to display them 
in italics.




Modified:
cfe/trunk/lib/Headers/__wmmintrin_pclmul.h
cfe/trunk/lib/Headers/bmiintrin.h
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/lib/Headers/f16cintrin.h
cfe/trunk/lib/Headers/immintrin.h
cfe/trunk/lib/Headers/mmintrin.h
cfe/trunk/lib/Headers/pmmintrin.h
cfe/trunk/lib/Headers/tmmintrin.h

Modified: cfe/trunk/lib/Headers/__wmmintrin_pclmul.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__wmmintrin_pclmul.h?rev=290561&r1=290560&r2=290561&view=diff
==
--- cfe/trunk/lib/Headers/__wmmintrin_pclmul.h (original)
+++ cfe/trunk/lib/Headers/__wmmintrin_pclmul.h Mon Dec 26 18:49:38 2016
@@ -42,12 +42,11 @@
 ///A 128-bit vector of [2 x i64] containing one of the source operands.
 /// \param __I
 ///An immediate value specifying which 64-bit values to select from the
-///operands.
-///Bit 0 is used to select a value from operand \a __X, and bit 4 is used
-///to select a value from operand \a __Y:
-///Bit[0]=0 indicates that bits[63:0] of operand \a __X are used.
-///Bit[0]=1 indicates that bits[127:64] of operand \a __X are used.
-///Bit[4]=0 indicates that bits[63:0] of operand \a __Y are used.
+///operands. Bit 0 is used to select a value from operand \a __X, and bit
+///4 is used to select a value from operand \a __Y: \n
+///Bit[0]=0 indicates that bits[63:0] of operand \a __X are used. \n
+///Bit[0]=1 indicates that bits[127:64] of operand \a __X are used. \n
+///Bit[4]=0 indicates that bits[63:0] of operand \a __Y are used. \n
 ///Bit[4]=1 indicates that bits[127:64] of operand \a __Y are used.
 /// \returns The 128-bit integer vector containing the result of the carry-less
 ///multiplication of the selected 64-bit values.

Modified: cfe/trunk/lib/Headers/bmiintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/bmiintrin.h?rev=290561&r1=290560&r2=290561&view=diff
==
--- cfe/trunk/lib/Headers/bmiintrin.h (original)
+++ cfe/trunk/lib/Headers/bmiintrin.h Mon Dec 26 18:49:38 2016
@@ -295,8 +295,8 @@ __tzcnt_u32(unsigned int __X)
 ///
 /// \param __X
 ///An unsigned 32-bit integer whose trailing zeros are to be counted.
-/// \returns An 32-bit integer containing the number of trailing zero
-///bits in the operand.
+/// \returns An 32-bit integer containing the number of trailing zero bits in
+///the operand.
 static __inline__ int __RELAXED_FN_ATTRS
 _mm_tzcnt_32(unsigned int __X)
 {
@@ -532,8 +532,8 @@ __tzcnt_u64(unsigned long long __X)
 ///
 /// \param __X
 ///An unsigned 64-bit integer whose trailing zeros are to be counted.
-/// \returns An 64-bit integer containing the number of trailing zero
-///bits in the operand.
+/// \returns An 64-bit integer containing the number of trailing zero bits in
+///the operand.
 static __inline__ long long __RELAXED_FN_ATTRS
 _mm_tzcnt_64(unsigned long long __X)
 {

Modified: cfe/trunk/lib/Headers/emmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/emmintrin.h?rev=290561&r1=290560&r2=290561&view=diff
==
--- cfe/trunk/lib/Headers/emmintrin.h (original)
+++ cfe/trunk/lib/Headers/emmintrin.h Mon Dec 26 18:49:38 2016
@@ -551,7 +551,8 @@ _mm_cmpord_pd(__m128d __a, __m128d __b)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VCMPUNORDPD / CMPUNORDPD  
instruction.
+/// This intrinsic corresponds to the  VCMPUNORDPD / CMPUNORDPD 
+///   instruction.
 ///
 /// \param __a
 ///A 128-bit vector of [2 x double].
@@ -734,10 +735,10 @@ _mm_cmple_sd(__m128d __a, __m128d __b)
   return (__m128d)__builtin_ia32_cmplesd((__v2df)__a, (__v2df)__b);
 }
 
-/// \brief Compares the lower double-precision floating-point values in each
-///of the two 128-bit floating-point vectors of [2 x double] to determine
-///if the value in the first parameter is greater than the corresponding
-///value in the second parameter. The comparison yields 0h for false,
+/// \brief Compares the lower double-precision floating-point values in each of
+///the two 128-bit floating-point vectors of [2 x double] to determine if
+///the value in the first parameter is g

r290567 - Check and build conversion sequences for non-type template arguments in

2016-12-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Dec 26 20:02:09 2016
New Revision: 290567

URL: http://llvm.org/viewvc/llvm-project?rev=290567&view=rev
Log:
Check and build conversion sequences for non-type template arguments in
dependent contexts when processing the template in C++11 and C++14, just like
we do in C++98 and C++1z. This allows us to diagnose invalid templates earlier.

Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=290567&r1=290566&r2=290567&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Dec 26 20:02:09 2016
@@ -5382,7 +5382,7 @@ ExprResult Sema::CheckConvertedConstantE
 
   APValue V;
   auto R = ::CheckConvertedConstantExpression(*this, From, T, V, CCE, true);
-  if (!R.isInvalid())
+  if (!R.isInvalid() && !R.get()->isValueDependent())
 Value = V.getInt();
   return R;
 }

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=290567&r1=290566&r2=290567&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Dec 26 20:02:09 2016
@@ -5076,8 +5076,8 @@ ExprResult Sema::CheckTemplateArgument(N
 // For a value-dependent argument, CheckConvertedConstantExpression is
 // permitted (and expected) to be unable to determine a value.
 if (ArgResult.get()->isValueDependent()) {
-  Converted = TemplateArgument(Arg);
-  return Arg;
+  Converted = TemplateArgument(ArgResult.get());
+  return ArgResult;
 }
 
 QualType CanonParamType = Context.getCanonicalType(ParamType);
@@ -5184,14 +5184,6 @@ ExprResult Sema::CheckTemplateArgument(N
 //  conversions (4.7) are applied.
 
 if (getLangOpts().CPlusPlus11) {
-  // We can't check arbitrary value-dependent arguments.
-  // FIXME: If there's no viable conversion to the template parameter type,
-  // we should be able to diagnose that prior to instantiation.
-  if (Arg->isValueDependent()) {
-Converted = TemplateArgument(Arg);
-return Arg;
-  }
-
   // C++ [temp.arg.nontype]p1:
   //   A template-argument for a non-type, non-template template-parameter
   //   shall be one of:
@@ -5206,6 +5198,12 @@ ExprResult Sema::CheckTemplateArgument(N
   if (ArgResult.isInvalid())
 return ExprError();
 
+  // We can't check arbitrary value-dependent arguments.
+  if (ArgResult.get()->isValueDependent()) {
+Converted = TemplateArgument(ArgResult.get());
+return ArgResult;
+  }
+
   // Widen the argument value to sizeof(parameter type). This is almost
   // always a no-op, except when the parameter type is bool. In
   // that case, this may extend the argument from 1 bit to 8 bits.

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp?rev=290567&r1=290566&r2=290567&view=diff
==
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp Mon Dec 26 20:02:09 
2016
@@ -27,3 +27,12 @@ namespace CanonicalNullptr {
 namespace Auto {
   template struct A { };  // expected-error {{until C++1z}}
 }
+
+namespace check_conversion_early {
+  struct X {};
+  template struct A {};
+  template struct A {}; // expected-error {{not implicitly 
convertible}}
+
+  struct Y { constexpr operator int() const { return 0; } };
+  template struct A {}; // expected-error {{depends on a template 
parameter of the partial specialization}}
+}

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp?rev=290567&r1=290566&r2=290567&view=diff
==
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp Mon Dec 26 20:02:09 
2016
@@ -137,7 +137,7 @@ namespace DeduceDifferentType {
   struct Z { constexpr operator Y&() { return y; } } z;
   constexpr Y::operator Z&() { return z; }
   template struct D {};
-  template int d(D); // expected-note {{does not have the same type}}
+  template int d(D); // expected-note {{couldn't infer template 
argument 'z'}}
   int d_imp = d(D()); // expected-error {{no matching function}}
   int d_exp = d(D());
 }


___

Re: r290533 - Driver: warn on -fPIC/-fpic/-fPIE/-fpie on Windows

2016-12-26 Thread Vitaly Buka via cfe-commits
This fails here
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/3537/steps/run%20tests/logs/stdio

On Sun, Dec 25, 2016 at 7:45 PM Saleem Abdulrasool via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: compnerd
> Date: Sun Dec 25 21:35:24 2016
> New Revision: 290533
>
> URL: http://llvm.org/viewvc/llvm-project?rev=290533&view=rev
> Log:
> Driver: warn on -fPIC/-fpic/-fPIE/-fpie on Windows
>
> Use of these flags would result in the use of ELF-style PIE/PIC code
> which is incorrect on Windows.  Windows is inherently PIC by means of
> the DLL slide that occurs at load.  This also mirrors the behaviour on
> GCC for MinGW.  Currently, the Windows x86_64 forces the relocation
> model to PIC (Level 2).  This is unchanged for now, though we should
> remove any assumptions on that and change it to a static relocation
> model.
>
> Added:
> cfe/trunk/test/Driver/windows-pic.cpp
> Modified:
> cfe/trunk/lib/Driver/Tools.cpp
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=290533&r1=290532&r2=290533&view=diff
>
> ==
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Sun Dec 25 21:35:24 2016
> @@ -3859,6 +3859,17 @@ ParsePICArgs(const ToolChain &ToolChain,
>  options::OPT_fpic,
> options::OPT_fno_pic,
>  options::OPT_fPIE,
> options::OPT_fno_PIE,
>  options::OPT_fpie,
> options::OPT_fno_pie);
> +  if (Triple.isOSWindows() && LastPICArg &&
> +  LastPICArg ==
> +  Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
> +  options::OPT_fPIE, options::OPT_fpie)) {
> +ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
> +<< LastPICArg->getSpelling() << Triple.str();
> +if (Triple.getArch() == llvm::Triple::x86_64)
> +  return std::make_tuple(llvm::Reloc::PIC_, 2U, false);
> +return std::make_tuple(llvm::Reloc::Static, 0U, false);
> +  }
> +
>// Check whether the tool chain trumps the PIC-ness decision. If the
> PIC-ness
>// is forced, then neither PIC nor PIE flags will have no effect.
>if (!ToolChain.isPICDefaultForced()) {
>
> Added: cfe/trunk/test/Driver/windows-pic.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/windows-pic.cpp?rev=290533&view=auto
>
> ==
> --- cfe/trunk/test/Driver/windows-pic.cpp (added)
> +++ cfe/trunk/test/Driver/windows-pic.cpp Sun Dec 25 21:35:24 2016
> @@ -0,0 +1,59 @@
> +// RUN: %clang -### -target i686-windows -fPIC %s 2>&1 | FileCheck
> -check-prefix CHECK-PIC-ERROR %s
> +// RUN: %clang -### -target i686-windows -fpic %s 2>&1 | FileCheck
> -check-prefix CHECK-pic-ERROR %s
> +// RUN: %clang -### -target i686-windows -fPIE %s 2>&1 | FileCheck
> -check-prefix CHECK-PIE-ERROR %s
> +// RUN: %clang -### -target i686-windows -fpie %s 2>&1 | FileCheck
> -check-prefix CHECK-pie-ERROR %s
> +// RUN: %clang -### -target i686-windows -fPIC -fno-pic %s
> +// RUN: %clang -### -target i686-windows -Fpic -fno-pic %s
> +// RUN: %clang -### -target i686-windows -fPIE -fno-pie %s
> +// RUN: %clang -### -target i686-windows -fpie -fno-pie %s
> +
> +// RUN: %clang -### -target i686-windows-itanium -fPIC %s 2>&1 |
> FileCheck -check-prefix CHECK-PIC-ERROR %s
> +// RUN: %clang -### -target i686-windows-itanium -fpic %s 2>&1 |
> FileCheck -check-prefix CHECK-pic-ERROR %s
> +// RUN: %clang -### -target i686-windows-itanium -fPIE %s 2>&1 |
> FileCheck -check-prefix CHECK-PIE-ERROR %s
> +// RUN: %clang -### -target i686-windows-itanium -fpie %s 2>&1 |
> FileCheck -check-prefix CHECK-pie-ERROR %s
> +// RUN: %clang -### -target i686-windows-itanium -fPIC -fno-pic %s
> +// RUN: %clang -### -target i686-windows-itanium -Fpic -fno-pic %s
> +// RUN: %clang -### -target i686-windows-itanium -fPIE -fno-pie %s
> +// RUN: %clang -### -target i686-windows-itanium -fpie -fno-pie %s
> +
> +// RUN: %clang -### -target i686-windows-gnu -fPIC %s 2>&1 | FileCheck
> -check-prefix CHECK-PIC-ERROR %s
> +// RUN: %clang -### -target i686-windows-gnu -fpic %s 2>&1 | FileCheck
> -check-prefix CHECK-pic-ERROR %s
> +// RUN: %clang -### -target i686-windows-gnu -fPIE %s 2>&1 | FileCheck
> -check-prefix CHECK-PIE-ERROR %s
> +// RUN: %clang -### -target i686-windows-gnu -fpie %s 2>&1 | FileCheck
> -check-prefix CHECK-pie-ERROR %s
> +// RUN: %clang -### -target i686-windows-gnu -fPIC -fno-pic %s
> +// RUN: %clang -### -target i686-windows-gnu -Fpic -fno-pic %s
> +// RUN: %clang -### -target i686-windows-gnu -fPIE -fno-pie %s
> +// RUN: %clang -### -target i686-windows-gnu -fpie -fno-pie %s
> +
> +// RUN: %clang -### -target x86_64-windows -fPIC %s 2>&1 | FileCheck
> -check-prefix CHECK-PIC-ERROR %s
> +// RUN: %clang -### -target x86_64-windows -fp

r290569 - Driver: switch Windows to static RelocModel

2016-12-26 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Mon Dec 26 20:20:35 2016
New Revision: 290569

URL: http://llvm.org/viewvc/llvm-project?rev=290569&view=rev
Log:
Driver: switch Windows to static RelocModel

Windows uses PE/COFF which is inherently position independent.  The use
of the PIC model is unnecessary.  In fact, we would generate invalid
code using the ELF PIC model when PIC was enabled previously.  Now that
we no longer accept -fPIC and -fpoc, this switches the internal
representation to the static model to permit us to make PIC modules
invalid when targeting Windows.  This should not change the code
generation, only the internal state management.

Modified:
cfe/trunk/lib/Driver/MSVCToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/test/Driver/pic.c

Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=290569&r1=290568&r2=290569&view=diff
==
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Mon Dec 26 20:20:35 2016
@@ -82,18 +82,6 @@ bool MSVCToolChain::IsUnwindTablesDefaul
   return getArch() == llvm::Triple::x86_64;
 }
 
-bool MSVCToolChain::isPICDefault() const {
-  return getArch() == llvm::Triple::x86_64;
-}
-
-bool MSVCToolChain::isPIEDefault() const {
-  return false;
-}
-
-bool MSVCToolChain::isPICDefaultForced() const {
-  return getArch() == llvm::Triple::x86_64;
-}
-
 #ifdef USE_WIN32
 static bool readFullStringValue(HKEY hkey, const char *valueName,
 std::string &value) {

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=290569&r1=290568&r2=290569&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Dec 26 20:20:35 2016
@@ -2880,22 +2880,13 @@ bool Generic_GCC::IsUnwindTablesDefault(
 
 bool Generic_GCC::isPICDefault() const {
   switch (getArch()) {
-  case llvm::Triple::x86_64:
-return getTriple().isOSWindows();
+  default: return false;
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
 return !getTriple().isOSBinFormatMachO() && !getTriple().isMacOSX();
-  default:
-return false;
   }
 }
 
-bool Generic_GCC::isPIEDefault() const { return false; }
-
-bool Generic_GCC::isPICDefaultForced() const {
-  return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows();
-}
-
 bool Generic_GCC::IsIntegratedAssemblerDefault() const {
   switch (getTriple().getArch()) {
   case llvm::Triple::x86:

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=290569&r1=290568&r2=290569&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Mon Dec 26 20:20:35 2016
@@ -232,8 +232,8 @@ public:
 
   bool IsUnwindTablesDefault() const override;
   bool isPICDefault() const override;
-  bool isPIEDefault() const override;
-  bool isPICDefaultForced() const override;
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
   bool IsIntegratedAssemblerDefault() const override;
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
@@ -1136,9 +1136,9 @@ public:
 
   bool IsIntegratedAssemblerDefault() const override;
   bool IsUnwindTablesDefault() const override;
-  bool isPICDefault() const override;
-  bool isPIEDefault() const override;
-  bool isPICDefaultForced() const override;
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
 
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,

Modified: cfe/trunk/test/Driver/pic.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/pic.c?rev=290569&r1=290568&r2=290569&view=diff
==
--- cfe/trunk/test/Driver/pic.c (original)
+++ cfe/trunk/test/Driver/pic.c Mon Dec 26 20:20:35 2016
@@ -255,9 +255,4 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
 // RUN: %clang -c %s -target arm64-linux-android -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
-//
-// On Windows-X64 PIC is enabled by default
-// RUN: %clang -c %s -target x86_64-pc-windows-msvc18.0.0 -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
-// RUN: %clang -c %s -target x86_64-pc-windows-gnu -### 2>&1 \
-// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
+


___
cfe-commits mailing list
cfe-commits@lists

[PATCH] D15075: No error for conflict between inputs\outputs and clobber list

2016-12-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

These patches break asan tests: 
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/528/steps/check-asan%20in%20gcc%20build/logs/stdio


Repository:
  rL LLVM

https://reviews.llvm.org/D15075



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


Re: r290533 - Driver: warn on -fPIC/-fpic/-fPIE/-fpie on Windows

2016-12-26 Thread Saleem Abdulrasool via cfe-commits
On Mon, Dec 26, 2016 at 6:22 PM, Vitaly Buka  wrote:

> This fails here http://lab.llvm.org:8011/builders/sanitizer-windows/
> builds/3537/steps/run%20tests/logs/stdio
>

Thanks for letting me know.  Should be addressed in SVN r290571.


>
> On Sun, Dec 25, 2016 at 7:45 PM Saleem Abdulrasool via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: compnerd
>> Date: Sun Dec 25 21:35:24 2016
>> New Revision: 290533
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=290533&view=rev
>> Log:
>> Driver: warn on -fPIC/-fpic/-fPIE/-fpie on Windows
>>
>> Use of these flags would result in the use of ELF-style PIE/PIC code
>> which is incorrect on Windows.  Windows is inherently PIC by means of
>> the DLL slide that occurs at load.  This also mirrors the behaviour on
>> GCC for MinGW.  Currently, the Windows x86_64 forces the relocation
>> model to PIC (Level 2).  This is unchanged for now, though we should
>> remove any assumptions on that and change it to a static relocation
>> model.
>>
>> Added:
>> cfe/trunk/test/Driver/windows-pic.cpp
>> Modified:
>> cfe/trunk/lib/Driver/Tools.cpp
>>
>> Modified: cfe/trunk/lib/Driver/Tools.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/
>> Tools.cpp?rev=290533&r1=290532&r2=290533&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Driver/Tools.cpp (original)
>> +++ cfe/trunk/lib/Driver/Tools.cpp Sun Dec 25 21:35:24 2016
>> @@ -3859,6 +3859,17 @@ ParsePICArgs(const ToolChain &ToolChain,
>>  options::OPT_fpic,
>> options::OPT_fno_pic,
>>  options::OPT_fPIE,
>> options::OPT_fno_PIE,
>>  options::OPT_fpie,
>> options::OPT_fno_pie);
>> +  if (Triple.isOSWindows() && LastPICArg &&
>> +  LastPICArg ==
>> +  Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
>> +  options::OPT_fPIE, options::OPT_fpie)) {
>> +ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
>> +<< LastPICArg->getSpelling() << Triple.str();
>> +if (Triple.getArch() == llvm::Triple::x86_64)
>> +  return std::make_tuple(llvm::Reloc::PIC_, 2U, false);
>> +return std::make_tuple(llvm::Reloc::Static, 0U, false);
>> +  }
>> +
>>// Check whether the tool chain trumps the PIC-ness decision. If the
>> PIC-ness
>>// is forced, then neither PIC nor PIE flags will have no effect.
>>if (!ToolChain.isPICDefaultForced()) {
>>
>> Added: cfe/trunk/test/Driver/windows-pic.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/
>> windows-pic.cpp?rev=290533&view=auto
>> 
>> ==
>> --- cfe/trunk/test/Driver/windows-pic.cpp (added)
>> +++ cfe/trunk/test/Driver/windows-pic.cpp Sun Dec 25 21:35:24 2016
>> @@ -0,0 +1,59 @@
>> +// RUN: %clang -### -target i686-windows -fPIC %s 2>&1 | FileCheck
>> -check-prefix CHECK-PIC-ERROR %s
>> +// RUN: %clang -### -target i686-windows -fpic %s 2>&1 | FileCheck
>> -check-prefix CHECK-pic-ERROR %s
>> +// RUN: %clang -### -target i686-windows -fPIE %s 2>&1 | FileCheck
>> -check-prefix CHECK-PIE-ERROR %s
>> +// RUN: %clang -### -target i686-windows -fpie %s 2>&1 | FileCheck
>> -check-prefix CHECK-pie-ERROR %s
>> +// RUN: %clang -### -target i686-windows -fPIC -fno-pic %s
>> +// RUN: %clang -### -target i686-windows -Fpic -fno-pic %s
>> +// RUN: %clang -### -target i686-windows -fPIE -fno-pie %s
>> +// RUN: %clang -### -target i686-windows -fpie -fno-pie %s
>> +
>> +// RUN: %clang -### -target i686-windows-itanium -fPIC %s 2>&1 |
>> FileCheck -check-prefix CHECK-PIC-ERROR %s
>> +// RUN: %clang -### -target i686-windows-itanium -fpic %s 2>&1 |
>> FileCheck -check-prefix CHECK-pic-ERROR %s
>> +// RUN: %clang -### -target i686-windows-itanium -fPIE %s 2>&1 |
>> FileCheck -check-prefix CHECK-PIE-ERROR %s
>> +// RUN: %clang -### -target i686-windows-itanium -fpie %s 2>&1 |
>> FileCheck -check-prefix CHECK-pie-ERROR %s
>> +// RUN: %clang -### -target i686-windows-itanium -fPIC -fno-pic %s
>> +// RUN: %clang -### -target i686-windows-itanium -Fpic -fno-pic %s
>> +// RUN: %clang -### -target i686-windows-itanium -fPIE -fno-pie %s
>> +// RUN: %clang -### -target i686-windows-itanium -fpie -fno-pie %s
>> +
>> +// RUN: %clang -### -target i686-windows-gnu -fPIC %s 2>&1 | FileCheck
>> -check-prefix CHECK-PIC-ERROR %s
>> +// RUN: %clang -### -target i686-windows-gnu -fpic %s 2>&1 | FileCheck
>> -check-prefix CHECK-pic-ERROR %s
>> +// RUN: %clang -### -target i686-windows-gnu -fPIE %s 2>&1 | FileCheck
>> -check-prefix CHECK-PIE-ERROR %s
>> +// RUN: %clang -### -target i686-windows-gnu -fpie %s 2>&1 | FileCheck
>> -check-prefix CHECK-pie-ERROR %s
>> +// RUN: %clang -### -target i686-windows-gnu -fPIC -fno-pic %s
>> +// RUN: %clang -### -target i686-windows-gnu -Fpic -fno-pic %s
>> +// RUN: %clang -### -target i686-windows-gnu -fPIE -fn

r290575 - [AVX-512] Replace masked 512-bit pmuldq and pmuludq builtins with the newly added unmasked versions and selects.

2016-12-26 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Dec 26 21:46:16 2016
New Revision: 290575

URL: http://llvm.org/viewvc/llvm-project?rev=290575&view=rev
Log:
[AVX-512] Replace masked 512-bit pmuldq and pmuludq builtins with the newly 
added unmasked versions and selects.

Modified:
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=290575&r1=290574&r2=290575&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Mon Dec 26 21:46:16 2016
@@ -1422,7 +1422,7 @@ _mm512_mul_epi32(__m512i __X, __m512i __
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mask_mul_epi32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
  (__v8di)_mm512_mul_epi32(__X, 
__Y),
  (__v8di)__W);
 }
@@ -1430,7 +1430,7 @@ _mm512_mask_mul_epi32(__m512i __W, __mma
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_maskz_mul_epi32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
  (__v8di)_mm512_mul_epi32(__X, 
__Y),
  (__v8di)_mm512_setzero_si512 ());
 }
@@ -1444,7 +1444,7 @@ _mm512_mul_epu32(__m512i __X, __m512i __
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mask_mul_epu32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
  (__v8di)_mm512_mul_epu32(__X, 
__Y),
  (__v8di)__W);
 }
@@ -1452,7 +1452,7 @@ _mm512_mask_mul_epu32(__m512i __W, __mma
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_maskz_mul_epu32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
  (__v8di)_mm512_mul_epu32(__X, 
__Y),
  (__v8di)_mm512_setzero_si512 ());
 }

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=290575&r1=290574&r2=290575&view=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Mon Dec 26 21:46:16 2016
@@ -1867,29 +1867,45 @@ __m512i test_mm512_add_epi64(__m512i __A
   return _mm512_add_epi64(__A,__B);
 }
 
+__m512i test_mm512_mul_epi32(__m512i __A, __m512i __B) {
+  //CHECK-LABEL: @test_mm512_mul_epi32
+  //CHECK: @llvm.x86.avx512.pmul.dq.512
+  return _mm512_mul_epi32(__A,__B);
+}
+
 __m512i test_mm512_maskz_mul_epi32 (__mmask16 __k,__m512i __A, __m512i __B) {
   //CHECK-LABEL: @test_mm512_maskz_mul_epi32
-  //CHECK: @llvm.x86.avx512.mask.pmul.dq.512
+  //CHECK: @llvm.x86.avx512.pmul.dq.512
+  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
   return _mm512_maskz_mul_epi32(__k,__A,__B);
 }
 
 __m512i test_mm512_mask_mul_epi32 (__mmask16 __k,__m512i __A, __m512i __B,
__m512i __src) {
   //CHECK-LABEL: @test_mm512_mask_mul_epi32
-  //CHECK: @llvm.x86.avx512.mask.pmul.dq.512
+  //CHECK: @llvm.x86.avx512.pmul.dq.512
+  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
   return _mm512_mask_mul_epi32(__src,__k,__A,__B);
 }
 
+__m512i test_mm512_mul_epu32 (__m512i __A, __m512i __B) {
+  //CHECK-LABEL: @test_mm512_mul_epu32
+  //CHECK: @llvm.x86.avx512.pmulu.dq.512
+  return _mm512_mul_epu32(__A,__B);
+}
+
 __m512i test_mm512_maskz_mul_epu32 (__mmask16 __k,__m512i __A, __m512i __B) {
   //CHECK-LABEL: @test_mm512_maskz_mul_epu32
-  //CHECK: @llvm.x86.avx512.mask.pmulu.dq.512
+  //CHECK: @llvm.x86.avx512.pmulu.dq.512
+  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
   return _mm512_maskz_mul_epu32(__k,__A,__B);
 }
 
 __m512i test_mm512_mask_mul_epu32 (__mmask16 __k,__m512i __A, __m512i __B, 
__m512i __src) {
   //CHECK-LABEL: @test_mm512_mask_mul_epu32
-  //CHECK: @llvm.x86.avx512.mask.pmulu.dq.512
+  //CHECK: @llvm.x86.avx512.pmulu.dq.512
+  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
   return _mm512_mask_mul_epu32(__src,__k,__A,__B);
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-b

r290574 - foo

2016-12-26 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Dec 26 21:46:13 2016
New Revision: 290574

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512fintrin.h

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=290574&r1=290573&r2=290574&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Mon Dec 26 21:46:13 2016
@@ -974,8 +974,8 @@ TARGET_BUILTIN(__builtin_ia32_pminsd512_
 TARGET_BUILTIN(__builtin_ia32_pminsq512_mask, "V8LLiV8LLiV8LLiV8LLiUc", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pminud512_mask, "V16iV16iV16iV16iUs", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pminuq512_mask, "V8LLiV8LLiV8LLiV8LLiUc", "", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmuldq512_mask, "V8LLiV16iV16iV8LLiUc", "", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmuludq512_mask, "V8LLiV16iV16iV8LLiUc", "", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmuldq512, "V8LLiV16iV16i", "", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmuludq512, "V8LLiV16iV16i", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_ptestmd512, "UsV16iV16iUs", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_ptestmq512, "UcV8LLiV8LLiUc", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pbroadcastd512_gpr_mask, "V16iiV16iUs", "", 
"avx512f")

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=290574&r1=290573&r2=290574&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Mon Dec 26 21:46:13 2016
@@ -1416,57 +1416,45 @@ _mm512_maskz_min_epu64 (__mmask8 __M, __
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mul_epi32(__m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
-  (__v16si) __Y,
-  (__v8di)
-  _mm512_setzero_si512 (),
-  (__mmask8) -1);
+  return (__m512i)__builtin_ia32_pmuldq512((__v16si)__X, (__v16si) __Y);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_mask_mul_epi32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_mask_mul_epi32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
-  (__v16si) __Y,
-  (__v8di) __W, __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+ (__v8di)_mm512_mul_epi32(__X, 
__Y),
+ (__v8di)__W);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_maskz_mul_epi32 (__mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_maskz_mul_epi32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
-  (__v16si) __Y,
-  (__v8di)
-  _mm512_setzero_si512 (),
-  __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+ (__v8di)_mm512_mul_epi32(__X, 
__Y),
+ (__v8di)_mm512_setzero_si512 ());
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mul_epu32(__m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
-   (__v16si) __Y,
-   (__v8di)
-   _mm512_setzero_si512 (),
-   (__mmask8) -1);
+  return (__m512i)__builtin_ia32_pmuludq512((__v16si)__X, (__v16si)__Y);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_mask_mul_epu32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_mask_mul_epu32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
-   (__v16si) __Y,
-   (__v8di) __W, __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+ (__v8di)_mm512_mul_epu32(__X, 
__Y),
+ (__v8di)__W);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_maskz_mul_epu32 (__mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_maskz_mul_epu32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
-   (__v16si) __Y,
-   (__v8di)
-   _mm512_setzero_si512 (),
-   __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
+ (__v8di)_mm512_mul_epu32(__X, 
__Y),
+ (__v8di)_mm512_setzero_si512 ());
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS



Re: r290574 - foo

2016-12-26 Thread Craig Topper via cfe-commits
Oops. I failed to squash this into another commit properly. Reverting
momentarily.

~Craig

On Mon, Dec 26, 2016 at 7:46 PM, Craig Topper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ctopper
> Date: Mon Dec 26 21:46:13 2016
> New Revision: 290574
>
> URL: http://llvm.org/viewvc/llvm-project?rev=290574&view=rev
> Log:
> foo
>
> Modified:
> cfe/trunk/include/clang/Basic/BuiltinsX86.def
> cfe/trunk/lib/Headers/avx512fintrin.h
>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/BuiltinsX86.def?rev=290574&r1=290573&r2=290574&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Mon Dec 26 21:46:13 2016
> @@ -974,8 +974,8 @@ TARGET_BUILTIN(__builtin_ia32_pminsd512_
>  TARGET_BUILTIN(__builtin_ia32_pminsq512_mask, "V8LLiV8LLiV8LLiV8LLiUc",
> "", "avx512f")
>  TARGET_BUILTIN(__builtin_ia32_pminud512_mask, "V16iV16iV16iV16iUs", "",
> "avx512f")
>  TARGET_BUILTIN(__builtin_ia32_pminuq512_mask, "V8LLiV8LLiV8LLiV8LLiUc",
> "", "avx512f")
> -TARGET_BUILTIN(__builtin_ia32_pmuldq512_mask, "V8LLiV16iV16iV8LLiUc",
> "", "avx512f")
> -TARGET_BUILTIN(__builtin_ia32_pmuludq512_mask, "V8LLiV16iV16iV8LLiUc",
> "", "avx512f")
> +TARGET_BUILTIN(__builtin_ia32_pmuldq512, "V8LLiV16iV16i", "", "avx512f")
> +TARGET_BUILTIN(__builtin_ia32_pmuludq512, "V8LLiV16iV16i", "", "avx512f")
>  TARGET_BUILTIN(__builtin_ia32_ptestmd512, "UsV16iV16iUs", "", "avx512f")
>  TARGET_BUILTIN(__builtin_ia32_ptestmq512, "UcV8LLiV8LLiUc", "",
> "avx512f")
>  TARGET_BUILTIN(__builtin_ia32_pbroadcastd512_gpr_mask, "V16iiV16iUs",
> "", "avx512f")
>
> Modified: cfe/trunk/lib/Headers/avx512fintrin.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/
> avx512fintrin.h?rev=290574&r1=290573&r2=290574&view=diff
> 
> ==
> --- cfe/trunk/lib/Headers/avx512fintrin.h (original)
> +++ cfe/trunk/lib/Headers/avx512fintrin.h Mon Dec 26 21:46:13 2016
> @@ -1416,57 +1416,45 @@ _mm512_maskz_min_epu64 (__mmask8 __M, __
>  static __inline __m512i __DEFAULT_FN_ATTRS
>  _mm512_mul_epi32(__m512i __X, __m512i __Y)
>  {
> -  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
> -  (__v16si) __Y,
> -  (__v8di)
> -  _mm512_setzero_si512 (),
> -  (__mmask8) -1);
> +  return (__m512i)__builtin_ia32_pmuldq512((__v16si)__X, (__v16si) __Y);
>  }
>
>  static __inline __m512i __DEFAULT_FN_ATTRS
> -_mm512_mask_mul_epi32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i
> __Y)
> +_mm512_mask_mul_epi32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
>  {
> -  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
> -  (__v16si) __Y,
> -  (__v8di) __W, __M);
> +  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
> +
>  (__v8di)_mm512_mul_epi32(__X, __Y),
> + (__v8di)__W);
>  }
>
>  static __inline __m512i __DEFAULT_FN_ATTRS
> -_mm512_maskz_mul_epi32 (__mmask8 __M, __m512i __X, __m512i __Y)
> +_mm512_maskz_mul_epi32(__mmask8 __M, __m512i __X, __m512i __Y)
>  {
> -  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
> -  (__v16si) __Y,
> -  (__v8di)
> -  _mm512_setzero_si512 (),
> -  __M);
> +  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
> +
>  (__v8di)_mm512_mul_epi32(__X, __Y),
> + (__v8di)_mm512_setzero_si512
> ());
>  }
>
>  static __inline __m512i __DEFAULT_FN_ATTRS
>  _mm512_mul_epu32(__m512i __X, __m512i __Y)
>  {
> -  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
> -   (__v16si) __Y,
> -   (__v8di)
> -   _mm512_setzero_si512 (),
> -   (__mmask8) -1);
> +  return (__m512i)__builtin_ia32_pmuludq512((__v16si)__X, (__v16si)__Y);
>  }
>
>  static __inline __m512i __DEFAULT_FN_ATTRS
> -_mm512_mask_mul_epu32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i
> __Y)
> +_mm512_mask_mul_epu32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
>  {
> -  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
> -   (__v16si) __Y,
> -   (__v8di) __W, __M);
> +  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
> +
>  (__v8di)_mm512_mul_epu32(__X, __Y),
> + (__v8di)__W);
>  }
>
>  static __inline __m512i __DEFAULT_FN_ATTRS
> -_mm512_maskz_mul_epu32 (__mmask8 __M, __m512i __X, __m512i __Y)
> +_mm512_maskz_mul_epu32(__mmask8 __M, __m512i __X, __m512i __Y)
>  {
> -  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
> -   (__v16si) __Y,
> -   (__v8di)
> -   _mm512_setzero_si512 (),
> -   _

r290576 - Factor out repeated code for deducing a non-type template parameter as a given

2016-12-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Dec 26 21:59:58 2016
New Revision: 290576

URL: http://llvm.org/viewvc/llvm-project?rev=290576&view=rev
Log:
Factor out repeated code for deducing a non-type template parameter as a given
argument value. No functionality change intended.

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

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=290576&r1=290575&r2=290576&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Dec 26 21:59:58 2016
@@ -307,20 +307,18 @@ checkDeducedTemplateArguments(ASTContext
 }
 
 /// \brief Deduce the value of the given non-type template parameter
-/// from the given integral constant.
+/// as the given deduced template argument. All non-type template parameter
+/// deduction is funneled through here.
 static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument(
 Sema &S, TemplateParameterList *TemplateParams,
-NonTypeTemplateParmDecl *NTTP, const llvm::APSInt &Value,
-QualType ValueType, bool DeducedFromArrayBound, TemplateDeductionInfo 
&Info,
+NonTypeTemplateParmDecl *NTTP, const DeducedTemplateArgument &NewDeduced,
+QualType ValueType, TemplateDeductionInfo &Info,
 SmallVectorImpl &Deduced) {
   assert(NTTP->getDepth() == Info.getDeducedDepth() &&
  "deducing non-type template argument with wrong depth");
 
-  DeducedTemplateArgument NewDeduced(S.Context, Value, ValueType,
- DeducedFromArrayBound);
-  DeducedTemplateArgument Result = checkDeducedTemplateArguments(S.Context,
- Deduced[NTTP->getIndex()],
- NewDeduced);
+  DeducedTemplateArgument Result = checkDeducedTemplateArguments(
+  S.Context, Deduced[NTTP->getIndex()], NewDeduced);
   if (Result.isNull()) {
 Info.Param = NTTP;
 Info.FirstArg = Deduced[NTTP->getIndex()];
@@ -334,11 +332,25 @@ static Sema::TemplateDeductionResult Ded
S, TemplateParams, NTTP->getType(), ValueType, Info, 
Deduced,
TDF_ParamWithReferenceType | TDF_SkipNonDependent,
/*PartialOrdering=*/false,
-   /*ArrayBound=*/DeducedFromArrayBound)
+   /*ArrayBound=*/NewDeduced.wasDeducedFromArrayBound())
  : Sema::TDK_Success;
 }
 
 /// \brief Deduce the value of the given non-type template parameter
+/// from the given integral constant.
+static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument(
+Sema &S, TemplateParameterList *TemplateParams,
+NonTypeTemplateParmDecl *NTTP, const llvm::APSInt &Value,
+QualType ValueType, bool DeducedFromArrayBound, TemplateDeductionInfo 
&Info,
+SmallVectorImpl &Deduced) {
+  return DeduceNonTypeTemplateArgument(
+  S, TemplateParams, NTTP,
+  DeducedTemplateArgument(S.Context, Value, ValueType,
+  DeducedFromArrayBound),
+  ValueType, Info, Deduced);
+}
+
+/// \brief Deduce the value of the given non-type template parameter
 /// from the given null pointer template argument type.
 static Sema::TemplateDeductionResult DeduceNullPtrTemplateArgument(
 Sema &S, TemplateParameterList *TemplateParams,
@@ -350,94 +362,39 @@ static Sema::TemplateDeductionResult Ded
   S.Context.NullPtrTy, NTTP->getLocation()),
   NullPtrType, CK_NullToPointer)
   .get();
-  DeducedTemplateArgument NewDeduced(Value);
-  DeducedTemplateArgument Result = checkDeducedTemplateArguments(
-  S.Context, Deduced[NTTP->getIndex()], NewDeduced);
-
-  if (Result.isNull()) {
-Info.Param = NTTP;
-Info.FirstArg = Deduced[NTTP->getIndex()];
-Info.SecondArg = NewDeduced;
-return Sema::TDK_Inconsistent;
-  }
-
-  Deduced[NTTP->getIndex()] = Result;
-  return S.getLangOpts().CPlusPlus1z
- ? DeduceTemplateArgumentsByTypeMatch(
-   S, TemplateParams, NTTP->getType(), Value->getType(), Info,
-   Deduced, TDF_ParamWithReferenceType | TDF_SkipNonDependent)
- : Sema::TDK_Success;
+  return DeduceNonTypeTemplateArgument(S, TemplateParams, NTTP,
+   DeducedTemplateArgument(Value),
+   Value->getType(), Info, Deduced);
 }
 
 /// \brief Deduce the value of the given non-type template parameter
 /// from the given type- or value-dependent expression.
 ///
 /// \returns true if deduction succeeded, false otherwise.
-static Sema::TemplateDeductionResult
-DeduceNonTypeTemplateArgument(Sema &S,
-  TemplateParameterList *TemplateParams,
-  NonTypeTemplateParmDecl *NTTP,
- 

r290577 - Add a test for `const` folding introduced by r290297. NFC.

2016-12-26 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Mon Dec 26 22:01:22 2016
New Revision: 290577

URL: http://llvm.org/viewvc/llvm-project?rev=290577&view=rev
Log:
Add a test for `const` folding introduced by r290297. NFC.

AFAICT, we didn't add a test targeted at the new "const can sometimes
act as constexpr" behavior introduced by r290297.

Modified:
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=290577&r1=290576&r2=290577&view=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Mon Dec 26 22:01:22 
2016
@@ -957,3 +957,20 @@ namespace PR27989 {
   }
   static_assert(f(0) == 1, "");
 }
+
+namespace const_char {
+template 
+constexpr int sum(const char (&Arr)[N]) {
+  static_assert(N >= M, "");
+  int S = 0;
+  for (unsigned I = 0; I != M; ++I)
+S += Arr[I];
+  return S;
+}
+
+// As an extension, we support evaluating some things that are `const` as 
though
+// they were `constexpr`.
+const char Cs[] = {'a', 'b', 'c'};
+const int N = 2;
+static_assert(sum(Cs) == 'a' + 'b', "");
+}


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


r290579 - Revert r290574 "foo"

2016-12-26 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Dec 26 22:03:29 2016
New Revision: 290579

URL: http://llvm.org/viewvc/llvm-project?rev=290579&view=rev
Log:
Revert r290574 "foo"

This was supposed to be merged with another commit with a real commit message. 
Sorry.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512fintrin.h

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=290579&r1=290578&r2=290579&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Mon Dec 26 22:03:29 2016
@@ -974,8 +974,8 @@ TARGET_BUILTIN(__builtin_ia32_pminsd512_
 TARGET_BUILTIN(__builtin_ia32_pminsq512_mask, "V8LLiV8LLiV8LLiV8LLiUc", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pminud512_mask, "V16iV16iV16iV16iUs", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pminuq512_mask, "V8LLiV8LLiV8LLiV8LLiUc", "", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmuldq512, "V8LLiV16iV16i", "", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmuludq512, "V8LLiV16iV16i", "", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmuldq512_mask, "V8LLiV16iV16iV8LLiUc", "", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmuludq512_mask, "V8LLiV16iV16iV8LLiUc", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_ptestmd512, "UsV16iV16iUs", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_ptestmq512, "UcV8LLiV8LLiUc", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pbroadcastd512_gpr_mask, "V16iiV16iUs", "", 
"avx512f")

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=290579&r1=290578&r2=290579&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Mon Dec 26 22:03:29 2016
@@ -1416,45 +1416,57 @@ _mm512_maskz_min_epu64 (__mmask8 __M, __
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mul_epi32(__m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_pmuldq512((__v16si)__X, (__v16si) __Y);
+  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
+  (__v16si) __Y,
+  (__v8di)
+  _mm512_setzero_si512 (),
+  (__mmask8) -1);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_mask_mul_epi32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_mask_mul_epi32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
- (__v8di)_mm512_mul_epi32(__X, 
__Y),
- (__v8di)__W);
+  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
+  (__v16si) __Y,
+  (__v8di) __W, __M);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_maskz_mul_epi32(__mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_maskz_mul_epi32 (__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
- (__v8di)_mm512_mul_epi32(__X, 
__Y),
- (__v8di)_mm512_setzero_si512 ());
+  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
+  (__v16si) __Y,
+  (__v8di)
+  _mm512_setzero_si512 (),
+  __M);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mul_epu32(__m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_pmuludq512((__v16si)__X, (__v16si)__Y);
+  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
+   (__v16si) __Y,
+   (__v8di)
+   _mm512_setzero_si512 (),
+   (__mmask8) -1);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_mask_mul_epu32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_mask_mul_epu32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
- (__v8di)_mm512_mul_epu32(__X, 
__Y),
- (__v8di)__W);
+  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
+   (__v16si) __Y,
+   (__v8di) __W, __M);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_maskz_mul_epu32(__mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_maskz_mul_epu32 (__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
- (__v8di)_mm512_mul_epu32(__X, 
__Y),
- (__v8di)_mm512_setzero_si512 ());
+  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
+   (__v16si) __Y,
+   (__v8di)
+

r290578 - Revert r290575 "[AVX-512] Replace masked 512-bit pmuldq and pmuludq builtins with the newly added unmasked versions and selects."

2016-12-26 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Dec 26 22:03:25 2016
New Revision: 290578

URL: http://llvm.org/viewvc/llvm-project?rev=290578&view=rev
Log:
Revert r290575 "[AVX-512] Replace masked 512-bit pmuldq and pmuludq builtins 
with the newly added unmasked versions and selects."

I failed to merge this with r290574.

Modified:
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=290578&r1=290577&r2=290578&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Mon Dec 26 22:03:25 2016
@@ -1422,7 +1422,7 @@ _mm512_mul_epi32(__m512i __X, __m512i __
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mask_mul_epi32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
  (__v8di)_mm512_mul_epi32(__X, 
__Y),
  (__v8di)__W);
 }
@@ -1430,7 +1430,7 @@ _mm512_mask_mul_epi32(__m512i __W, __mma
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_maskz_mul_epi32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
  (__v8di)_mm512_mul_epi32(__X, 
__Y),
  (__v8di)_mm512_setzero_si512 ());
 }
@@ -1444,7 +1444,7 @@ _mm512_mul_epu32(__m512i __X, __m512i __
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mask_mul_epu32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
  (__v8di)_mm512_mul_epu32(__X, 
__Y),
  (__v8di)__W);
 }
@@ -1452,7 +1452,7 @@ _mm512_mask_mul_epu32(__m512i __W, __mma
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_maskz_mul_epu32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__U,
  (__v8di)_mm512_mul_epu32(__X, 
__Y),
  (__v8di)_mm512_setzero_si512 ());
 }

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=290578&r1=290577&r2=290578&view=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Mon Dec 26 22:03:25 2016
@@ -1867,45 +1867,29 @@ __m512i test_mm512_add_epi64(__m512i __A
   return _mm512_add_epi64(__A,__B);
 }
 
-__m512i test_mm512_mul_epi32(__m512i __A, __m512i __B) {
-  //CHECK-LABEL: @test_mm512_mul_epi32
-  //CHECK: @llvm.x86.avx512.pmul.dq.512
-  return _mm512_mul_epi32(__A,__B);
-}
-
 __m512i test_mm512_maskz_mul_epi32 (__mmask16 __k,__m512i __A, __m512i __B) {
   //CHECK-LABEL: @test_mm512_maskz_mul_epi32
-  //CHECK: @llvm.x86.avx512.pmul.dq.512
-  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
+  //CHECK: @llvm.x86.avx512.mask.pmul.dq.512
   return _mm512_maskz_mul_epi32(__k,__A,__B);
 }
 
 __m512i test_mm512_mask_mul_epi32 (__mmask16 __k,__m512i __A, __m512i __B,
__m512i __src) {
   //CHECK-LABEL: @test_mm512_mask_mul_epi32
-  //CHECK: @llvm.x86.avx512.pmul.dq.512
-  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
+  //CHECK: @llvm.x86.avx512.mask.pmul.dq.512
   return _mm512_mask_mul_epi32(__src,__k,__A,__B);
 }
 
-__m512i test_mm512_mul_epu32 (__m512i __A, __m512i __B) {
-  //CHECK-LABEL: @test_mm512_mul_epu32
-  //CHECK: @llvm.x86.avx512.pmulu.dq.512
-  return _mm512_mul_epu32(__A,__B);
-}
-
 __m512i test_mm512_maskz_mul_epu32 (__mmask16 __k,__m512i __A, __m512i __B) {
   //CHECK-LABEL: @test_mm512_maskz_mul_epu32
-  //CHECK: @llvm.x86.avx512.pmulu.dq.512
-  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
+  //CHECK: @llvm.x86.avx512.mask.pmulu.dq.512
   return _mm512_maskz_mul_epu32(__k,__A,__B);
 }
 
 __m512i test_mm512_mask_mul_epu32 (__mmask16 __k,__m512i __A, __m512i __B, 
__m512i __src) {
   //CHECK-LABEL: @test_mm512_mask_mul_epu32
-  //CHECK: @llvm.x86.avx512.pmulu.dq.512
-  //CHECK: select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
+  //CHECK: @llvm.x86.avx512.mask.pmulu.dq.512
   return _mm512_mask_mul_epu32(__src,__k,__A,__B);
 }
 


___
cfe-commits mailing list

r290580 - [AVX-512] Replace masked 512-bit pmuldq and pmuludq builtins with the newly added unmasked versions and selects.

2016-12-26 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Dec 26 22:04:57 2016
New Revision: 290580

URL: http://llvm.org/viewvc/llvm-project?rev=290580&view=rev
Log:
[AVX-512] Replace masked 512-bit pmuldq and pmuludq builtins with the newly 
added unmasked versions and selects.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=290580&r1=290579&r2=290580&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Mon Dec 26 22:04:57 2016
@@ -974,8 +974,8 @@ TARGET_BUILTIN(__builtin_ia32_pminsd512_
 TARGET_BUILTIN(__builtin_ia32_pminsq512_mask, "V8LLiV8LLiV8LLiV8LLiUc", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pminud512_mask, "V16iV16iV16iV16iUs", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_pminuq512_mask, "V8LLiV8LLiV8LLiV8LLiUc", "", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmuldq512_mask, "V8LLiV16iV16iV8LLiUc", "", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_pmuludq512_mask, "V8LLiV16iV16iV8LLiUc", "", 
"avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmuldq512, "V8LLiV16iV16i", "", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_pmuludq512, "V8LLiV16iV16i", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_ptestmd512, "UsV16iV16iUs", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_ptestmq512, "UcV8LLiV8LLiUc", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_pbroadcastd512_gpr_mask, "V16iiV16iUs", "", 
"avx512f")

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=290580&r1=290579&r2=290580&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Mon Dec 26 22:04:57 2016
@@ -1416,57 +1416,45 @@ _mm512_maskz_min_epu64 (__mmask8 __M, __
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mul_epi32(__m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
-  (__v16si) __Y,
-  (__v8di)
-  _mm512_setzero_si512 (),
-  (__mmask8) -1);
+  return (__m512i)__builtin_ia32_pmuldq512((__v16si)__X, (__v16si) __Y);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_mask_mul_epi32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_mask_mul_epi32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
-  (__v16si) __Y,
-  (__v8di) __W, __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+ (__v8di)_mm512_mul_epi32(__X, 
__Y),
+ (__v8di)__W);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_maskz_mul_epi32 (__mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_maskz_mul_epi32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuldq512_mask ((__v16si) __X,
-  (__v16si) __Y,
-  (__v8di)
-  _mm512_setzero_si512 (),
-  __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+ (__v8di)_mm512_mul_epi32(__X, 
__Y),
+ (__v8di)_mm512_setzero_si512 ());
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
 _mm512_mul_epu32(__m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
-   (__v16si) __Y,
-   (__v8di)
-   _mm512_setzero_si512 (),
-   (__mmask8) -1);
+  return (__m512i)__builtin_ia32_pmuludq512((__v16si)__X, (__v16si)__Y);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_mask_mul_epu32 (__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_mask_mul_epu32(__m512i __W, __mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
-   (__v16si) __Y,
-   (__v8di) __W, __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+ (__v8di)_mm512_mul_epu32(__X, 
__Y),
+ (__v8di)__W);
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS
-_mm512_maskz_mul_epu32 (__mmask8 __M, __m512i __X, __m512i __Y)
+_mm512_maskz_mul_epu32(__mmask8 __M, __m512i __X, __m512i __Y)
 {
-  return (__m512i) __builtin_ia32_pmuludq512_mask ((__v16si) __X,
-   (__v16si) __Y,
-   (__v8di)
-   _mm512_setzero_si512 (),
-   __M);
+  return (__m512i)__builtin_ia32_selectq_512((__mmask8)__M,
+ (__v8di)_mm512_m

Re: r290577 - Add a test for `const` folding introduced by r290297. NFC.

2016-12-26 Thread Richard Smith via cfe-commits
On 26 December 2016 at 20:01, George Burgess IV via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: gbiv
> Date: Mon Dec 26 22:01:22 2016
> New Revision: 290577
>
> URL: http://llvm.org/viewvc/llvm-project?rev=290577&view=rev
> Log:
> Add a test for `const` folding introduced by r290297. NFC.
>
> AFAICT, we didn't add a test targeted at the new "const can sometimes
> act as constexpr" behavior introduced by r290297.
>
> Modified:
> cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>
> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/constant-expression-cxx1y.cpp?rev=290577&r1=
> 290576&r2=290577&view=diff
> 
> ==
> --- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Mon Dec 26
> 22:01:22 2016
> @@ -957,3 +957,20 @@ namespace PR27989 {
>}
>static_assert(f(0) == 1, "");
>  }
> +
> +namespace const_char {
> +template 
> +constexpr int sum(const char (&Arr)[N]) {
> +  static_assert(N >= M, "");
> +  int S = 0;
> +  for (unsigned I = 0; I != M; ++I)
> +S += Arr[I];
> +  return S;
> +}
> +
> +// As an extension, we support evaluating some things that are `const` as
> though
> +// they were `constexpr`.
> +const char Cs[] = {'a', 'b', 'c'};
> +const int N = 2;
> +static_assert(sum(Cs) == 'a' + 'b', "");
> +}


Hold on, this test should fail. It's OK to extend the set of things we can
constant-fold, but formal constant expression checking still needs to be
strict. (You should produce a CCEDiag from within the constant expression
evaluator to mark things that are not core constant expressions but are
permitted as an extension.)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r290577 - Add a test for `const` folding introduced by r290297. NFC.

2016-12-26 Thread George Burgess IV via cfe-commits
SG; working on a follow-up now. Thanks!

On Mon, Dec 26, 2016 at 8:26 PM, Richard Smith 
wrote:

> On 26 December 2016 at 20:01, George Burgess IV via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: gbiv
>> Date: Mon Dec 26 22:01:22 2016
>> New Revision: 290577
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=290577&view=rev
>> Log:
>> Add a test for `const` folding introduced by r290297. NFC.
>>
>> AFAICT, we didn't add a test targeted at the new "const can sometimes
>> act as constexpr" behavior introduced by r290297.
>>
>> Modified:
>> cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>>
>> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c
>> onstant-expression-cxx1y.cpp?rev=290577&r1=290576&r2=290577&view=diff
>> 
>> ==
>> --- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Mon Dec 26
>> 22:01:22 2016
>> @@ -957,3 +957,20 @@ namespace PR27989 {
>>}
>>static_assert(f(0) == 1, "");
>>  }
>> +
>> +namespace const_char {
>> +template 
>> +constexpr int sum(const char (&Arr)[N]) {
>> +  static_assert(N >= M, "");
>> +  int S = 0;
>> +  for (unsigned I = 0; I != M; ++I)
>> +S += Arr[I];
>> +  return S;
>> +}
>> +
>> +// As an extension, we support evaluating some things that are `const`
>> as though
>> +// they were `constexpr`.
>> +const char Cs[] = {'a', 'b', 'c'};
>> +const int N = 2;
>> +static_assert(sum(Cs) == 'a' + 'b', "");
>> +}
>
>
> Hold on, this test should fail. It's OK to extend the set of things we can
> constant-fold, but formal constant expression checking still needs to be
> strict. (You should produce a CCEDiag from within the constant expression
> evaluator to mark things that are not core constant expressions but are
> permitted as an extension.)
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290584 - Emit CCEDiags when evaluating a const variable.

2016-12-26 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Mon Dec 26 23:33:20 2016
New Revision: 290584

URL: http://llvm.org/viewvc/llvm-project?rev=290584&view=rev
Log:
Emit CCEDiags when evaluating a const variable.

This addresses post-review feedback from r290577.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=290584&r1=290583&r2=290584&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Dec 26 23:33:20 2016
@@ -2903,7 +2903,7 @@ static CompleteObject findCompleteObject
 // All the remaining cases only permit reading.
 Info.FFDiag(E, diag::note_constexpr_modify_global);
 return CompleteObject();
-  } else if (VD->isConstexpr() || BaseType.isConstQualified()) {
+  } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
 // In OpenCL if a variable is in constant address space it is a const 
value.
@@ -2928,6 +2928,9 @@ static CompleteObject findCompleteObject
 } else {
   Info.CCEDiag(E);
 }
+  } else if (BaseType.isConstQualified() && VD->hasDefinition(Info.Ctx)) {
+Info.CCEDiag(E, diag::note_constexpr_ltor_non_constexpr) << VD;
+// Keep evaluating to see what we can do.
   } else {
 // FIXME: Allow folding of values of any literal type in all languages.
 if (Info.checkingPotentialConstantExpression() &&

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=290584&r1=290583&r2=290584&view=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Mon Dec 26 23:33:20 
2016
@@ -1195,7 +1195,7 @@ struct S {
   int j : f(0); // expected-error {{constant expression}} expected-note {{in 
call to 'f(0)'}}
   int k : g(0); // expected-error {{constant expression}} expected-note 
{{temporary created here}} expected-note {{in call to 'g(0)'}}
   int l : n3; // expected-error {{constant expression}} expected-note {{read 
of non-const variable}}
-  int m : t.n; // expected-warning{{width of bit-field 'm' (42 bits)}}
+  int m : t.n; // expected-warning{{width of bit-field 'm' (42 bits)}} 
expected-warning{{expression is not an integral constant expression}} 
expected-note{{read of non-constexpr variable 't' is not allowed}}
 };
 
 }

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=290584&r1=290583&r2=290584&view=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Mon Dec 26 23:33:20 
2016
@@ -959,18 +959,21 @@ namespace PR27989 {
 }
 
 namespace const_char {
-template 
+template 
 constexpr int sum(const char (&Arr)[N]) {
-  static_assert(N >= M, "");
   int S = 0;
-  for (unsigned I = 0; I != M; ++I)
-S += Arr[I];
+  for (unsigned I = 0; I != N; ++I)
+S += Arr[I]; // expected-note 2{{read of non-constexpr variable 'Cs' is 
not allowed}}
   return S;
 }
 
 // As an extension, we support evaluating some things that are `const` as 
though
-// they were `constexpr`.
-const char Cs[] = {'a', 'b', 'c'};
-const int N = 2;
-static_assert(sum(Cs) == 'a' + 'b', "");
+// they were `constexpr` when folding, but it should not be allowed in normal
+// constexpr evaluation.
+const char Cs[] = {'a', 'b'};
+void foo() __attribute__((enable_if(sum(Cs) == 'a' + 'b', "")));
+void run() { foo(); }
+
+static_assert(sum(Cs) == 'a' + 'b', ""); // expected-error{{not an integral 
constant expression}} expected-note{{in call to 'sum(Cs)'}}
+constexpr int S = sum(Cs); // expected-error{{must be initialized by a 
constant expression}} expected-note{{in call}}
 }


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


Re: r290577 - Add a test for `const` folding introduced by r290297. NFC.

2016-12-26 Thread George Burgess IV via cfe-commits
r290584 :)

On Mon, Dec 26, 2016 at 8:30 PM, George Burgess IV <
george.burgess...@gmail.com> wrote:

> SG; working on a follow-up now. Thanks!
>
> On Mon, Dec 26, 2016 at 8:26 PM, Richard Smith 
> wrote:
>
>> On 26 December 2016 at 20:01, George Burgess IV via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: gbiv
>>> Date: Mon Dec 26 22:01:22 2016
>>> New Revision: 290577
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=290577&view=rev
>>> Log:
>>> Add a test for `const` folding introduced by r290297. NFC.
>>>
>>> AFAICT, we didn't add a test targeted at the new "const can sometimes
>>> act as constexpr" behavior introduced by r290297.
>>>
>>> Modified:
>>> cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>>>
>>> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c
>>> onstant-expression-cxx1y.cpp?rev=290577&r1=290576&r2=290577&view=diff
>>> 
>>> ==
>>> --- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
>>> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Mon Dec 26
>>> 22:01:22 2016
>>> @@ -957,3 +957,20 @@ namespace PR27989 {
>>>}
>>>static_assert(f(0) == 1, "");
>>>  }
>>> +
>>> +namespace const_char {
>>> +template 
>>> +constexpr int sum(const char (&Arr)[N]) {
>>> +  static_assert(N >= M, "");
>>> +  int S = 0;
>>> +  for (unsigned I = 0; I != M; ++I)
>>> +S += Arr[I];
>>> +  return S;
>>> +}
>>> +
>>> +// As an extension, we support evaluating some things that are `const`
>>> as though
>>> +// they were `constexpr`.
>>> +const char Cs[] = {'a', 'b', 'c'};
>>> +const int N = 2;
>>> +static_assert(sum(Cs) == 'a' + 'b', "");
>>> +}
>>
>>
>> Hold on, this test should fail. It's OK to extend the set of things we
>> can constant-fold, but formal constant expression checking still needs to
>> be strict. (You should produce a CCEDiag from within the constant
>> expression evaluator to mark things that are not core constant expressions
>> but are permitted as an extension.)
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290586 - Work around a standard defect: template argument deduction for non-type

2016-12-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Dec 27 00:14:37 2016
New Revision: 290586

URL: http://llvm.org/viewvc/llvm-project?rev=290586&view=rev
Log:
Work around a standard defect: template argument deduction for non-type
template parameters of reference type basically doesn't work, because we're
always deducing from an argument expression of non-reference type, so the type
of the deduced expression never matches. Instead, compare the type of an
expression naming the parameter to the type of the argument.

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp
cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=290586&r1=290585&r2=290586&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Dec 27 00:14:37 2016
@@ -5040,7 +5040,8 @@ ExprResult Sema::CheckTemplateArgument(N
  "non-type template parameter type cannot be qualified");
 
   if (CTAK == CTAK_Deduced &&
-  !Context.hasSameUnqualifiedType(ParamType, Arg->getType())) {
+  !Context.hasSameType(ParamType.getNonLValueExprType(Context),
+   Arg->getType().getNonLValueExprType(Context))) {
 // C++ [temp.deduct.type]p17: (DR1770)
 //   If P has a form that contains , and if the type of i differs from
 //   the type of the corresponding template parameter of the template named
@@ -5048,6 +5049,11 @@ ExprResult Sema::CheckTemplateArgument(N
 //
 // Note that CTAK will be CTAK_DeducedFromArrayBound if the form was [i]
 // rather than .
+//
+// FIXME: We interpret the 'i' here as referring to the expression
+// denoting the non-type template parameter rather than the parameter
+// itself, and so strip off references before comparing types. It's
+// not clear how this is supposed to work for references.
 Diag(StartLoc, diag::err_deduced_non_type_template_arg_type_mismatch)
   << Arg->getType().getUnqualifiedType()
   << ParamType.getUnqualifiedType();

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=290586&r1=290585&r2=290586&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Dec 27 00:14:37 2016
@@ -327,13 +327,18 @@ static Sema::TemplateDeductionResult Ded
   }
 
   Deduced[NTTP->getIndex()] = Result;
-  return S.getLangOpts().CPlusPlus1z
- ? DeduceTemplateArgumentsByTypeMatch(
-   S, TemplateParams, NTTP->getType(), ValueType, Info, 
Deduced,
-   TDF_ParamWithReferenceType | TDF_SkipNonDependent,
-   /*PartialOrdering=*/false,
-   /*ArrayBound=*/NewDeduced.wasDeducedFromArrayBound())
- : Sema::TDK_Success;
+  if (!S.getLangOpts().CPlusPlus1z)
+return Sema::TDK_Success;
+
+  // FIXME: It's not clear how deduction of a parameter of reference
+  // type from an argument (of non-reference type) should be performed.
+  // For now, we just remove reference types from both sides and let
+  // the final check for matching types sort out the mess.
+  return DeduceTemplateArgumentsByTypeMatch(
+  S, TemplateParams, NTTP->getType().getNonReferenceType(),
+  ValueType.getNonReferenceType(), Info, Deduced, TDF_SkipNonDependent,
+  /*PartialOrdering=*/false,
+  /*ArrayBound=*/NewDeduced.wasDeducedFromArrayBound());
 }
 
 /// \brief Deduce the value of the given non-type template parameter

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp?rev=290586&r1=290585&r2=290586&view=diff
==
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp Tue Dec 27 00:14:37 2016
@@ -374,3 +374,28 @@ namespace partial_order_different_types
   template struct A<0, 0, T, U, V> {}; // 
expected-note {{matches}}
   A<0, 0, int, int, 0> a; // expected-error {{ambiguous partial 
specializations}}
 }
+
+namespace partial_order_references {
+  // FIXME: The standard does not appear to consider the second specialization
+  // to be more more specialized than the first! The problem is that deducing
+  // an 'int&' parameter from an argument 'R' results in a type mismatch,
+  // because the parameter has a reference type and the argument is an
+  // expression and thus does not have reference type. We resolve this by
+  // matching the type of an expression corresponding to the para

r290587 - Add reference/non-reference mismatch test.

2016-12-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Dec 27 00:18:22 2016
New Revision: 290587

URL: http://llvm.org/viewvc/llvm-project?rev=290587&view=rev
Log:
Add reference/non-reference mismatch test.

Modified:
cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp?rev=290587&r1=290586&r2=290587&view=diff
==
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp Tue Dec 27 00:18:22 2016
@@ -389,7 +389,7 @@ namespace partial_order_references {
   int N;
   A<0, 0, N> a;
 
-  // FIXME: These should both be rejected as they are not more specialized than
+  // FIXME: These should all be rejected as they are not more specialized than
   // the primary template (they can never be used due to the type mismatch).
   template struct B; // expected-note {{template}}
   template struct B<0, R> {};
@@ -398,4 +398,9 @@ namespace partial_order_references {
   template struct C; // expected-note {{template}}
   template struct C<0, R> {};
   C<0, N> c; // expected-error {{undefined}}
+
+  template struct D; // expected-note {{template}}
+  template struct D<0, N> {};
+  extern const int K = 5;
+  D<0, K> d; // expected-error {{undefined}}
 }


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