[clang] [llvm] [RFC] Introducing `__builtin_consistent` to generate AArch64 BC.cond … (PR #72175)

2024-01-06 Thread Dávid Bolvanský via cfe-commits

davidbolvansky wrote:

but we already have _builtin_expect_with_probability, this looks less general…

cc @nikic 

https://github.com/llvm/llvm-project/pull/72175
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 090b2e2 - [AttrDocs] Enhance musttail attribute documentation

2023-04-06 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2023-04-06T16:51:33+02:00
New Revision: 090b2e27efb2bd2859913f0e9c15effe2a88982b

URL: 
https://github.com/llvm/llvm-project/commit/090b2e27efb2bd2859913f0e9c15effe2a88982b
DIFF: 
https://github.com/llvm/llvm-project/commit/090b2e27efb2bd2859913f0e9c15effe2a88982b.diff

LOG: [AttrDocs] Enhance musttail attribute documentation

Based on info from https://github.com/llvm/llvm-project/issues/54964

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 02f0b6e622771..dae12624a822b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -603,6 +603,9 @@ Any variables in scope, including all arguments to the 
function and the
 return value must be trivially destructible. The calling convention of the
 caller and callee must match, and they must not be variadic functions or have
 old style K&R C function declarations.
+
+``clang::musttail`` provides assurances that the tail call can be optimized on
+all targets, not just one.
   }];
 }
 



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


[clang] b3b08ad - [Clang] Added missing doc for minsize attribute

2022-06-10 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-06-10T21:18:45+02:00
New Revision: b3b08ad6239ccf68bb725defde07edb7a471a9b2

URL: 
https://github.com/llvm/llvm-project/commit/b3b08ad6239ccf68bb725defde07edb7a471a9b2
DIFF: 
https://github.com/llvm/llvm-project/commit/b3b08ad6239ccf68bb725defde07edb7a471a9b2.diff

LOG: [Clang] Added missing doc for minsize attribute

Fixes https://github.com/llvm/llvm-project/issues/53226

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fe6295f3069c..d1f407259cb6 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1438,7 +1438,7 @@ def Final : InheritableAttr {
 def MinSize : InheritableAttr {
   let Spellings = [Clang<"minsize">];
   let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
-  let Documentation = [Undocumented];
+  let Documentation = [MinSizeDocs];
 }
 
 def FlagEnum : InheritableAttr {

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 872eb8a26673..59bbc80708ed 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5833,6 +5833,15 @@ attribute can also be written using C++11 syntax: 
``[[mig::server_routine]]``.
 }];
 }
 
+def MinSizeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+This function attribute indicates that optimization passes and code generator 
passes
+make choices that keep the function code size as small as possible. 
Optimizations may
+also sacrifice runtime performance in order to minimize the size of the 
generated code.
+  }];
+}
+
 def MSAllocatorDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{



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


[clang] 520c8ca - [Clang] Added release note for improved -Wunused-but-set-variable warning

2022-03-25 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-25T10:45:28+01:00
New Revision: 520c8ca9d2f940dd93618ad98c445573f13aa714

URL: 
https://github.com/llvm/llvm-project/commit/520c8ca9d2f940dd93618ad98c445573f13aa714
DIFF: 
https://github.com/llvm/llvm-project/commit/520c8ca9d2f940dd93618ad98c445573f13aa714.diff

LOG: [Clang] Added release note for improved -Wunused-but-set-variable warning

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b268d0f8c20d8..cb2d81e21f243 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -93,6 +93,8 @@ Improvements to Clang's diagnostics
   extension definitions of an inline namespace and therefore points its note
   at the original definition. This fixes `Issue 50794 (PR51452)
   `_.
+- ``-Wunused-but-set-variable`` now also warns if the variable is only used
+  by unary operators.
 
 Non-comprehensive list of changes in this release
 - The builtin function __builtin_dump_struct would crash clang when the target 



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


[clang] 2af845a - Relands "[Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators"

2022-03-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T10:34:44+01:00
New Revision: 2af845a6519c9cde5c8f58db5554f8b1084ce1ed

URL: 
https://github.com/llvm/llvm-project/commit/2af845a6519c9cde5c8f58db5554f8b1084ce1ed
DIFF: 
https://github.com/llvm/llvm-project/commit/2af845a6519c9cde5c8f58db5554f8b1084ce1ed.diff

LOG: Relands "[Clang] -Wunused-but-set-variable warning - handle also pre/post 
unary operators"

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Sema/warn-unused-but-set-parameters.c
clang/test/Sema/warn-unused-but-set-variables.c
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8873731cd3d3e..f360dc6e1a236 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7921,6 +7921,7 @@ static void MaybeDecrementCount(
 Expr *E, llvm::DenseMap &RefsMinusAssignments) {
   DeclRefExpr *LHS = nullptr;
   bool IsCompoundAssign = false;
+  bool isIncrementDecrementUnaryOp = false;
   if (BinaryOperator *BO = dyn_cast(E)) {
 if (BO->getLHS()->getType()->isDependentType() ||
 BO->getRHS()->getType()->isDependentType()) {
@@ -7935,6 +7936,11 @@ static void MaybeDecrementCount(
 if (COCE->getOperator() != OO_Equal)
   return;
 LHS = dyn_cast(COCE->getArg(0));
+  } else if (UnaryOperator *UO = dyn_cast(E)) {
+if (!UO->isIncrementDecrementOp())
+  return;
+isIncrementDecrementUnaryOp = true;
+LHS = dyn_cast(UO->getSubExpr());
   }
   if (!LHS)
 return;
@@ -7942,8 +7948,10 @@ static void MaybeDecrementCount(
   if (!VD)
 return;
   // Don't decrement RefsMinusAssignments if volatile variable with compound
-  // assignment (+=, ...) to avoid potential unused-but-set-variable warning.
-  if (IsCompoundAssign && VD->getType().isVolatileQualified())
+  // assignment (+=, ...) or increment/decrement unary operator to avoid
+  // potential unused-but-set-variable warning.
+  if ((IsCompoundAssign || isIncrementDecrementUnaryOp) &&
+  VD->getType().isVolatileQualified())
 return;
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())

diff  --git a/clang/test/Sema/warn-unused-but-set-parameters.c 
b/clang/test/Sema/warn-unused-but-set-parameters.c
index 4f000617cfcc4..f1563ab50c1fb 100644
--- a/clang/test/Sema/warn-unused-but-set-parameters.c
+++ b/clang/test/Sema/warn-unused-but-set-parameters.c
@@ -25,10 +25,10 @@ void f3(struct S s) { // expected-warning{{parameter 's' 
set but not used}}
   s = t;
 }
 
-void f4(int j) { //TODO: warn
+void f4(int j) { // expected-warning{{parameter 'j' set but not used}}
 j++;
 }
 
-void f5(int k) { //TODO: warn
+void f5(int k) { // expected-warning{{parameter 'k' set but not used}}
 --k;
 }

diff  --git a/clang/test/Sema/warn-unused-but-set-variables.c 
b/clang/test/Sema/warn-unused-but-set-variables.c
index 6e5b7d671711b..a390944815a9a 100644
--- a/clang/test/Sema/warn-unused-but-set-variables.c
+++ b/clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,3 +73,23 @@ void f3(void) {
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
+
+void f4(void) {
+  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
+  x1++;
+  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
+  x2--;
+  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
+  ++x3;
+  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
+  --x4;
+
+  static int counter = 0; // expected-warning{{variable 'counter' set but not 
used}}
+  counter += 1;
+
+  volatile int v1 = 0;
+  ++v1;
+  typedef volatile int volint;
+  volint v2 = 0;
+  v2++;
+}

diff  --git a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp 
b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
index 400e9d7681b31..418baa78aa964 100644
--- a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,6 +7,7 @@ struct S {
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
+  void operator ++();
 };
 
 int f0() {
@@ -62,3 +63,9 @@ template void f4(T n) {
   SWarnUnused swu;
   swu += n;
 }
+
+template  void f5() {
+  // Don't warn for overloaded pre/post operators in template code.
+  SWarnUnused swu;
+  ++swu;
+}



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


[clang] 48285c2 - [NFCI] Fix set-but-unused warning in ClangAttrEmitter.cpp

2022-03-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T08:13:28+01:00
New Revision: 48285c20eb5f5ed4f7b539fbd7f882c997a08f46

URL: 
https://github.com/llvm/llvm-project/commit/48285c20eb5f5ed4f7b539fbd7f882c997a08f46
DIFF: 
https://github.com/llvm/llvm-project/commit/48285c20eb5f5ed4f7b539fbd7f882c997a08f46.diff

LOG: [NFCI] Fix set-but-unused warning in ClangAttrEmitter.cpp

Added: 


Modified: 
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 47c06cdd147cb..b77554cbb6d39 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1522,12 +1522,10 @@ writePrettyPrintFunction(const Record &R,
   // To avoid printing parentheses around an empty argument list or
   // printing spurious commas at the end of an argument list, we need to
   // determine where the last provided non-fake argument is.
-  unsigned NonFakeArgs = 0;
   bool FoundNonOptArg = false;
   for (const auto &arg : llvm::reverse(Args)) {
 if (arg->isFake())
   continue;
-++NonFakeArgs;
 if (FoundNonOptArg)
   continue;
 // FIXME: arg->getIsOmitted() == "false" means we haven't implemented



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


[clang] 1c13bbd - [NFCI] Fix set-but-unused warning in UnwrappedLineParser.cpp

2022-03-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T08:13:29+01:00
New Revision: 1c13bbdde630b8716f817989a33ccc77a588642c

URL: 
https://github.com/llvm/llvm-project/commit/1c13bbdde630b8716f817989a33ccc77a588642c
DIFF: 
https://github.com/llvm/llvm-project/commit/1c13bbdde630b8716f817989a33ccc77a588642c.diff

LOG: [NFCI] Fix set-but-unused warning in UnwrappedLineParser.cpp

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 8052eb932141d..b8cffcd471e91 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -600,10 +600,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   do {
 // Get next non-comment token.
 FormatToken *NextTok;
-unsigned ReadTokens = 0;
 do {
   NextTok = Tokens->getNextToken();
-  ++ReadTokens;
 } while (NextTok->is(tok::comment));
 
 switch (Tok->Tok.getKind()) {
@@ -643,7 +641,6 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 ScopedMacroState MacroState(*Line, Tokens, NextTok);
 do {
   NextTok = Tokens->getNextToken();
-  ++ReadTokens;
 } while (NextTok->isNot(tok::eof));
   }
 
@@ -696,7 +693,6 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 // We can have an array subscript after a braced init
 // list, but C++11 attributes are expected after blocks.
 NextTok = Tokens->getNextToken();
-++ReadTokens;
 ProbablyBracedList = NextTok->isNot(tok::l_square);
   }
 }



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


[clang] a683ba4 - [NFCI] Fix set-but-unused warning in CGOpenMPRuntime.cpp

2022-03-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T07:49:21+01:00
New Revision: a683ba4ff5a04025ad5221ef2262195212a51577

URL: 
https://github.com/llvm/llvm-project/commit/a683ba4ff5a04025ad5221ef2262195212a51577
DIFF: 
https://github.com/llvm/llvm-project/commit/a683ba4ff5a04025ad5221ef2262195212a51577.diff

LOG: [NFCI] Fix set-but-unused warning in CGOpenMPRuntime.cpp

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index cd58a1b67a166..cb7ab2273a300 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11989,7 +11989,6 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
   }
   // Mark linear parameters.
   auto *SI = Attr->steps_begin();
-  auto *MI = Attr->modifiers_begin();
   for (const Expr *E : Attr->linears()) {
 E = E->IgnoreParenImpCasts();
 unsigned Pos;
@@ -12033,7 +12032,6 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 if (Linear == ParamAttr.Kind)
   ParamAttr.StrideOrArg = ParamAttr.StrideOrArg * PtrRescalingFactor;
 ++SI;
-++MI;
   }
   llvm::APSInt VLENVal;
   SourceLocation ExprLoc;



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


[clang] dc46fa4 - [NFCI] Fix set-but-unused warning in ExprConstant.cpp

2022-03-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T07:47:50+01:00
New Revision: dc46fa41d46e3cace9dbdc0b2c7b61d206b03165

URL: 
https://github.com/llvm/llvm-project/commit/dc46fa41d46e3cace9dbdc0b2c7b61d206b03165
DIFF: 
https://github.com/llvm/llvm-project/commit/dc46fa41d46e3cace9dbdc0b2c7b61d206b03165.diff

LOG: [NFCI] Fix set-but-unused warning in ExprConstant.cpp

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 78f7592471ddb..0930bfd3fc8b9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10102,7 +10102,6 @@ bool RecordExprEvaluator::VisitLambdaExpr(const 
LambdaExpr *E) {
   // Iterate through all the lambda's closure object's fields and initialize
   // them.
   auto *CaptureInitIt = E->capture_init_begin();
-  const LambdaCapture *CaptureIt = ClosureClass->captures_begin();
   bool Success = true;
   const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(ClosureClass);
   for (const auto *Field : ClosureClass->fields()) {
@@ -10126,7 +10125,6 @@ bool RecordExprEvaluator::VisitLambdaExpr(const 
LambdaExpr *E) {
 return false;
   Success = false;
 }
-++CaptureIt;
   }
   return Success;
 }



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


[clang] 5b6b840 - Revert "[Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators"

2022-03-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-24T07:44:51+01:00
New Revision: 5b6b840531fa05093a4099699b0cda881fbadef8

URL: 
https://github.com/llvm/llvm-project/commit/5b6b840531fa05093a4099699b0cda881fbadef8
DIFF: 
https://github.com/llvm/llvm-project/commit/5b6b840531fa05093a4099699b0cda881fbadef8.diff

LOG: Revert "[Clang] -Wunused-but-set-variable warning - handle also pre/post 
unary operators"

This reverts commit 460fc440ad8d41ca2e3882987512989b1c188fbe.

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Sema/warn-unused-but-set-parameters.c
clang/test/Sema/warn-unused-but-set-variables.c
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f360dc6e1a236..8873731cd3d3e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7921,7 +7921,6 @@ static void MaybeDecrementCount(
 Expr *E, llvm::DenseMap &RefsMinusAssignments) {
   DeclRefExpr *LHS = nullptr;
   bool IsCompoundAssign = false;
-  bool isIncrementDecrementUnaryOp = false;
   if (BinaryOperator *BO = dyn_cast(E)) {
 if (BO->getLHS()->getType()->isDependentType() ||
 BO->getRHS()->getType()->isDependentType()) {
@@ -7936,11 +7935,6 @@ static void MaybeDecrementCount(
 if (COCE->getOperator() != OO_Equal)
   return;
 LHS = dyn_cast(COCE->getArg(0));
-  } else if (UnaryOperator *UO = dyn_cast(E)) {
-if (!UO->isIncrementDecrementOp())
-  return;
-isIncrementDecrementUnaryOp = true;
-LHS = dyn_cast(UO->getSubExpr());
   }
   if (!LHS)
 return;
@@ -7948,10 +7942,8 @@ static void MaybeDecrementCount(
   if (!VD)
 return;
   // Don't decrement RefsMinusAssignments if volatile variable with compound
-  // assignment (+=, ...) or increment/decrement unary operator to avoid
-  // potential unused-but-set-variable warning.
-  if ((IsCompoundAssign || isIncrementDecrementUnaryOp) &&
-  VD->getType().isVolatileQualified())
+  // assignment (+=, ...) to avoid potential unused-but-set-variable warning.
+  if (IsCompoundAssign && VD->getType().isVolatileQualified())
 return;
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())

diff  --git a/clang/test/Sema/warn-unused-but-set-parameters.c 
b/clang/test/Sema/warn-unused-but-set-parameters.c
index f1563ab50c1fb..4f000617cfcc4 100644
--- a/clang/test/Sema/warn-unused-but-set-parameters.c
+++ b/clang/test/Sema/warn-unused-but-set-parameters.c
@@ -25,10 +25,10 @@ void f3(struct S s) { // expected-warning{{parameter 's' 
set but not used}}
   s = t;
 }
 
-void f4(int j) { // expected-warning{{parameter 'j' set but not used}}
+void f4(int j) { //TODO: warn
 j++;
 }
 
-void f5(int k) { // expected-warning{{parameter 'k' set but not used}}
+void f5(int k) { //TODO: warn
 --k;
 }

diff  --git a/clang/test/Sema/warn-unused-but-set-variables.c 
b/clang/test/Sema/warn-unused-but-set-variables.c
index 58104d198084c..6e5b7d671711b 100644
--- a/clang/test/Sema/warn-unused-but-set-variables.c
+++ b/clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,20 +73,3 @@ void f3(void) {
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
-
-void f4(void) {
-  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
-  x1++;
-  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
-  x2--;
-  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
-  ++x3;
-  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
-  --x4;
-
-  volatile int v1 = 0;
-  ++v1;
-  typedef volatile int volint;
-  volint v2 = 0;
-  v2++;
-}

diff  --git a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp 
b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
index 418baa78aa964..400e9d7681b31 100644
--- a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,7 +7,6 @@ struct S {
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
-  void operator ++();
 };
 
 int f0() {
@@ -63,9 +62,3 @@ template void f4(T n) {
   SWarnUnused swu;
   swu += n;
 }
-
-template  void f5() {
-  // Don't warn for overloaded pre/post operators in template code.
-  SWarnUnused swu;
-  ++swu;
-}



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


[clang] d90a3fc - [Clang] Added testcases for -Wunused-but-set-parameter

2022-03-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-23T22:14:38+01:00
New Revision: d90a3fcacda7257b26ac32350353410f79be6d2b

URL: 
https://github.com/llvm/llvm-project/commit/d90a3fcacda7257b26ac32350353410f79be6d2b
DIFF: 
https://github.com/llvm/llvm-project/commit/d90a3fcacda7257b26ac32350353410f79be6d2b.diff

LOG: [Clang] Added testcases for -Wunused-but-set-parameter

Clang now emits warnings for them after D122271 (shared logic with 
-Wunused-but-set-variable)

Added: 


Modified: 
clang/test/Sema/warn-unused-but-set-parameters.c

Removed: 




diff  --git a/clang/test/Sema/warn-unused-but-set-parameters.c 
b/clang/test/Sema/warn-unused-but-set-parameters.c
index 4da4822090f3d..f1563ab50c1fb 100644
--- a/clang/test/Sema/warn-unused-but-set-parameters.c
+++ b/clang/test/Sema/warn-unused-but-set-parameters.c
@@ -24,3 +24,11 @@ void f3(struct S s) { // expected-warning{{parameter 's' set 
but not used}}
   struct S t;
   s = t;
 }
+
+void f4(int j) { // expected-warning{{parameter 'j' set but not used}}
+j++;
+}
+
+void f5(int k) { // expected-warning{{parameter 'k' set but not used}}
+--k;
+}



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


[clang] 460fc44 - [Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators

2022-03-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-23T22:05:36+01:00
New Revision: 460fc440ad8d41ca2e3882987512989b1c188fbe

URL: 
https://github.com/llvm/llvm-project/commit/460fc440ad8d41ca2e3882987512989b1c188fbe
DIFF: 
https://github.com/llvm/llvm-project/commit/460fc440ad8d41ca2e3882987512989b1c188fbe.diff

LOG: [Clang] -Wunused-but-set-variable warning - handle also pre/post unary 
operators

Clang fails to diagnose:
```
void test() {
int j = 0;
for (int i = 0; i < 1000; i++)
j++;
return;
}
```

Reason: Missing support for UnaryOperator.

We should not warn with volatile variables... so add check for it.

Reviewed By: efriedma

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

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Sema/warn-unused-but-set-variables.c
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8873731cd3d3e..f360dc6e1a236 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7921,6 +7921,7 @@ static void MaybeDecrementCount(
 Expr *E, llvm::DenseMap &RefsMinusAssignments) {
   DeclRefExpr *LHS = nullptr;
   bool IsCompoundAssign = false;
+  bool isIncrementDecrementUnaryOp = false;
   if (BinaryOperator *BO = dyn_cast(E)) {
 if (BO->getLHS()->getType()->isDependentType() ||
 BO->getRHS()->getType()->isDependentType()) {
@@ -7935,6 +7936,11 @@ static void MaybeDecrementCount(
 if (COCE->getOperator() != OO_Equal)
   return;
 LHS = dyn_cast(COCE->getArg(0));
+  } else if (UnaryOperator *UO = dyn_cast(E)) {
+if (!UO->isIncrementDecrementOp())
+  return;
+isIncrementDecrementUnaryOp = true;
+LHS = dyn_cast(UO->getSubExpr());
   }
   if (!LHS)
 return;
@@ -7942,8 +7948,10 @@ static void MaybeDecrementCount(
   if (!VD)
 return;
   // Don't decrement RefsMinusAssignments if volatile variable with compound
-  // assignment (+=, ...) to avoid potential unused-but-set-variable warning.
-  if (IsCompoundAssign && VD->getType().isVolatileQualified())
+  // assignment (+=, ...) or increment/decrement unary operator to avoid
+  // potential unused-but-set-variable warning.
+  if ((IsCompoundAssign || isIncrementDecrementUnaryOp) &&
+  VD->getType().isVolatileQualified())
 return;
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())

diff  --git a/clang/test/Sema/warn-unused-but-set-variables.c 
b/clang/test/Sema/warn-unused-but-set-variables.c
index 6e5b7d671711b..58104d198084c 100644
--- a/clang/test/Sema/warn-unused-but-set-variables.c
+++ b/clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,3 +73,20 @@ void f3(void) {
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
+
+void f4(void) {
+  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
+  x1++;
+  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
+  x2--;
+  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
+  ++x3;
+  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
+  --x4;
+
+  volatile int v1 = 0;
+  ++v1;
+  typedef volatile int volint;
+  volint v2 = 0;
+  v2++;
+}

diff  --git a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp 
b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
index 400e9d7681b31..418baa78aa964 100644
--- a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,6 +7,7 @@ struct S {
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
+  void operator ++();
 };
 
 int f0() {
@@ -62,3 +63,9 @@ template void f4(T n) {
   SWarnUnused swu;
   swu += n;
 }
+
+template  void f5() {
+  // Don't warn for overloaded pre/post operators in template code.
+  SWarnUnused swu;
+  ++swu;
+}



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


[clang] cb2f2fe - [Clang] Added info about noinline/always_inline statement attributes to release notes

2022-03-17 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-17T16:29:23+01:00
New Revision: cb2f2fecc151999a7892a9d1325a34f85dabcecb

URL: 
https://github.com/llvm/llvm-project/commit/cb2f2fecc151999a7892a9d1325a34f85dabcecb
DIFF: 
https://github.com/llvm/llvm-project/commit/cb2f2fecc151999a7892a9d1325a34f85dabcecb.diff

LOG: [Clang] Added info about noinline/always_inline statement attributes to 
release notes

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d457be1305cf7..21531bf72cd5b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -103,6 +103,9 @@ Attribute Changes in Clang
 attributes of 
diff erent kinds.
   - Emit error on GNU attributes for a nested namespace definition.
 
+- Statement attributes ``[[clang::noinline]]`` and  
``[[clang::always_inline]]``
+  can be used to control inlining decisions at callsites.
+
 Windows Support
 ---
 



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


[clang] 56e7d6b - [Clang] noinline stmt attribute - emit warnings rather than errors

2022-03-14 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-14T23:40:17+01:00
New Revision: 56e7d6bd444cef8d879adc35dcf461cb4d2ed6d5

URL: 
https://github.com/llvm/llvm-project/commit/56e7d6bd444cef8d879adc35dcf461cb4d2ed6d5
DIFF: 
https://github.com/llvm/llvm-project/commit/56e7d6bd444cef8d879adc35dcf461cb4d2ed6d5.diff

LOG: [Clang] noinline stmt attribute - emit warnings rather than errors

Compatible behaviour with always_inline stmt attribute

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/stmt-attributes.c
clang/test/Sema/attr-noinline.c
clang/test/Sema/attr-noinline.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index e28044646080e..a35b2fcbc4fb5 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1770,7 +1770,7 @@ def NoInline : DeclOrStmtAttr {
   let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
 C2x<"clang", "noinline">]>];
   let Documentation = [NoInlineDocs];
-  let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
+  let Subjects = SubjectList<[Function, Stmt], WarnDiag,
  "functions and statements">;
   let SimpleHandler = 1;
 }

diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index ebb10da9ab6ea..02776278827c0 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -217,14 +217,13 @@ static Attr *handleNoMergeAttr(Sema &S, Stmt *St, const 
ParsedAttr &A,
 static Attr *handleNoInlineAttr(Sema &S, Stmt *St, const ParsedAttr &A,
 SourceRange Range) {
   NoInlineAttr NIA(S.Context, A);
-  CallExprFinder CEF(S, St);
-
   if (!NIA.isClangNoInline()) {
 S.Diag(St->getBeginLoc(), diag::warn_function_attribute_ignored_in_stmt)
 << "[[clang::noinline]]";
 return nullptr;
   }
 
+  CallExprFinder CEF(S, St);
   if (!CEF.foundCallExpr()) {
 S.Diag(St->getBeginLoc(), diag::warn_attribute_ignored_no_calls_in_stmt)
 << A;

diff  --git a/clang/test/Parser/stmt-attributes.c 
b/clang/test/Parser/stmt-attributes.c
index 4a8c2c1d2a74d..ccd206e70a225 100644
--- a/clang/test/Parser/stmt-attributes.c
+++ b/clang/test/Parser/stmt-attributes.c
@@ -45,7 +45,7 @@ void foo(int i) {
   }
 
   __attribute__((fastcall)) goto there; // expected-error {{'fastcall' 
attribute cannot be applied to a statement}}
-  __attribute__((noinline)) there : // expected-error {{'noinline' 
attribute only applies to functions and statements}}
+  __attribute__((noinline)) there : // expected-warning {{'noinline' 
attribute only applies to functions and statements}}
 
 __attribute__((weakref)) return; // 
expected-error {{'weakref' attribute only applies to variables and functions}}
 

diff  --git a/clang/test/Sema/attr-noinline.c b/clang/test/Sema/attr-noinline.c
index 065e8fad716aa..2a3532df4b34b 100644
--- a/clang/test/Sema/attr-noinline.c
+++ b/clang/test/Sema/attr-noinline.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
 
-int a __attribute__((noinline)); // expected-error {{'noinline' attribute only 
applies to functions and statements}}
+int a __attribute__((noinline)); // expected-warning {{'noinline' attribute 
only applies to functions and statements}}
 
 void t1(void) __attribute__((noinline));
 

diff  --git a/clang/test/Sema/attr-noinline.cpp 
b/clang/test/Sema/attr-noinline.cpp
index 97c894a3f2f0c..d35782f11adbb 100644
--- a/clang/test/Sema/attr-noinline.cpp
+++ b/clang/test/Sema/attr-noinline.cpp
@@ -13,7 +13,7 @@ void foo() {
   int x;
   [[clang::noinline]] x = 0; // expected-warning {{'noinline' attribute is 
ignored because there exists no call expression inside the statement}}
   [[clang::noinline]] { asm("nop"); } // expected-warning {{'noinline' 
attribute is ignored because there exists no call expression inside the 
statement}}
-  [[clang::noinline]] label: x = 1; // expected-error {{'noinline' attribute 
only applies to functions and statements}}
+  [[clang::noinline]] label: x = 1; // expected-warning {{'noinline' attribute 
only applies to functions and statements}}
 
 
   [[clang::noinline]] always_inline_fn(); // expected-warning {{statement 
attribute 'noinline' has higher precedence than function attribute 
'always_inline'}}
@@ -24,4 +24,4 @@ void foo() {
   __attribute__((noinline)) bar(); // expected-warning {{attribute is ignored 
on this statement as it only applies to functions; use '[[clang::noinline]]' on 
statements}}
 }
 
-[[clang::noinline]] static int i = bar(); // expected-error {{'noinline' 
attribute only applies to functions and statements}}
+[[clang::noinline]] static int i = bar(); // expected-warning {{'noinline' 
attribute only applies to functions and statements}}



[clang] a717e9d - [AttrDocs] try to fix build

2022-03-14 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-14T22:19:55+01:00
New Revision: a717e9d47e64682bf45e6a998d11d76f47454f12

URL: 
https://github.com/llvm/llvm-project/commit/a717e9d47e64682bf45e6a998d11d76f47454f12
DIFF: 
https://github.com/llvm/llvm-project/commit/a717e9d47e64682bf45e6a998d11d76f47454f12.diff

LOG: [AttrDocs] try to fix build

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index ee5be4c0bc412..d7cd31174bc5b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6260,7 +6260,11 @@ attribute associated with it (the attribute applies to 
the declaration, not the
 statement in that case). So this use case will not work:
 
 .. code-block:: c
-  [[clang::always_inline]] int i = bar();
+
+  int example(void) {
+[[clang::always_inline]] int i = bar();
+return i;
+  }
 
 This attribute does not guarantee that inline substitution actually occurs.
 



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


[clang] 003c0b9 - [Clang] always_inline statement attribute

2022-03-14 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-03-14T21:45:31+01:00
New Revision: 003c0b9307bc52605fc93c599dfe36849839ded5

URL: 
https://github.com/llvm/llvm-project/commit/003c0b9307bc52605fc93c599dfe36849839ded5
DIFF: 
https://github.com/llvm/llvm-project/commit/003c0b9307bc52605fc93c599dfe36849839ded5.diff

LOG: [Clang] always_inline statement  attribute

Motivation:

```
int test(int x, int y) {
int r = 0;
[[clang::always_inline]] r += foo(x, y); // force compiler to inline this 
function here
return r;
}
```

In 2018, @kuhar proposed "Introduce per-callsite inline intrinsics" in 
https://reviews.llvm.org/D51200 to solve this motivation case (and many others).

This patch solves this problem with call site attribute. "noinline" statement 
attribute already landed in D119061. Also, some LLVM Inliner fixes landed so 
call site attribute is stronger than function attribute.

Reviewed By: aaron.ballman

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

Added: 
clang/test/CodeGen/attr-alwaysinline.cpp
clang/test/Sema/attr-alwaysinline.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/objc-implementation-attrs.m

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index cd2e2ca8bbf5a..e28044646080e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -706,9 +706,13 @@ def AlignNatural : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
-def AlwaysInline : InheritableAttr {
-  let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
-  let Subjects = SubjectList<[Function]>;
+def AlwaysInline : DeclOrStmtAttr {
+  let Spellings = [GCC<"always_inline">, CXX11<"clang", "always_inline">,
+   C2x<"clang", "always_inline">, Keyword<"__forceinline">];
+  let Accessors = [Accessor<"isClangAlwaysInline", [CXX11<"clang", 
"always_inline">,
+C2x<"clang", 
"always_inline">]>];
+  let Subjects = SubjectList<[Function, Stmt], WarnDiag,
+ "functions and statements">;
   let Documentation = [AlwaysInlineDocs];
 }
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 5f50b49ee2373..ee5be4c0bc412 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6241,7 +6241,28 @@ def AlwaysInlineDocs : Documentation {
 Inlining heuristics are disabled and inlining is always attempted regardless of
 optimization level.
 
-Does not guarantee that inline substitution actually occurs.
+``[[clang::always_inline]]`` spelling can be used as a statement attribute; 
other
+spellings of the attribute are not supported on statements. If a statement is
+marked ``[[clang::always_inline]]`` and contains calls, the compiler attempts
+to inline those calls.
+
+.. code-block:: c
+
+  int example(void) {
+int i;
+[[clang::always_inline]] foo(); // attempts to inline foo
+[[clang::always_inline]] i = bar(); // attempts to inline bar
+[[clang::always_inline]] return f(42, baz(bar())); // attempts to inline 
everything
+  }
+
+A declaration statement, which is a statement, is not a statement that can 
have an
+attribute associated with it (the attribute applies to the declaration, not the
+statement in that case). So this use case will not work:
+
+.. code-block:: c
+  [[clang::always_inline]] int i = bar();
+
+This attribute does not guarantee that inline substitution actually occurs.
 
 Note: applying this attribute to a coroutine at the `-O0` optimization 
level
 has no effect; other optimization levels may only partially inline and result 
in a

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db4adbbb6e1e6..e17b018937fb4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4052,7 +4052,7 @@ def warn_attribute_nonnull_parm_no_args : Warning<
   InGroup;
 def warn_function_stmt_attribute_precedence : Warning<
   "statement attribute %0 has higher precedence than function attribute "
-  "'%select{always_inline|flatten}1'">,
+  "'%select{always_inline|flatten|noinline}1'">,
   InGroup;
 def note_declared_nonnull : Note<
   "declared %select{'returns_nonnull'|'nonnull'}0 here">;

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index ab84d133de84e..8331d1ba215e9 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5248,6 +5248,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (InN

[clang] 223b824 - [Clang] noinline call site attribute

2022-02-28 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-02-28T21:21:17+01:00
New Revision: 223b8240223541d3feb0c96b7f9bac114cd72f46

URL: 
https://github.com/llvm/llvm-project/commit/223b8240223541d3feb0c96b7f9bac114cd72f46
DIFF: 
https://github.com/llvm/llvm-project/commit/223b8240223541d3feb0c96b7f9bac114cd72f46.diff

LOG: [Clang] noinline call site attribute

Motivation:

```
int foo(int x, int y) { // any compiler will happily inline this function
return x / y;
}

int test(int x, int y) {
int r = 0;
[[clang::noinline]] r += foo(x, y); // for some reason we don't want any 
inlining here
return r;
}

```

In 2018, @kuhar proposed "Introduce per-callsite inline intrinsics"  in 
https://reviews.llvm.org/D51200 to solve this motivation case (and many others).

This patch solves this problem with call site attribute. The implementation is 
"smaller" wrt approach which uses new intrinsics and thanks to 
https://reviews.llvm.org/D79121 (Add nomerge statement attribute to clang), we 
have got some basic infrastructure to deal with attrs on statements with call 
expressions.

GCC devs are more inclined to call attribute solution as well, as builtins are 
problematic for them - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104187. But 
they have no patch proposal yet so..  We have free hands here.

If this approach makes sense, next future steps would be support for call site 
attributes for always_inline / flatten.

Reviewed By: aaron.ballman, kuhar

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

Added: 
clang/test/CodeGen/attr-noinline.cpp
clang/test/Sema/attr-noinline.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/stmt-attributes.c
clang/test/Sema/attr-noinline.c

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f47bb413ea997..cd2e2ca8bbf5a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1760,10 +1760,14 @@ def Convergent : InheritableAttr {
   let SimpleHandler = 1;
 }
 
-def NoInline : InheritableAttr {
-  let Spellings = [GCC<"noinline">, Declspec<"noinline">];
-  let Subjects = SubjectList<[Function]>;
-  let Documentation = [Undocumented];
+def NoInline : DeclOrStmtAttr {
+  let Spellings = [GCC<"noinline">, CXX11<"clang", "noinline">,
+   C2x<"clang", "noinline">, Declspec<"noinline">];
+  let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
+C2x<"clang", "noinline">]>];
+  let Documentation = [NoInlineDocs];
+  let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
+ "functions and statements">;
   let SimpleHandler = 1;
 }
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 784e30f04cf52..5f50b49ee2373 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -527,6 +527,29 @@ calls.
   }];
 }
 
+def NoInlineDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+This function attribute suppresses the inlining of a function at the call sites
+of the function.
+
+``[[clang::noinline]]`` spelling can be used as a statement attribute; other
+spellings of the attribute are not supported on statements. If a statement is
+marked ``[[clang::noinline]]`` and contains calls, those calls inside the
+statement will not be inlined by the compiler.
+
+.. code-block:: c
+
+  int example(void) {
+int r;
+[[clang::noinline]] foo();
+[[clang::noinline]] r = bar();
+return r;
+  }
+
+  }];
+}
+
 def MustTailDocs : Documentation {
   let Category = DocCatStmt;
   let Content = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2528777678571..8f631b7c1a8a2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2891,11 +2891,16 @@ def warn_auto_var_is_id : Warning<
   InGroup>;
 
 // Attributes
-def warn_nomerge_attribute_ignored_in_stmt: Warning<
+def warn_attribute_ignored_no_calls_in_stmt: Warning<
   "%0 attribute is ignored because there exists no call expression inside the "
   "statement">,
   InGroup;
 
+def warn_function_attribute_ignored_in_stmt : Warning<
+  "attribute is ignored on this statement as it only applies to functions; "
+  "use '%0' on statements">,
+  InGroup;
+
 def err_musttail_needs_trivial_args : Error<
   "tail call requires that the return value, all parameters, and any "
   "temporaries created by the expression are trivially destructible">;
@@ -4033,6 +4038,10

[clang] 2c91754 - [Clang] Add attributes alloc_size and alloc_align to mm_malloc

2022-02-17 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-02-17T19:59:18+01:00
New Revision: 2c91754a13f333d7fe9f9d3d40fb618e40c48cab

URL: 
https://github.com/llvm/llvm-project/commit/2c91754a13f333d7fe9f9d3d40fb618e40c48cab
DIFF: 
https://github.com/llvm/llvm-project/commit/2c91754a13f333d7fe9f9d3d40fb618e40c48cab.diff

LOG: [Clang] Add attributes alloc_size and alloc_align to mm_malloc

LLVM optimizes source codes with mm_malloc better, especially due to alignment 
info.

alloc align https://clang.llvm.org/docs/AttributeReference.html#alloc-align
alloc size https://clang.llvm.org/docs/AttributeReference.html#alloc-size

Reviewed By: aaron.ballman

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

Added: 
clang/test/Headers/Inputs/include/malloc.h
clang/test/Headers/mm_malloc.c

Modified: 
clang/lib/Headers/mm_malloc.h

Removed: 




diff  --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index 933dbaacade59..d32fe59416277 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -28,9 +28,9 @@ extern "C" int posix_memalign(void **__memptr, size_t 
__alignment, size_t __size
 
 #if !(defined(_WIN32) && defined(_mm_malloc))
 static __inline__ void *__attribute__((__always_inline__, __nodebug__,
-   __malloc__))
-_mm_malloc(size_t __size, size_t __align)
-{
+   __malloc__, __alloc_size__(1),
+   __alloc_align__(2)))
+_mm_malloc(size_t __size, size_t __align) {
   if (__align == 1) {
 return malloc(__size);
   }

diff  --git a/clang/test/Headers/Inputs/include/malloc.h 
b/clang/test/Headers/Inputs/include/malloc.h
new file mode 100644
index 0..590263bb010a3
--- /dev/null
+++ b/clang/test/Headers/Inputs/include/malloc.h
@@ -0,0 +1,7 @@
+#if defined(__MINGW32__)
+void *__mingw_aligned_malloc(size_t, size_t);
+void __mingw_aligned_free(void *);
+#elif defined(_WIN32)
+void *_aligned_malloc(size_t, size_t);
+void _aligned_free(void *);
+#endif

diff  --git a/clang/test/Headers/mm_malloc.c b/clang/test/Headers/mm_malloc.c
new file mode 100644
index 0..a436ff3013bf6
--- /dev/null
+++ b/clang/test/Headers/mm_malloc.c
@@ -0,0 +1,12 @@
+
+// RUN: %clang_cc1 -internal-isystem %S/Inputs/include %s -emit-llvm -O1 
-triple x86_64-linux-gnu -o - | FileCheck %s
+#include 
+
+_Bool align_test(void) {
+// CHECK-LABEL: @align_test(
+// CHECK:ret i1 true
+ void *p = _mm_malloc(1024, 16);
+_Bool ret = ((__UINTPTR_TYPE__)p % 16) == 0;
+_mm_free(p);
+return ret;
+}



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


[clang] b2936ca - [clang] inheritance fix for nomerge attribute

2022-02-11 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-02-11T15:51:08+01:00
New Revision: b2936caf77e00fdb97814960eb1355c2a36c1e70

URL: 
https://github.com/llvm/llvm-project/commit/b2936caf77e00fdb97814960eb1355c2a36c1e70
DIFF: 
https://github.com/llvm/llvm-project/commit/b2936caf77e00fdb97814960eb1355c2a36c1e70.diff

LOG: [clang] inheritance fix for nomerge attribute

Discussed here: https://reviews.llvm.org/D119061#3310822

Reviewed By: aaron.ballman

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

Added: 
clang/test/Sema/attr-nomerge-ast.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/Parser/stmt-attributes.c
clang/test/Parser/stmt-attributes.m
clang/test/Sema/attr-nomerge.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 5156b6b5615b..8e8b7bc16e3b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1390,7 +1390,6 @@ def : MutualExclusions<[Likely, Unlikely]>;
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
-  let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
  "functions and statements">;
   let SimpleHandler = 1;

diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 4f2977f89ce1..63c6fa391459 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -202,7 +202,7 @@ static Attr *handleNoMergeAttr(Sema &S, Stmt *St, const 
ParsedAttr &A,
 
   if (!CEF.foundCallExpr()) {
 S.Diag(St->getBeginLoc(), diag::warn_nomerge_attribute_ignored_in_stmt)
-<< NMA.getSpelling();
+<< A;
 return nullptr;
   }
 

diff  --git a/clang/test/Parser/stmt-attributes.c 
b/clang/test/Parser/stmt-attributes.c
index 52061afd7bc1..86c9255fd47e 100644
--- a/clang/test/Parser/stmt-attributes.c
+++ b/clang/test/Parser/stmt-attributes.c
@@ -80,7 +80,7 @@ void foobar(void) {
   __attribute__((nomerge, unused)) bar(); // expected-error {{expected 
identifier or '('}}
   __attribute__((nomerge(1, 2))) bar();   // expected-error {{'nomerge' 
attribute takes no arguments}}
   int x;
-  __attribute__((nomerge)) x = 10; // expected-warning {{nomerge attribute is 
ignored because there exists no call expression inside the statement}}
+  __attribute__((nomerge)) x = 10; // expected-warning {{'nomerge' attribute 
is ignored because there exists no call expression inside the statement}}
 
   __attribute__((nomerge)) label : bar(); // expected-error {{'nomerge' 
attribute only applies to functions and statements}}
 }

diff  --git a/clang/test/Parser/stmt-attributes.m 
b/clang/test/Parser/stmt-attributes.m
index a138580d6717..227ea9dc2fac 100644
--- a/clang/test/Parser/stmt-attributes.m
+++ b/clang/test/Parser/stmt-attributes.m
@@ -29,13 +29,13 @@ - (void)bar {
   // expected-error@-3 {{expected identifier or '('}}
   // expected-note@-4 {{to match this '['}}
   __attribute__((nomerge)) [self foo];
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
   __attribute__((nomerge)) [getTest() foo];
 
   __attribute__(()) ^{};
   // expected-error@-1 {{expected identifier or '('}}
   __attribute__((nomerge)) ^{};
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
   __attribute__((nomerge)) ^{ [self foo]; }();
 
   __attribute__(()) @try {
@@ -49,9 +49,9 @@ - (void)bar {
   }
 
   __attribute__((nomerge)) (__bridge void *)self;
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
 
   __attribute__((nomerge)) self.hasFoobar;
-  // expected-warning@-1 {{nomerge attribute is ignored because there exists 
no call expression inside the statement}}
+  // expected-warning@-1 {{'nomerge' attribute is ignored because there exists 
no call expression inside the statement}}
 }
 @end

diff  --git a/clang/test/Sema/attr-nomerge-ast.cpp 
b/clang/test/Sema/attr-nomerge-ast.cpp
new file mode 100644
index ..c440cf760b16
--- /dev/null
+++ b/clang/test/Sema/attr-nomerge-ast.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
+
+[[clang::nomerge]] void func();
+[[clang::nomerge]] void func();
+void func();
+[[clang::nomerge]] void func() {}
+
+// CHECK: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr
+// 

[clang] 7119f76 - [clang] added allocsize attribute to allocation functions

2022-02-05 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-02-05T14:26:35+01:00
New Revision: 7119f76c47797391fddcfcb60f29e70a2b424713

URL: 
https://github.com/llvm/llvm-project/commit/7119f76c47797391fddcfcb60f29e70a2b424713
DIFF: 
https://github.com/llvm/llvm-project/commit/7119f76c47797391fddcfcb60f29e70a2b424713.diff

LOG: [clang] added allocsize attribute to allocation functions

Added: 
clang/test/CodeGen/allocs-fns-allocsize.c

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f2871d82b0409..fce33991c4aa4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15340,6 +15340,26 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
 default:
   break;
 }
+
+// Add allocsize attribute for allocation functions.
+switch (BuiltinID) {
+case Builtin::BIcalloc:
+  FD->addAttr(AllocSizeAttr::CreateImplicit(
+  Context, ParamIdx(1, FD), ParamIdx(2, FD), FD->getLocation()));
+  break;
+case Builtin::BImemalign:
+case Builtin::BIaligned_alloc:
+case Builtin::BIrealloc:
+  FD->addAttr(AllocSizeAttr::CreateImplicit(Context, ParamIdx(2, FD),
+ParamIdx(), 
FD->getLocation()));
+  break;
+case Builtin::BImalloc:
+  FD->addAttr(AllocSizeAttr::CreateImplicit(Context, ParamIdx(1, FD),
+ParamIdx(), 
FD->getLocation()));
+  break;
+default:
+  break;
+}
   }
 
   AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);

diff  --git a/clang/test/CodeGen/allocs-fns-allocsize.c 
b/clang/test/CodeGen/allocs-fns-allocsize.c
new file mode 100644
index 0..27133b252372e
--- /dev/null
+++ b/clang/test/CodeGen/allocs-fns-allocsize.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+void *malloc(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+void *aligned_alloc(size_t, size_t);
+void *memalign(size_t, size_t);
+
+void *malloc_test(size_t n) {
+  return malloc(n);
+}
+
+void *calloc_test(size_t e, size_t n) {
+  return calloc(e, n);
+}
+
+void *realloc_test(void *p, size_t n) {
+  return realloc(p, n);
+}
+
+void *aligned_alloc_test(size_t n, size_t a) {
+  return aligned_alloc(a, n);
+}
+
+void *memalign_test(size_t n, size_t a) {
+  return memalign(a, n);
+}
+
+// CHECK: @malloc(i64 noundef) #1
+// CHECK: @calloc(i64 noundef, i64 noundef) #2
+// CHECK: @realloc(i8* noundef, i64 noundef) #3
+// CHECK: @aligned_alloc(i64 noundef, i64 noundef) #3
+// CHECK: @memalign(i64 noundef, i64 noundef) #3
+
+// CHECK: attributes #1 = { allocsize(0)
+// CHECK: attributes #2 = { allocsize(0,1)
+// CHECK: attributes #3 = { allocsize(1)



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


[clang] 74b1c4c - [clang] added alloc allign attr to memalign

2022-02-05 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-02-05T11:46:56+01:00
New Revision: 74b1c4c36740fe94953ef648e40df7dd9e9a9c7d

URL: 
https://github.com/llvm/llvm-project/commit/74b1c4c36740fe94953ef648e40df7dd9e9a9c7d
DIFF: 
https://github.com/llvm/llvm-project/commit/74b1c4c36740fe94953ef648e40df7dd9e9a9c7d.diff

LOG: [clang] added alloc allign attr to memalign

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGen/alloc-fns-alignment.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a86947aa5fbfc..f2871d82b0409 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15315,6 +15315,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) 
{
 
 // Add known guaranteed alignment for allocation functions.
 switch (BuiltinID) {
+case Builtin::BImemalign:
 case Builtin::BIaligned_alloc:
   if (!FD->hasAttr())
 FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD),
@@ -15322,7 +15323,6 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) 
{
   LLVM_FALLTHROUGH;
 case Builtin::BIcalloc:
 case Builtin::BImalloc:
-case Builtin::BImemalign:
 case Builtin::BIrealloc:
 case Builtin::BIstrdup:
 case Builtin::BIstrndup: {

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
index 8ab0610accf03..29d6e9e4fb380 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -6,6 +6,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-aligned_alloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-ALIGNED_ALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-memalign 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MEMALIGN
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -13,6 +14,7 @@ void *malloc(size_t);
 void *calloc(size_t, size_t);
 void *realloc(void *, size_t);
 void *aligned_alloc(size_t, size_t);
+void *memalign(size_t, size_t);
 
 void *malloc_test(size_t n) {
   return malloc(n);
@@ -30,6 +32,10 @@ void *aligned_alloc_variable_test(size_t n, size_t a) {
   return aligned_alloc(a, n);
 }
 
+void *memalign_variable_test(size_t n, size_t a) {
+  return memalign(a, n);
+}
+
 void *aligned_alloc_constant_test(size_t n) {
   return aligned_alloc(8, n);
 }
@@ -38,6 +44,10 @@ void *aligned_alloc_large_constant_test(size_t n) {
   return aligned_alloc(4096, n);
 }
 
+void *memalign_large_constant_test(size_t n) {
+  return memalign(4096, n);
+}
+
 // CHECK-LABEL: @malloc_test
 // ALIGN16: align 16 i8* @malloc
 
@@ -51,12 +61,19 @@ void *aligned_alloc_large_constant_test(size_t n) {
 // ALIGN16:  %[[ALLOCATED:.*]] = call align 16 i8* 
@aligned_alloc({{i32|i64}} noundef %[[ALIGN:.*]], {{i32|i64}} noundef 
%[[NBYTES:.*]])
 // ALIGN16-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[ALLOCATED]], 
{{i32|i64}} %[[ALIGN]]) ]
 
+// CHECK-LABEL: @memalign_variable_test
+// ALIGN16:  %[[ALLOCATED:.*]] = call align 16 i8* @memalign({{i32|i64}} 
noundef %[[ALIGN:.*]], {{i32|i64}} noundef %[[NBYTES:.*]])
+// ALIGN16-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[ALLOCATED]], 
{{i32|i64}} %[[ALIGN]]) ]
+
 // CHECK-LABEL: @aligned_alloc_constant_test
 // ALIGN16: align 16 i8* @aligned_alloc
 
 // CHECK-LABEL: @aligned_alloc_large_constant_test
 // ALIGN16: align 4096 i8* @aligned_alloc
 
+// CHECK-LABEL: @memalign_large_constant_test
+// ALIGN16: align 4096 i8* @memalign
+
 // CHECK-LABEL: @malloc_test
 // ALIGN8: align 8 i8* @malloc
 
@@ -69,13 +86,20 @@ void *aligned_alloc_large_constant_test(size_t n) {
 // CHECK-LABEL: @aligned_alloc_variable_test
 // ALIGN8: align 8 i8* @aligned_alloc
 
+// CHECK-LABEL: @memalign_variable_test
+// ALIGN8: align 8 i8* @memalign
+
 // CHECK-LABEL: @aligned_alloc_constant_test
 // ALIGN8: align 8 i8* @aligned_alloc
 
 // CHECK-LABEL: @aligned_alloc_large_constant_test
 // ALIGN8: align 4096 i8* @aligned_alloc
 
+// CHECK-LABEL: @memalign_large_constant_test
+// ALIGN8: align 4096 i8* @memalign
+
 // NOBUILTIN-MALLOC: declare i8* @malloc
 // NOBUILTIN-CALLOC: declare i8* @calloc
 // NOBUILTIN-REALLOC: declare i8* @realloc
 // NOBUILTIN-ALIGNED_ALLOC: declare i8* @aligned_alloc
+// NOBUILTIN-MEMALIGN: declare i8* @memalign



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


[clang] 623b66e - [Clang][NFC] Added testcase from #49549

2022-01-31 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-01-31T23:45:56+01:00
New Revision: 623b66eded4b1ab2fbb962d3841899458bac6693

URL: 
https://github.com/llvm/llvm-project/commit/623b66eded4b1ab2fbb962d3841899458bac6693
DIFF: 
https://github.com/llvm/llvm-project/commit/623b66eded4b1ab2fbb962d3841899458bac6693.diff

LOG: [Clang][NFC] Added testcase from #49549

The issue is fixed in trunk, so add testcase to avoid regression in the future.

Added: 


Modified: 
clang/test/SemaCXX/attr-likelihood.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/attr-likelihood.cpp 
b/clang/test/SemaCXX/attr-likelihood.cpp
index f7503fed49b93..642d62fa89826 100644
--- a/clang/test/SemaCXX/attr-likelihood.cpp
+++ b/clang/test/SemaCXX/attr-likelihood.cpp
@@ -159,4 +159,18 @@ constexpr int constexpr_function() {
   [[likely]] return 0;
 }
 static_assert(constexpr_function() == 0);
+
+constexpr double pow(double x, long long n) noexcept {
+if (n > 0) [[likely]]
+return x * pow(x, n - 1);
+else [[unlikely]]
+return 1;
+}
+constexpr long long fact(long long n) noexcept {
+if (n > 1) [[likely]]
+return n * fact(n - 1);
+else [[unlikely]]
+return 1;
+}
+
 #endif



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


[clang] fe30370 - Reland "[AlwaysInliner] Enable call site inlining to make flatten attribute working again (#53360)"

2022-01-25 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-01-26T01:11:06+01:00
New Revision: fe30370b007e7efa1bd1f39a3189b27ae4e5fcbe

URL: 
https://github.com/llvm/llvm-project/commit/fe30370b007e7efa1bd1f39a3189b27ae4e5fcbe
DIFF: 
https://github.com/llvm/llvm-project/commit/fe30370b007e7efa1bd1f39a3189b27ae4e5fcbe.diff

LOG: Reland "[AlwaysInliner] Enable call site inlining to make flatten 
attribute working again (#53360)"

Added: 


Modified: 
clang/test/CodeGen/flatten.c
clang/test/CodeGenCXX/flatten.cpp
llvm/lib/Transforms/IPO/AlwaysInliner.cpp
llvm/test/Transforms/Inline/always-inline.ll

Removed: 




diff  --git a/clang/test/CodeGen/flatten.c b/clang/test/CodeGen/flatten.c
index 287d4f2a46b65..4e762223de486 100644
--- a/clang/test/CodeGen/flatten.c
+++ b/clang/test/CodeGen/flatten.c
@@ -1,9 +1,3 @@
-// UNSUPPORTED: experimental-new-pass-manager
-// Currently, 
diff erent code seems to be intentionally generated under the new
-// PM since we alwaysinline functions and not callsites under new PM.
-// Under new PM, f() will not be inlined from g() since f is not marked as
-// alwaysinline.
-
 // RUN: %clang_cc1 -triple=x86_64-linux-gnu %s -emit-llvm -o - | FileCheck %s
 
 void f(void) {}

diff  --git a/clang/test/CodeGenCXX/flatten.cpp 
b/clang/test/CodeGenCXX/flatten.cpp
index 7a6484591aaa0..e988d6d726dd7 100644
--- a/clang/test/CodeGenCXX/flatten.cpp
+++ b/clang/test/CodeGenCXX/flatten.cpp
@@ -1,7 +1,3 @@
-// UNSUPPORTED: experimental-new-pass-manager
-// See the comment for CodeGen/flatten.c on why this is unsupported with the 
new
-// PM.
-
 // RUN: %clang_cc1 -triple=x86_64-linux-gnu -std=c++11 %s -emit-llvm -o - | 
FileCheck %s
 
 void f(void) {}

diff  --git a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp 
b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
index 7acc9b266ad82..a6d9ce1033f3c 100644
--- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -54,13 +54,13 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
 if (F.isPresplitCoroutine())
   continue;
 
-if (!F.isDeclaration() && F.hasFnAttribute(Attribute::AlwaysInline) &&
-isInlineViable(F).isSuccess()) {
+if (!F.isDeclaration() && isInlineViable(F).isSuccess()) {
   Calls.clear();
 
   for (User *U : F.users())
 if (auto *CB = dyn_cast(U))
-  if (CB->getCalledFunction() == &F)
+  if (CB->getCalledFunction() == &F &&
+  CB->hasFnAttr(Attribute::AlwaysInline))
 Calls.insert(CB);
 
   for (CallBase *CB : Calls) {
@@ -92,10 +92,12 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
 Changed = true;
   }
 
-  // Remember to try and delete this function afterward. This both avoids
-  // re-walking the rest of the module and avoids dealing with any iterator
-  // invalidation issues while deleting functions.
-  InlinedFunctions.push_back(&F);
+  if (F.hasFnAttribute(Attribute::AlwaysInline)) {
+// Remember to try and delete this function afterward. This both avoids
+// re-walking the rest of the module and avoids dealing with any
+// iterator invalidation issues while deleting functions.
+InlinedFunctions.push_back(&F);
+  }
 }
   }
 

diff  --git a/llvm/test/Transforms/Inline/always-inline.ll 
b/llvm/test/Transforms/Inline/always-inline.ll
index 0fcf956199c46..f947bdbd87347 100644
--- a/llvm/test/Transforms/Inline/always-inline.ll
+++ b/llvm/test/Transforms/Inline/always-inline.ll
@@ -1,14 +1,11 @@
-; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
+; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | 
FileCheck %s --check-prefix=CHECK
 ;
 ; Ensure the threshold has no impact on these decisions.
-; RUN: opt < %s -inline-threshold=2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
-; RUN: opt < %s -inline-threshold=-2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
+; RUN: opt < %s -inline-threshold=2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK
+; RUN: opt < %s -inline-threshold=-2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK
 ;
 ; The new pass manager doesn't re-use any threshold based infrastructure for
-; the always inliner, but test that we get the correct result. The new PM
-; always inliner also doesn't support inlining call-site alwaysinline
-; annotations. It isn't clear that this is a reasonable use case for
-; 'alwaysinline'.
+; the always inliner, but test that we get the correct result.
 ; RUN: opt < %s -inline-threshold=0 -passes=always-inline -S | FileCheck %s 
--check-prefix=CHECK
 ; RUN: opt < %s -inline-threshold=2000 -passes=always-inline -S | 
FileCheck %s --check-p

[clang] 90f185c - Revert "[AlwaysInliner] Enable call site inlining to make flatten attribute working again (#53360)"

2022-01-25 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-01-25T23:13:46+01:00
New Revision: 90f185c964d05e9f3081bb4acc734b3932db221a

URL: 
https://github.com/llvm/llvm-project/commit/90f185c964d05e9f3081bb4acc734b3932db221a
DIFF: 
https://github.com/llvm/llvm-project/commit/90f185c964d05e9f3081bb4acc734b3932db221a.diff

LOG: Revert "[AlwaysInliner] Enable call site inlining to make flatten 
attribute working again (#53360)"

This reverts commit ceec4383681c42bfd3d06a6913ce7554bea160b0. Clang tests fail.

Added: 


Modified: 
clang/test/CodeGen/flatten.c
clang/test/CodeGenCXX/flatten.cpp
llvm/lib/Transforms/IPO/AlwaysInliner.cpp
llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
llvm/test/Transforms/Inline/always-inline.ll

Removed: 




diff  --git a/clang/test/CodeGen/flatten.c b/clang/test/CodeGen/flatten.c
index 4e762223de486..287d4f2a46b65 100644
--- a/clang/test/CodeGen/flatten.c
+++ b/clang/test/CodeGen/flatten.c
@@ -1,3 +1,9 @@
+// UNSUPPORTED: experimental-new-pass-manager
+// Currently, 
diff erent code seems to be intentionally generated under the new
+// PM since we alwaysinline functions and not callsites under new PM.
+// Under new PM, f() will not be inlined from g() since f is not marked as
+// alwaysinline.
+
 // RUN: %clang_cc1 -triple=x86_64-linux-gnu %s -emit-llvm -o - | FileCheck %s
 
 void f(void) {}

diff  --git a/clang/test/CodeGenCXX/flatten.cpp 
b/clang/test/CodeGenCXX/flatten.cpp
index e988d6d726dd7..7a6484591aaa0 100644
--- a/clang/test/CodeGenCXX/flatten.cpp
+++ b/clang/test/CodeGenCXX/flatten.cpp
@@ -1,3 +1,7 @@
+// UNSUPPORTED: experimental-new-pass-manager
+// See the comment for CodeGen/flatten.c on why this is unsupported with the 
new
+// PM.
+
 // RUN: %clang_cc1 -triple=x86_64-linux-gnu -std=c++11 %s -emit-llvm -o - | 
FileCheck %s
 
 void f(void) {}

diff  --git a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp 
b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
index 8f20f59b5e4d7..7acc9b266ad82 100644
--- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -54,13 +54,13 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
 if (F.isPresplitCoroutine())
   continue;
 
-if (!F.isDeclaration() && isInlineViable(F).isSuccess()) {
+if (!F.isDeclaration() && F.hasFnAttribute(Attribute::AlwaysInline) &&
+isInlineViable(F).isSuccess()) {
   Calls.clear();
 
   for (User *U : F.users())
 if (auto *CB = dyn_cast(U))
-  if (CB->getCalledFunction() == &F &&
-  CB->hasFnAttr(Attribute::AlwaysInline))
+  if (CB->getCalledFunction() == &F)
 Calls.insert(CB);
 
   for (CallBase *CB : Calls) {

diff  --git a/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll 
b/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
index 5d62747180233..d805d7549231d 100644
--- a/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
+++ b/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
@@ -3,7 +3,9 @@
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.12.0"
 
-; CHECK-NOT: define {{.*}} @f(i8* %buffer, i32* %array)
+; CHECK: define internal { i8*, i32 } @f(i8* %buffer, i32* %array)
+; CHECK-NEXT: entry:
+; CHECK-NEXT:  unreachable
 
 define internal {i8*, i32} @f(i8* %buffer, i32* %array) {
 entry:

diff  --git a/llvm/test/Transforms/Inline/always-inline.ll 
b/llvm/test/Transforms/Inline/always-inline.ll
index 8eb3d020f6634..0fcf956199c46 100644
--- a/llvm/test/Transforms/Inline/always-inline.ll
+++ b/llvm/test/Transforms/Inline/always-inline.ll
@@ -1,11 +1,14 @@
-; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | 
FileCheck %s --check-prefix=CHECK
+; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
 ;
 ; Ensure the threshold has no impact on these decisions.
-; RUN: opt < %s -inline-threshold=2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK
-; RUN: opt < %s -inline-threshold=-2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK
+; RUN: opt < %s -inline-threshold=2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
+; RUN: opt < %s -inline-threshold=-2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
 ;
 ; The new pass manager doesn't re-use any threshold based infrastructure for
-; the always inliner, but test that we get the correct result.
+; the always inliner, but test that we get the correct result. The new PM
+; always inliner also doesn't support inlining call-site alwaysinline
+; annotations. It isn't clear that this is a reasonable use case for
+; 'alwaysinline'.
 ; RUN: opt < %s -inline-threshold=0 -passes=always-inline -S | FileChec

[clang] ceec438 - [AlwaysInliner] Enable call site inlining to make flatten attribute working again (#53360)

2022-01-25 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2022-01-25T22:55:30+01:00
New Revision: ceec4383681c42bfd3d06a6913ce7554bea160b0

URL: 
https://github.com/llvm/llvm-project/commit/ceec4383681c42bfd3d06a6913ce7554bea160b0
DIFF: 
https://github.com/llvm/llvm-project/commit/ceec4383681c42bfd3d06a6913ce7554bea160b0.diff

LOG: [AlwaysInliner] Enable call site inlining to make flatten attribute 
working again (#53360)

Problem: Migration to new PM broke flatten attribute.

This is one use case why LLVM should support inlining call-site with 
alwaysinline.  The flatten attribute is nowdays broken, so we should either 
land patch like this one or remove everything related to  flatten attribute 
from Clang.

Second use case is something like "per call site inlining intrinsics" to 
control inlining even more; mentioned in
https://lists.llvm.org/pipermail/cfe-dev/2018-September/059232.html

Fixes https://github.com/llvm/llvm-project/issues/53360

Reviewed By: aeubanks

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

Added: 


Modified: 
clang/test/CodeGen/flatten.c
clang/test/CodeGenCXX/flatten.cpp
llvm/lib/Transforms/IPO/AlwaysInliner.cpp
llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
llvm/test/Transforms/Inline/always-inline.ll

Removed: 




diff  --git a/clang/test/CodeGen/flatten.c b/clang/test/CodeGen/flatten.c
index 287d4f2a46b65..4e762223de486 100644
--- a/clang/test/CodeGen/flatten.c
+++ b/clang/test/CodeGen/flatten.c
@@ -1,9 +1,3 @@
-// UNSUPPORTED: experimental-new-pass-manager
-// Currently, 
diff erent code seems to be intentionally generated under the new
-// PM since we alwaysinline functions and not callsites under new PM.
-// Under new PM, f() will not be inlined from g() since f is not marked as
-// alwaysinline.
-
 // RUN: %clang_cc1 -triple=x86_64-linux-gnu %s -emit-llvm -o - | FileCheck %s
 
 void f(void) {}

diff  --git a/clang/test/CodeGenCXX/flatten.cpp 
b/clang/test/CodeGenCXX/flatten.cpp
index 7a6484591aaa0..e988d6d726dd7 100644
--- a/clang/test/CodeGenCXX/flatten.cpp
+++ b/clang/test/CodeGenCXX/flatten.cpp
@@ -1,7 +1,3 @@
-// UNSUPPORTED: experimental-new-pass-manager
-// See the comment for CodeGen/flatten.c on why this is unsupported with the 
new
-// PM.
-
 // RUN: %clang_cc1 -triple=x86_64-linux-gnu -std=c++11 %s -emit-llvm -o - | 
FileCheck %s
 
 void f(void) {}

diff  --git a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp 
b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
index 7acc9b266ad82..8f20f59b5e4d7 100644
--- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -54,13 +54,13 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
 if (F.isPresplitCoroutine())
   continue;
 
-if (!F.isDeclaration() && F.hasFnAttribute(Attribute::AlwaysInline) &&
-isInlineViable(F).isSuccess()) {
+if (!F.isDeclaration() && isInlineViable(F).isSuccess()) {
   Calls.clear();
 
   for (User *U : F.users())
 if (auto *CB = dyn_cast(U))
-  if (CB->getCalledFunction() == &F)
+  if (CB->getCalledFunction() == &F &&
+  CB->hasFnAttr(Attribute::AlwaysInline))
 Calls.insert(CB);
 
   for (CallBase *CB : Calls) {

diff  --git a/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll 
b/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
index d805d7549231d..5d62747180233 100644
--- a/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
+++ b/llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll
@@ -3,9 +3,7 @@
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.12.0"
 
-; CHECK: define internal { i8*, i32 } @f(i8* %buffer, i32* %array)
-; CHECK-NEXT: entry:
-; CHECK-NEXT:  unreachable
+; CHECK-NOT: define {{.*}} @f(i8* %buffer, i32* %array)
 
 define internal {i8*, i32} @f(i8* %buffer, i32* %array) {
 entry:

diff  --git a/llvm/test/Transforms/Inline/always-inline.ll 
b/llvm/test/Transforms/Inline/always-inline.ll
index 0fcf956199c46..8eb3d020f6634 100644
--- a/llvm/test/Transforms/Inline/always-inline.ll
+++ b/llvm/test/Transforms/Inline/always-inline.ll
@@ -1,14 +1,11 @@
-; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
+; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | 
FileCheck %s --check-prefix=CHECK
 ;
 ; Ensure the threshold has no impact on these decisions.
-; RUN: opt < %s -inline-threshold=2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
-; RUN: opt < %s -inline-threshold=-2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
+; RUN: opt < %s -inline-threshold=2000 -always-inline -enable-new-pm=0 -S 
| FileCheck %s --check-prefix=CHECK
+; RUN: opt < %s -inline-threshold=-2000 -

[clang] fb84aa2 - Fixed warnings in target/parser codes produced by -Wbitwise-instead-of-logicala

2021-10-03 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-10-03T15:04:01+02:00
New Revision: fb84aa2a8f52272cd0cb9510bac5404a3d4ec565

URL: 
https://github.com/llvm/llvm-project/commit/fb84aa2a8f52272cd0cb9510bac5404a3d4ec565
DIFF: 
https://github.com/llvm/llvm-project/commit/fb84aa2a8f52272cd0cb9510bac5404a3d4ec565.diff

LOG: Fixed warnings in target/parser codes produced by 
-Wbitwise-instead-of-logicala

Added: 


Modified: 
clang/lib/Lex/PPExpressions.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
llvm/lib/Target/Lanai/LanaiAluCode.h
llvm/lib/Target/Mips/MipsSubtarget.cpp

Removed: 




diff  --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index 1ebfae606a588..424cccfdb9eef 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -662,7 +662,7 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned 
MinPrec,
 case tok::ampamp: // Logical && does not do UACs.
   break;  // No UAC
 default:
-  Res.setIsUnsigned(LHS.isUnsigned()|RHS.isUnsigned());
+  Res.setIsUnsigned(LHS.isUnsigned() || RHS.isUnsigned());
   // If this just promoted something from signed to unsigned, and if the
   // value was negative, warn about it.
   if (ValueLive && Res.isUnsigned()) {
@@ -822,7 +822,7 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned 
MinPrec,
 
   // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
   // either operand is unsigned.
-  Res.setIsUnsigned(RHS.isUnsigned() | AfterColonVal.isUnsigned());
+  Res.setIsUnsigned(RHS.isUnsigned() || AfterColonVal.isUnsigned());
 
   // Figure out the precedence of the token after the : part.
   PeekPrec = getPrecedence(PeekTok.getKind());

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 75dcc66af2b8a..ebca7f3083810 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -8529,8 +8529,8 @@ bool 
LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) {
   assert(Lex.getKind() == lltok::kw_funcFlags);
   Lex.Lex();
 
-  if ((int)parseToken(lltok::colon, "expected ':' in funcFlags") |
-  (int)parseToken(lltok::lparen, "expected '(' in funcFlags"))
+  if (parseToken(lltok::colon, "expected ':' in funcFlags") ||
+  parseToken(lltok::lparen, "expected '(' in funcFlags"))
 return true;
 
   do {
@@ -8609,7 +8609,7 @@ bool 
LLParser::parseOptionalCalls(std::vector &Calls) {
   assert(Lex.getKind() == lltok::kw_calls);
   Lex.Lex();
 
-  if (parseToken(lltok::colon, "expected ':' in calls") |
+  if (parseToken(lltok::colon, "expected ':' in calls") ||
   parseToken(lltok::lparen, "expected '(' in calls"))
 return true;
 
@@ -8701,8 +8701,8 @@ bool LLParser::parseOptionalVTableFuncs(VTableFuncList 
&VTableFuncs) {
   assert(Lex.getKind() == lltok::kw_vTableFuncs);
   Lex.Lex();
 
-  if ((int)parseToken(lltok::colon, "expected ':' in vTableFuncs") |
-  (int)parseToken(lltok::lparen, "expected '(' in vTableFuncs"))
+  if (parseToken(lltok::colon, "expected ':' in vTableFuncs") ||
+  parseToken(lltok::lparen, "expected '(' in vTableFuncs"))
 return true;
 
   IdToIndexMapType IdToIndexMap;

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
index 3c4191a485603..50e515d6c4fe1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
@@ -1826,8 +1826,9 @@ bool 
AMDGPUInstructionSelector::selectG_SELECT(MachineInstr &I) const {
 .add(I.getOperand(2))
 .add(I.getOperand(3));
 
-bool Ret = constrainSelectedInstRegOperands(*Select, TII, TRI, RBI) |
-   constrainSelectedInstRegOperands(*CopySCC, TII, TRI, RBI);
+bool Ret = false;
+Ret |= constrainSelectedInstRegOperands(*Select, TII, TRI, RBI);
+Ret |= constrainSelectedInstRegOperands(*CopySCC, TII, TRI, RBI);
 I.eraseFromParent();
 return Ret;
   }

diff  --git a/llvm/lib/Target/Lanai/LanaiAluCode.h 
b/llvm/lib/Target/Lanai/LanaiAluCode.h
index 728332bff00b8..69be055427231 100644
--- a/llvm/lib/Target/Lanai/LanaiAluCode.h
+++ b/llvm/lib/Target/Lanai/LanaiAluCode.h
@@ -70,7 +70,7 @@ inline static unsigned makePostOp(unsigned AluOp) {
 }
 
 inline static bool modifiesOp(unsigned AluOp) {
-  return isPreOp(AluOp) | isPostOp(AluOp);
+  return isPreOp(AluOp) || isPostOp(AluOp);
 }
 
 inline static const char *lanaiAluCodeToString(unsigned AluOp) {

diff  --git a/llvm/lib/Target/Mips/MipsSubtarget.cpp 
b/llvm/lib/Target/Mips/MipsSubtarget.cpp
index 8bb9d75e9173a..0ae2d584a1a6c 100644
--- a/llvm/lib/Target/Mips/MipsSubtarget.cpp
+++ b/llvm/lib/Target/Mips/MipsSubtarget.cpp
@@ -78,7 +78,7 @@ MipsSubtarget::MipsSubtarget(const Triple &TT, StringRef CPU, 

[clang] a76355d - Unbreak hexagon-check-builtins.c due to rGb1fcca388441

2021-10-03 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-10-03T13:19:34+02:00
New Revision: a76355d570a96ebcb4e790bc06020f184351500d

URL: 
https://github.com/llvm/llvm-project/commit/a76355d570a96ebcb4e790bc06020f184351500d
DIFF: 
https://github.com/llvm/llvm-project/commit/a76355d570a96ebcb4e790bc06020f184351500d.diff

LOG: Unbreak hexagon-check-builtins.c due to rGb1fcca388441

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index bdd9fb495da2..66450f61c091 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2988,8 +2988,8 @@ bool Sema::CheckHexagonBuiltinArgument(unsigned 
BuiltinID, CallExpr *TheCall) {
   unsigned M = 1 << A.Align;
   Min *= M;
   Max *= M;
-  Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max) ||
-   SemaBuiltinConstantArgMultiple(TheCall, A.OpNum, M);
+  Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max);
+  Error |= SemaBuiltinConstantArgMultiple(TheCall, A.OpNum, M);
 }
   }
   return Error;



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


[clang] f59cc95 - Reland "[Clang] Extend -Wbool-operation to warn about bitwise and of bools with side effects"

2021-10-03 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-10-03T13:05:09+02:00
New Revision: f59cc9542bfb461d16ad12b2cc4be4abbfd9d96e

URL: 
https://github.com/llvm/llvm-project/commit/f59cc9542bfb461d16ad12b2cc4be4abbfd9d96e
DIFF: 
https://github.com/llvm/llvm-project/commit/f59cc9542bfb461d16ad12b2cc4be4abbfd9d96e.diff

LOG: Reland "[Clang] Extend -Wbool-operation to warn about bitwise and of bools 
with side effects"

This reverts commit a4933f57f3f0a45e1db1075f7285f0761a80fc06. New warnings were 
fixed.

Added: 
clang/test/Sema/warn-bitwise-and-bool.c
clang/test/Sema/warn-bitwise-or-bool.c

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Misc/warning-wall.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 761b323d0616..d9db3482dbda 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -64,7 +64,8 @@ def StringConversion : DiagGroup<"string-conversion">;
 def SignConversion : DiagGroup<"sign-conversion">;
 def PointerBoolConversion : DiagGroup<"pointer-bool-conversion">;
 def UndefinedBoolConversion : DiagGroup<"undefined-bool-conversion">;
-def BoolOperation : DiagGroup<"bool-operation">;
+def BitwiseInsteadOfLogical : DiagGroup<"bitwise-instead-of-logical">;
+def BoolOperation : DiagGroup<"bool-operation", [BitwiseInsteadOfLogical]>;
 def BoolConversion : DiagGroup<"bool-conversion", [PointerBoolConversion,
UndefinedBoolConversion]>;
 def IntConversion : DiagGroup<"int-conversion">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1d4ea92c6520..c71a00b18432 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -66,6 +66,7 @@ def warn_infinite_recursive_function : Warning<
 def warn_comma_operator : Warning<"possible misuse of comma operator here">,
   InGroup>, DefaultIgnore;
 def note_cast_to_void : Note<"cast expression to void to silence warning">;
+def note_cast_operand_to_int : Note<"cast one or both operands to int to 
silence this warning">;
 
 // Constant expressions
 def err_expr_not_ice : Error<
@@ -7423,6 +7424,9 @@ def note_member_declared_here : Note<
   "member %0 declared here">;
 def note_member_first_declared_here : Note<
   "member %0 first declared here">;
+def warn_bitwise_instead_of_logical : Warning<
+  "use of bitwise '%0' with boolean operands">,
+  InGroup, DefaultIgnore;
 def warn_bitwise_negation_bool : Warning<
   "bitwise negation of a boolean expression%select{;| always evaluates to 
'true';}0 "
   "did you mean logical negation?">,

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 615ba1aef8e6..bdd9fb495da2 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -13249,6 +13249,20 @@ static void AnalyzeImplicitConversions(
   << OrigE->getSourceRange() << T->isBooleanType()
   << FixItHint::CreateReplacement(UO->getBeginLoc(), "!");
 
+  if (const auto *BO = dyn_cast(SourceExpr))
+if ((BO->getOpcode() == BO_And || BO->getOpcode() == BO_Or) &&
+BO->getLHS()->isKnownToHaveBooleanValue() &&
+BO->getRHS()->isKnownToHaveBooleanValue() &&
+BO->getLHS()->HasSideEffects(S.Context) &&
+BO->getRHS()->HasSideEffects(S.Context)) {
+  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
+  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
+  << FixItHint::CreateReplacement(
+ BO->getOperatorLoc(),
+ (BO->getOpcode() == BO_And ? "&&" : "||"));
+  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+}
+
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
   if (auto *CO = dyn_cast(SourceExpr)) {

diff  --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index a3686fb96a4c..a4a79bec934a 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -4,6 +4,7 @@ RUN: FileCheck --input-file=%t %s
  CHECK:-Wall
 CHECK-NEXT:  -Wmost
 CHECK-NEXT:-Wbool-operation
+CHECK-NEXT:-Wbitwise-instead-of-logical
 CHECK-NEXT:-Wchar-subscripts
 CHECK-NEXT:-Wcomment
 CHECK-NEXT:-Wdelete-non-virtual-dtor

diff  --git a/clang/test/Sema/warn-bitwise-and-bool.c 
b/clang/test/Sema/warn-bitwise-and-bool.c
new file mode 100644
index ..6bec1be1abde
--- /dev/null
+++ b/clang/test/Sema/warn-bitwise-and-bool.c
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wbool-operation %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RU

[clang] b1fcca3 - Fixed warnings in LLVM produced by -Wbitwise-instead-of-logical

2021-10-03 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-10-03T13:04:18+02:00
New Revision: b1fcca38844138d1950e1b34eb2be65b3bfc7352

URL: 
https://github.com/llvm/llvm-project/commit/b1fcca38844138d1950e1b34eb2be65b3bfc7352
DIFF: 
https://github.com/llvm/llvm-project/commit/b1fcca38844138d1950e1b34eb2be65b3bfc7352.diff

LOG: Fixed warnings in LLVM produced by -Wbitwise-instead-of-logical

Added: 


Modified: 
clang/lib/AST/Type.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExpr.cpp
llvm/unittests/Support/TargetParserTest.cpp
llvm/utils/TableGen/CodeGenDAGPatterns.cpp

Removed: 




diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 112218d6eb36..de57b40b221a 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3759,8 +3759,8 @@ class CachedProperties {
 
   friend CachedProperties merge(CachedProperties L, CachedProperties R) {
 Linkage MergedLinkage = minLinkage(L.L, R.L);
-return CachedProperties(MergedLinkage,
- L.hasLocalOrUnnamedType() | 
R.hasLocalOrUnnamedType());
+return CachedProperties(MergedLinkage, L.hasLocalOrUnnamedType() ||
+   R.hasLocalOrUnnamedType());
   }
 };
 

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5c92e1e7e073..a62a4d60830d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -668,9 +668,9 @@ bool CodeGenFunction::isVptrCheckRequired(TypeCheckKind 
TCK, QualType Ty) {
 }
 
 bool CodeGenFunction::sanitizePerformTypeCheck() const {
-  return SanOpts.has(SanitizerKind::Null) |
- SanOpts.has(SanitizerKind::Alignment) |
- SanOpts.has(SanitizerKind::ObjectSize) |
+  return SanOpts.has(SanitizerKind::Null) ||
+ SanOpts.has(SanitizerKind::Alignment) ||
+ SanOpts.has(SanitizerKind::ObjectSize) ||
  SanOpts.has(SanitizerKind::Vptr);
 }
 

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 8b53e3504e13..615ba1aef8e6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2988,7 +2988,7 @@ bool Sema::CheckHexagonBuiltinArgument(unsigned 
BuiltinID, CallExpr *TheCall) {
   unsigned M = 1 << A.Align;
   Min *= M;
   Max *= M;
-  Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max) |
+  Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max) ||
SemaBuiltinConstantArgMultiple(TheCall, A.OpNum, M);
 }
   }

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8d483f317a42..aedfc07c466d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8377,7 +8377,7 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, 
ExprResult &LHS,
   // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary
   // selection operator (?:).
   if (getLangOpts().OpenCL &&
-  (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get( {
+  ((int)checkBlockType(*this, LHS.get()) | (int)checkBlockType(*this, 
RHS.get( {
 return QualType();
   }
 

diff  --git a/llvm/unittests/Support/TargetParserTest.cpp 
b/llvm/unittests/Support/TargetParserTest.cpp
index a465eb0c57c7..de63efdf7276 100644
--- a/llvm/unittests/Support/TargetParserTest.cpp
+++ b/llvm/unittests/Support/TargetParserTest.cpp
@@ -1181,9 +1181,9 @@ TEST(TargetParserTest, testAArch64CPUArchList) {
 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
  unsigned ArchAttr) {
   AArch64::ArchKind AK = AArch64::parseArch(Arch);
-  return (AK != AArch64::ArchKind::INVALID) &
- AArch64::getDefaultCPU(Arch).equals(DefaultCPU) &
- AArch64::getSubArch(AK).equals(SubArch) &
+  return (AK != AArch64::ArchKind::INVALID) &&
+ AArch64::getDefaultCPU(Arch).equals(DefaultCPU) &&
+ AArch64::getSubArch(AK).equals(SubArch) &&
  (AArch64::getArchAttr(AK) == ArchAttr);
 }
 

diff  --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp 
b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index c1a3a34d928b..ebb4a31d86f4 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -1612,8 +1612,10 @@ bool 
SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
 unsigned OResNo = 0;
 TreePatternNode *OtherNode =
   getOperandNum(x.SDTCisSameAs_Info.OtherOperandNum, N, NodeInfo, OResNo);
-return NodeToApply->UpdateNodeType(ResNo, 
OtherNode->getExtType(OResNo),TP)|
-   OtherNode->UpdateNodeType(OResNo,NodeToApply->getExtType(ResNo),TP);
+return (int)NodeToApply->UpdateNodeType(ResNo,
+OtherNode->getExtType(OResNo), TP) 
|
+   (int)OtherNode->UpdateNodeType(OResNo,
+  NodeToApply->getExt

[clang] a4933f5 - Revert "[Clang] Extend -Wbool-operation to warn about bitwise and of bools with side effects"

2021-10-03 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-10-03T12:47:12+02:00
New Revision: a4933f57f3f0a45e1db1075f7285f0761a80fc06

URL: 
https://github.com/llvm/llvm-project/commit/a4933f57f3f0a45e1db1075f7285f0761a80fc06
DIFF: 
https://github.com/llvm/llvm-project/commit/a4933f57f3f0a45e1db1075f7285f0761a80fc06.diff

LOG: Revert "[Clang] Extend -Wbool-operation to warn about bitwise and of bools 
with side effects"

This reverts commit f62d18ff140f67a8776a7a3c62a75645d8d540b5. Found some cases 
in LLVM itself.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Misc/warning-wall.c

Removed: 
clang/test/Sema/warn-bitwise-and-bool.c
clang/test/Sema/warn-bitwise-or-bool.c



diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index d9db3482dbda7..761b323d06166 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -64,8 +64,7 @@ def StringConversion : DiagGroup<"string-conversion">;
 def SignConversion : DiagGroup<"sign-conversion">;
 def PointerBoolConversion : DiagGroup<"pointer-bool-conversion">;
 def UndefinedBoolConversion : DiagGroup<"undefined-bool-conversion">;
-def BitwiseInsteadOfLogical : DiagGroup<"bitwise-instead-of-logical">;
-def BoolOperation : DiagGroup<"bool-operation", [BitwiseInsteadOfLogical]>;
+def BoolOperation : DiagGroup<"bool-operation">;
 def BoolConversion : DiagGroup<"bool-conversion", [PointerBoolConversion,
UndefinedBoolConversion]>;
 def IntConversion : DiagGroup<"int-conversion">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c71a00b184328..1d4ea92c65205 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -66,7 +66,6 @@ def warn_infinite_recursive_function : Warning<
 def warn_comma_operator : Warning<"possible misuse of comma operator here">,
   InGroup>, DefaultIgnore;
 def note_cast_to_void : Note<"cast expression to void to silence warning">;
-def note_cast_operand_to_int : Note<"cast one or both operands to int to 
silence this warning">;
 
 // Constant expressions
 def err_expr_not_ice : Error<
@@ -7424,9 +7423,6 @@ def note_member_declared_here : Note<
   "member %0 declared here">;
 def note_member_first_declared_here : Note<
   "member %0 first declared here">;
-def warn_bitwise_instead_of_logical : Warning<
-  "use of bitwise '%0' with boolean operands">,
-  InGroup, DefaultIgnore;
 def warn_bitwise_negation_bool : Warning<
   "bitwise negation of a boolean expression%select{;| always evaluates to 
'true';}0 "
   "did you mean logical negation?">,

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 10a3f30704172..8b53e3504e13a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -13249,20 +13249,6 @@ static void AnalyzeImplicitConversions(
   << OrigE->getSourceRange() << T->isBooleanType()
   << FixItHint::CreateReplacement(UO->getBeginLoc(), "!");
 
-  if (const auto *BO = dyn_cast(SourceExpr))
-if ((BO->getOpcode() == BO_And || BO->getOpcode() == BO_Or) &&
-BO->getLHS()->isKnownToHaveBooleanValue() &&
-BO->getRHS()->isKnownToHaveBooleanValue() &&
-BO->getLHS()->HasSideEffects(S.Context) &&
-BO->getRHS()->HasSideEffects(S.Context)) {
-  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
-  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
-  << FixItHint::CreateReplacement(
- BO->getOperatorLoc(),
- (BO->getOpcode() == BO_And ? "&&" : "||"));
-  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
-}
-
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
   if (auto *CO = dyn_cast(SourceExpr)) {

diff  --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index a4a79bec934af..a3686fb96a4ce 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -4,7 +4,6 @@ RUN: FileCheck --input-file=%t %s
  CHECK:-Wall
 CHECK-NEXT:  -Wmost
 CHECK-NEXT:-Wbool-operation
-CHECK-NEXT:-Wbitwise-instead-of-logical
 CHECK-NEXT:-Wchar-subscripts
 CHECK-NEXT:-Wcomment
 CHECK-NEXT:-Wdelete-non-virtual-dtor

diff  --git a/clang/test/Sema/warn-bitwise-and-bool.c 
b/clang/test/Sema/warn-bitwise-and-bool.c
deleted file mode 100644
index 6bec1be1abdef..0
--- a/clang/test/Sema/warn-bitwise-and-bool.c
+++ /dev/null
@@ -1,63 +0,0 @@
-// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wbool-operation %s
-// RUN: %clang_cc1 -x c -fsyntax-only -

[clang] f62d18f - [Clang] Extend -Wbool-operation to warn about bitwise and of bools with side effects

2021-10-03 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-10-03T11:06:40+02:00
New Revision: f62d18ff140f67a8776a7a3c62a75645d8d540b5

URL: 
https://github.com/llvm/llvm-project/commit/f62d18ff140f67a8776a7a3c62a75645d8d540b5
DIFF: 
https://github.com/llvm/llvm-project/commit/f62d18ff140f67a8776a7a3c62a75645d8d540b5.diff

LOG: [Clang] Extend -Wbool-operation to warn about bitwise and of bools with 
side effects

Motivation: 
https://arstechnica.com/gadgets/2021/07/google-pushed-a-one-character-typo-to-production-bricking-chrome-os-devices/

Warn for pattern boolA & boolB or boolA | boolB where boolA and boolB has 
possible side effects.

Casting one operand to int is enough to silence this warning: for example 
(int)boolA & boolB or boolA| (int)boolB

Fixes https://bugs.llvm.org/show_bug.cgi?id=51216

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

Added: 
clang/test/Sema/warn-bitwise-and-bool.c
clang/test/Sema/warn-bitwise-or-bool.c

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Misc/warning-wall.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 761b323d06166..d9db3482dbda7 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -64,7 +64,8 @@ def StringConversion : DiagGroup<"string-conversion">;
 def SignConversion : DiagGroup<"sign-conversion">;
 def PointerBoolConversion : DiagGroup<"pointer-bool-conversion">;
 def UndefinedBoolConversion : DiagGroup<"undefined-bool-conversion">;
-def BoolOperation : DiagGroup<"bool-operation">;
+def BitwiseInsteadOfLogical : DiagGroup<"bitwise-instead-of-logical">;
+def BoolOperation : DiagGroup<"bool-operation", [BitwiseInsteadOfLogical]>;
 def BoolConversion : DiagGroup<"bool-conversion", [PointerBoolConversion,
UndefinedBoolConversion]>;
 def IntConversion : DiagGroup<"int-conversion">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1d4ea92c65205..c71a00b184328 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -66,6 +66,7 @@ def warn_infinite_recursive_function : Warning<
 def warn_comma_operator : Warning<"possible misuse of comma operator here">,
   InGroup>, DefaultIgnore;
 def note_cast_to_void : Note<"cast expression to void to silence warning">;
+def note_cast_operand_to_int : Note<"cast one or both operands to int to 
silence this warning">;
 
 // Constant expressions
 def err_expr_not_ice : Error<
@@ -7423,6 +7424,9 @@ def note_member_declared_here : Note<
   "member %0 declared here">;
 def note_member_first_declared_here : Note<
   "member %0 first declared here">;
+def warn_bitwise_instead_of_logical : Warning<
+  "use of bitwise '%0' with boolean operands">,
+  InGroup, DefaultIgnore;
 def warn_bitwise_negation_bool : Warning<
   "bitwise negation of a boolean expression%select{;| always evaluates to 
'true';}0 "
   "did you mean logical negation?">,

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 8b53e3504e13a..10a3f30704172 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -13249,6 +13249,20 @@ static void AnalyzeImplicitConversions(
   << OrigE->getSourceRange() << T->isBooleanType()
   << FixItHint::CreateReplacement(UO->getBeginLoc(), "!");
 
+  if (const auto *BO = dyn_cast(SourceExpr))
+if ((BO->getOpcode() == BO_And || BO->getOpcode() == BO_Or) &&
+BO->getLHS()->isKnownToHaveBooleanValue() &&
+BO->getRHS()->isKnownToHaveBooleanValue() &&
+BO->getLHS()->HasSideEffects(S.Context) &&
+BO->getRHS()->HasSideEffects(S.Context)) {
+  S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
+  << (BO->getOpcode() == BO_And ? "&" : "|") << OrigE->getSourceRange()
+  << FixItHint::CreateReplacement(
+ BO->getOperatorLoc(),
+ (BO->getOpcode() == BO_And ? "&&" : "||"));
+  S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
+}
+
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
   if (auto *CO = dyn_cast(SourceExpr)) {

diff  --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index a3686fb96a4ce..a4a79bec934af 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -4,6 +4,7 @@ RUN: FileCheck --input-file=%t %s
  CHECK:-Wall
 CHECK-NEXT:  -Wmost
 CHECK-NEXT:-Wbool-operation
+CHECK-NEXT:-Wbitwise-instead-of-logical
 CHECK-NEXT:-Wchar-subscripts
 CHECK-NEXT:-Wcomment
 CHECK-NEXT:-Wdelete-non-virtual

[clang] ccd7dda - [Clang] Updated warning-wall.c test file

2021-08-15 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-08-15T13:54:58+02:00
New Revision: ccd7dda8e39adeaf5bbec3c7b68b68800dff7663

URL: 
https://github.com/llvm/llvm-project/commit/ccd7dda8e39adeaf5bbec3c7b68b68800dff7663
DIFF: 
https://github.com/llvm/llvm-project/commit/ccd7dda8e39adeaf5bbec3c7b68b68800dff7663.diff

LOG: [Clang] Updated warning-wall.c test file

-Wbool-operation was moved to -Wall and test file needs to be adjusted.

Added: 


Modified: 
clang/test/Misc/warning-wall.c

Removed: 




diff  --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index ee3a63e7bbd48..a3686fb96a4ce 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -3,6 +3,7 @@ RUN: FileCheck --input-file=%t %s
 
  CHECK:-Wall
 CHECK-NEXT:  -Wmost
+CHECK-NEXT:-Wbool-operation
 CHECK-NEXT:-Wchar-subscripts
 CHECK-NEXT:-Wcomment
 CHECK-NEXT:-Wdelete-non-virtual-dtor



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


[clang] 079ca8e - [Clang] Put -Wbool-operation under -Wall

2021-08-15 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-08-15T13:37:27+02:00
New Revision: 079ca8e312016bd4fbbd3b185087d4c6246c140b

URL: 
https://github.com/llvm/llvm-project/commit/079ca8e312016bd4fbbd3b185087d4c6246c140b
DIFF: 
https://github.com/llvm/llvm-project/commit/079ca8e312016bd4fbbd3b185087d4c6246c140b.diff

LOG: [Clang] Put -Wbool-operation under -Wall

To keep compatibility with GCC.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/Sema/warn-bitwise-negation-bool.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 4a67dffb2f7d4..30dadd9731c15 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -64,6 +64,7 @@ def StringConversion : DiagGroup<"string-conversion">;
 def SignConversion : DiagGroup<"sign-conversion">;
 def PointerBoolConversion : DiagGroup<"pointer-bool-conversion">;
 def UndefinedBoolConversion : DiagGroup<"undefined-bool-conversion">;
+def BoolOperation : DiagGroup<"bool-operation">;
 def BoolConversion : DiagGroup<"bool-conversion", [PointerBoolConversion,
UndefinedBoolConversion]>;
 def IntConversion : DiagGroup<"int-conversion">;
@@ -944,6 +945,7 @@ def Extra : DiagGroup<"extra", [
   ]>;
 
 def Most : DiagGroup<"most", [
+BoolOperation,
 CharSubscript,
 Comment,
 DeleteNonVirtualDtor,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cbcc0e1f11c48..9eaa696d99913 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7424,7 +7424,7 @@ def note_member_first_declared_here : Note<
 def warn_bitwise_negation_bool : Warning<
   "bitwise negation of a boolean expression%select{;| always evaluates to 
'true';}0 "
   "did you mean logical negation?">,
-  InGroup>;
+  InGroup, DefaultIgnore;
 def err_decrement_bool : Error<"cannot decrement expression of type bool">;
 def warn_increment_bool : Warning<
   "incrementing expression of type bool is deprecated and "

diff  --git a/clang/test/Sema/warn-bitwise-negation-bool.c 
b/clang/test/Sema/warn-bitwise-negation-bool.c
index c74705bc765a2..d9196ca592b26 100644
--- a/clang/test/Sema/warn-bitwise-negation-bool.c
+++ b/clang/test/Sema/warn-bitwise-negation-bool.c
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wbool-operation %s
-// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
-// RUN: %clang_cc1 -x c -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | 
FileCheck %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c -fsyntax-only -Wbool-operation 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wbool-operation %s
-// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
-// RUN: %clang_cc1 -x c++ -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 
| FileCheck %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wbool-operation 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 #ifdef __cplusplus
 typedef bool boolean;



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


[clang] 49de607 - Revert "[Remarks] Emit optimization remarks for atomics generating CAS loop"

2021-08-15 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-08-15T11:44:13+02:00
New Revision: 49de6070a2b7a9bb88ff7c935fea5176b1d9255f

URL: 
https://github.com/llvm/llvm-project/commit/49de6070a2b7a9bb88ff7c935fea5176b1d9255f
DIFF: 
https://github.com/llvm/llvm-project/commit/49de6070a2b7a9bb88ff7c935fea5176b1d9255f.diff

LOG: Revert "[Remarks] Emit optimization remarks for atomics generating CAS 
loop"

This reverts commit 435785214f73ff0c92e97f2ade6356e3ba3bf661. Still same 
compile time issues for -O0 -g, eg. +1.3% for sqlite3.

Added: 


Modified: 
llvm/lib/CodeGen/AtomicExpandPass.cpp
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
llvm/test/CodeGen/ARM/O3-pipeline.ll
llvm/test/CodeGen/PowerPC/O3-pipeline.ll
llvm/test/CodeGen/X86/O0-pipeline.ll
llvm/test/CodeGen/X86/opt-pipeline.ll

Removed: 
clang/test/CodeGenCUDA/atomics-remarks-gfx90a.cu
clang/test/CodeGenOpenCL/atomics-remarks-gfx90a.cl
llvm/test/CodeGen/AMDGPU/atomics-remarks-gfx90a.ll



diff  --git a/clang/test/CodeGenCUDA/atomics-remarks-gfx90a.cu 
b/clang/test/CodeGenCUDA/atomics-remarks-gfx90a.cu
deleted file mode 100644
index 96892286fd75e..0
--- a/clang/test/CodeGenCUDA/atomics-remarks-gfx90a.cu
+++ /dev/null
@@ -1,16 +0,0 @@
-// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -fcuda-is-device \
-// RUN:   -target-cpu gfx90a -Rpass=atomic-expand -S -o - 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=GFX90A-CAS
-
-// REQUIRES: amdgpu-registered-target
-
-#include "Inputs/cuda.h"
-#include 
-
-// GFX90A-CAS: A compare and swap loop was generated for an atomic fadd 
operation at system memory scope
-// GFX90A-CAS-LABEL: _Z14atomic_add_casPf
-// GFX90A-CAS:  flat_atomic_cmpswap v0, v[2:3], v[4:5] glc
-// GFX90A-CAS:  s_cbranch_execnz
-__device__ float atomic_add_cas(float *p) {
-  return __atomic_fetch_add(p, 1.0f, memory_order_relaxed);
-}

diff  --git a/clang/test/CodeGenOpenCL/atomics-remarks-gfx90a.cl 
b/clang/test/CodeGenOpenCL/atomics-remarks-gfx90a.cl
deleted file mode 100644
index 2d8b68f83b9d6..0
--- a/clang/test/CodeGenOpenCL/atomics-remarks-gfx90a.cl
+++ /dev/null
@@ -1,46 +0,0 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -triple=amdgcn-amd-amdhsa -target-cpu 
gfx90a \
-// RUN: -Rpass=atomic-expand -S -o - 2>&1 | \
-// RUN: FileCheck %s --check-prefix=REMARK
-
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -triple=amdgcn-amd-amdhsa -target-cpu 
gfx90a \
-// RUN: -Rpass=atomic-expand -S -emit-llvm -o - 2>&1 | \
-// RUN: FileCheck %s --check-prefix=GFX90A-CAS
-
-// REQUIRES: amdgpu-registered-target
-
-typedef enum memory_order {
-  memory_order_relaxed = __ATOMIC_RELAXED,
-  memory_order_acquire = __ATOMIC_ACQUIRE,
-  memory_order_release = __ATOMIC_RELEASE,
-  memory_order_acq_rel = __ATOMIC_ACQ_REL,
-  memory_order_seq_cst = __ATOMIC_SEQ_CST
-} memory_order;
-
-typedef enum memory_scope {
-  memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
-  memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
-  memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
-  memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
-#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
-  memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
-#endif
-} memory_scope;
-
-// REMARK: remark: A compare and swap loop was generated for an atomic fadd 
operation at workgroup-one-as memory scope [-Rpass=atomic-expand]
-// REMARK: remark: A compare and swap loop was generated for an atomic fadd 
operation at agent-one-as memory scope [-Rpass=atomic-expand]
-// REMARK: remark: A compare and swap loop was generated for an atomic fadd 
operation at one-as memory scope [-Rpass=atomic-expand]
-// REMARK: remark: A compare and swap loop was generated for an atomic fadd 
operation at wavefront-one-as memory scope [-Rpass=atomic-expand]
-// GFX90A-CAS-LABEL: @atomic_cas
-// GFX90A-CAS: atomicrmw fadd float addrspace(1)* {{.*}} 
syncscope("workgroup-one-as") monotonic
-// GFX90A-CAS: atomicrmw fadd float addrspace(1)* {{.*}} 
syncscope("agent-one-as") monotonic
-// GFX90A-CAS: atomicrmw fadd float addrspace(1)* {{.*}} syncscope("one-as") 
monotonic
-// GFX90A-CAS: atomicrmw fadd float addrspace(1)* {{.*}} 
syncscope("wavefront-one-as") monotonic
-float atomic_cas(__global atomic_float *d, float a) {
-  float ret1 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, 
memory_scope_work_group);
-  float ret2 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, 
memory_scope_device);
-  float ret3 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, 
memory_scope_all_svm_devices);
-  float ret4 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, 
memory_scope_sub_group);
-}
-
-
-

diff  --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp 
b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index 5b5458e1058e8..125a3be585cb5 100644
--- a/

[clang] d29a53d - [Clang] Added heading to doc for malloc attribute

2021-04-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-24T15:35:16+02:00
New Revision: d29a53d9cabcb37621b793c5bf44076e75b8db88

URL: 
https://github.com/llvm/llvm-project/commit/d29a53d9cabcb37621b793c5bf44076e75b8db88
DIFF: 
https://github.com/llvm/llvm-project/commit/d29a53d9cabcb37621b793c5bf44076e75b8db88.diff

LOG: [Clang] Added heading to doc for malloc attribute

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 7b9d618c07ae..1960596f1bfb 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3714,6 +3714,7 @@ system) and does not imply undefined behavior, making it 
more widely applicable.
 
 def RestrictDocs : Documentation {
   let Category = DocCatFunction;
+  let Heading = "malloc";
   let Content = [{
 The ``malloc`` attribute indicates that the function acts like a system memory
 allocation function, returning a pointer to allocated storage disjoint from the



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


[clang] c68f929 - [Clang] Added doc for malloc attribute

2021-04-24 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-24T15:27:48+02:00
New Revision: c68f92983600196e33e8abfbcd1aa19235f34c8d

URL: 
https://github.com/llvm/llvm-project/commit/c68f92983600196e33e8abfbcd1aa19235f34c8d
DIFF: 
https://github.com/llvm/llvm-project/commit/c68f92983600196e33e8abfbcd1aa19235f34c8d.diff

LOG: [Clang] Added doc for malloc attribute

Taken mostly from LLVM langref.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fcad24b83a05..08534ec61620 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1494,7 +1494,7 @@ def IFunc : Attr, TargetSpecificAttr {
 def Restrict : InheritableAttr {
   let Spellings = [Declspec<"restrict">, GCC<"malloc">];
   let Subjects = SubjectList<[Function]>;
-  let Documentation = [Undocumented];
+  let Documentation = [RestrictDocs];
 }
 
 def LayoutVersion : InheritableAttr, TargetSpecificAttr 
{

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 0af5b790d8a3..7b9d618c07ae 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3712,6 +3712,15 @@ system) and does not imply undefined behavior, making it 
more widely applicable.
   }];
 }
 
+def RestrictDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``malloc`` attribute indicates that the function acts like a system memory
+allocation function, returning a pointer to allocated storage disjoint from the
+storage for any other object accessible to the caller.
+  }];
+}
+
 def ReturnsNonNullDocs : Documentation {
   let Category = NullabilityDocs;
   let Content = [{



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


[clang] 2cae702 - Reland "[Clang] Propagate guaranteed alignment for malloc and others"

2021-04-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-23T14:05:57+02:00
New Revision: 2cae7025c1d9e83d971f670c9a66497a8c1094ec

URL: 
https://github.com/llvm/llvm-project/commit/2cae7025c1d9e83d971f670c9a66497a8c1094ec
DIFF: 
https://github.com/llvm/llvm-project/commit/2cae7025c1d9e83d971f670c9a66497a8c1094ec.diff

LOG: Reland "[Clang] Propagate guaranteed alignment for malloc and others"

This relands commit 6914a0ed2b30924b188968e59a83efa07ac5fe57. Crash in 
InstCombine was fixed.

Added: 
clang/test/CodeGen/alloc-fns-alignment.c

Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3bcaaceb63d8e..449c026639b90 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -612,8 +612,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   }
 
   /// Return the largest alignment for which a suitably-sized allocation with
-  /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
-  /// pointer.
+  /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a
+  /// correctly-aligned pointer.
   unsigned getNewAlign() const {
 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
   }

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 366c83eeb8e89..6c77f1889fb52 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2048,6 +2048,24 @@ void CodeGenModule::ConstructAttributeList(
   // allows it to work on indirect virtual function calls.
   if (AttrOnCallSite && TargetDecl->hasAttr())
 FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
+
+  // Add known guaranteed alignment for allocation functions.
+  if (unsigned BuiltinID = Fn->getBuiltinID()) {
+switch (BuiltinID) {
+case Builtin::BIaligned_alloc:
+case Builtin::BIcalloc:
+case Builtin::BImalloc:
+case Builtin::BImemalign:
+case Builtin::BIrealloc:
+case Builtin::BIstrdup:
+case Builtin::BIstrndup:
+  RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() /
+Context.getTargetInfo().getCharWidth());
+  break;
+default:
+  break;
+}
+  }
 }
 
 // 'const', 'pure' and 'noalias' attributed functions are also nounwind.

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
new file mode 100644
index 0..d2f9b467196a7
--- /dev/null
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
+// RUN: %clang_cc1 -triple x86_64-windows-msvc  -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
+// RUN: %clang_cc1 -triple i386-apple-darwin-emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu   -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN8
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
+
+typedef __SIZE_TYPE__ size_t;
+
+void *malloc(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+
+void *malloc_test(size_t n) {
+  return malloc(n);
+}
+
+void *calloc_test(size_t n) {
+  return calloc(1, n);
+}
+
+void *raalloc_test(void *p, size_t n) {
+  return realloc(p, n);
+}
+
+// ALIGN16: align 16 i8* @malloc
+// ALIGN16: align 16 i8* @calloc
+// ALIGN16: align 16 i8* @realloc
+// ALIGN8: align 8 i8* @malloc
+// ALIGN8: align 8 i8* @calloc
+// ALIGN8: align 8 i8* @realloc
+// NOBUILTIN-MALLOC: declare i8* @malloc
+// NOBUILTIN-CALLOC: declare i8* @calloc
+// NOBUILTIN-REALLOC: declare i8* @realloc



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


[clang] 6914a0e - Revert "[Clang] Propagate guaranteed alignment for malloc and others"

2021-04-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-23T11:33:33+02:00
New Revision: 6914a0ed2b30924b188968e59a83efa07ac5fe57

URL: 
https://github.com/llvm/llvm-project/commit/6914a0ed2b30924b188968e59a83efa07ac5fe57
DIFF: 
https://github.com/llvm/llvm-project/commit/6914a0ed2b30924b188968e59a83efa07ac5fe57.diff

LOG: Revert "[Clang] Propagate guaranteed alignment for malloc and others"

This reverts commit c2297544c04764237cedc523083c7be2fb3833d4. Some buildbots 
are broken.

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/CodeGen/CGCall.cpp

Removed: 
clang/test/CodeGen/alloc-fns-alignment.c



diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 449c026639b9..3bcaaceb63d8 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -612,8 +612,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   }
 
   /// Return the largest alignment for which a suitably-sized allocation with
-  /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a
-  /// correctly-aligned pointer.
+  /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
+  /// pointer.
   unsigned getNewAlign() const {
 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
   }

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 6c77f1889fb5..366c83eeb8e8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2048,24 +2048,6 @@ void CodeGenModule::ConstructAttributeList(
   // allows it to work on indirect virtual function calls.
   if (AttrOnCallSite && TargetDecl->hasAttr())
 FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
-
-  // Add known guaranteed alignment for allocation functions.
-  if (unsigned BuiltinID = Fn->getBuiltinID()) {
-switch (BuiltinID) {
-case Builtin::BIaligned_alloc:
-case Builtin::BIcalloc:
-case Builtin::BImalloc:
-case Builtin::BImemalign:
-case Builtin::BIrealloc:
-case Builtin::BIstrdup:
-case Builtin::BIstrndup:
-  RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() /
-Context.getTargetInfo().getCharWidth());
-  break;
-default:
-  break;
-}
-  }
 }
 
 // 'const', 'pure' and 'noalias' attributed functions are also nounwind.

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
deleted file mode 100644
index d2f9b467196a..
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ /dev/null
@@ -1,35 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple x86_64-windows-msvc  -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-apple-darwin-emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu   -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN8
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
-
-typedef __SIZE_TYPE__ size_t;
-
-void *malloc(size_t);
-void *calloc(size_t, size_t);
-void *realloc(void *, size_t);
-
-void *malloc_test(size_t n) {
-  return malloc(n);
-}
-
-void *calloc_test(size_t n) {
-  return calloc(1, n);
-}
-
-void *raalloc_test(void *p, size_t n) {
-  return realloc(p, n);
-}
-
-// ALIGN16: align 16 i8* @malloc
-// ALIGN16: align 16 i8* @calloc
-// ALIGN16: align 16 i8* @realloc
-// ALIGN8: align 8 i8* @malloc
-// ALIGN8: align 8 i8* @calloc
-// ALIGN8: align 8 i8* @realloc
-// NOBUILTIN-MALLOC: declare i8* @malloc
-// NOBUILTIN-CALLOC: declare i8* @calloc
-// NOBUILTIN-REALLOC: declare i8* @realloc



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


[clang] c229754 - [Clang] Propagate guaranteed alignment for malloc and others

2021-04-23 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-23T11:07:14+02:00
New Revision: c2297544c04764237cedc523083c7be2fb3833d4

URL: 
https://github.com/llvm/llvm-project/commit/c2297544c04764237cedc523083c7be2fb3833d4
DIFF: 
https://github.com/llvm/llvm-project/commit/c2297544c04764237cedc523083c7be2fb3833d4.diff

LOG: [Clang] Propagate guaranteed alignment for malloc and others

LLVM should be smarter about *known* malloc's alignment and this knowledge may 
enable other optimizations.

Originally started as LLVM patch - https://reviews.llvm.org/D100862 but this 
logic should be really in Clang.

Reviewed By: rjmccall

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

Added: 
clang/test/CodeGen/alloc-fns-alignment.c

Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3bcaaceb63d8..449c026639b9 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -612,8 +612,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   }
 
   /// Return the largest alignment for which a suitably-sized allocation with
-  /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
-  /// pointer.
+  /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a
+  /// correctly-aligned pointer.
   unsigned getNewAlign() const {
 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
   }

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 366c83eeb8e8..6c77f1889fb5 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2048,6 +2048,24 @@ void CodeGenModule::ConstructAttributeList(
   // allows it to work on indirect virtual function calls.
   if (AttrOnCallSite && TargetDecl->hasAttr())
 FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
+
+  // Add known guaranteed alignment for allocation functions.
+  if (unsigned BuiltinID = Fn->getBuiltinID()) {
+switch (BuiltinID) {
+case Builtin::BIaligned_alloc:
+case Builtin::BIcalloc:
+case Builtin::BImalloc:
+case Builtin::BImemalign:
+case Builtin::BIrealloc:
+case Builtin::BIstrdup:
+case Builtin::BIstrndup:
+  RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() /
+Context.getTargetInfo().getCharWidth());
+  break;
+default:
+  break;
+}
+  }
 }
 
 // 'const', 'pure' and 'noalias' attributed functions are also nounwind.

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
new file mode 100644
index ..d2f9b467196a
--- /dev/null
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
+// RUN: %clang_cc1 -triple x86_64-windows-msvc  -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
+// RUN: %clang_cc1 -triple i386-apple-darwin-emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu   -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN8
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
+
+typedef __SIZE_TYPE__ size_t;
+
+void *malloc(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+
+void *malloc_test(size_t n) {
+  return malloc(n);
+}
+
+void *calloc_test(size_t n) {
+  return calloc(1, n);
+}
+
+void *raalloc_test(void *p, size_t n) {
+  return realloc(p, n);
+}
+
+// ALIGN16: align 16 i8* @malloc
+// ALIGN16: align 16 i8* @calloc
+// ALIGN16: align 16 i8* @realloc
+// ALIGN8: align 8 i8* @malloc
+// ALIGN8: align 8 i8* @calloc
+// ALIGN8: align 8 i8* @realloc
+// NOBUILTIN-MALLOC: declare i8* @malloc
+// NOBUILTIN-CALLOC: declare i8* @calloc
+// NOBUILTIN-REALLOC: declare i8* @realloc



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


[clang] abf3ca6 - [Diagnostics] Restore -Wdeprecated warning when user-declared copy assignment operator is defined as deleted (PR45634)

2021-04-22 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-22T20:35:41+02:00
New Revision: abf3ca61e3235681f26d0f527b8e2763dd4c0c62

URL: 
https://github.com/llvm/llvm-project/commit/abf3ca61e3235681f26d0f527b8e2763dd4c0c62
DIFF: 
https://github.com/llvm/llvm-project/commit/abf3ca61e3235681f26d0f527b8e2763dd4c0c62.diff

LOG: [Diagnostics] Restore -Wdeprecated warning when user-declared copy 
assignment operator is defined as deleted (PR45634)

Solves https://bugs.llvm.org/show_bug.cgi?id=45634
Be more agressive than GCC with -Wdeprecated-copy. Also provide 
-W(no-)deprecated-copy-user-provided-copy/dtor options to on/off this behaviour.

Reviewed By: Quuxplusone

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

Added: 
clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/deprecated-copy.cpp
clang/test/SemaCXX/deprecated.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index e202645d1f2b0..df2a46cecc5d0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -162,8 +162,12 @@ def CXX11CompatDeprecatedWritableStr :
 def DeprecatedArrayCompare : DiagGroup<"deprecated-array-compare">;
 def DeprecatedAttributes : DiagGroup<"deprecated-attributes">;
 def DeprecatedCommaSubscript : DiagGroup<"deprecated-comma-subscript">;
-def DeprecatedCopy : DiagGroup<"deprecated-copy">;
-def DeprecatedCopyDtor : DiagGroup<"deprecated-copy-dtor">;
+def DeprecatedCopyWithUserProvidedCopy : 
DiagGroup<"deprecated-copy-with-user-provided-copy">;
+def DeprecatedCopyWithUserProvidedDtor : 
DiagGroup<"deprecated-copy-with-user-provided-dtor">;
+def DeprecatedCopy : DiagGroup<"deprecated-copy", 
[DeprecatedCopyWithUserProvidedCopy]>;
+def DeprecatedCopyWithDtor : DiagGroup<"deprecated-copy-with-dtor", 
[DeprecatedCopyWithUserProvidedDtor]>;
+// For compatibility with GCC.
+def : DiagGroup<"deprecated-copy-dtor", [DeprecatedCopyWithDtor]>;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
 def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
@@ -186,7 +190,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedAttributes,
   DeprecatedCommaSubscript,
   DeprecatedCopy,
-  DeprecatedCopyDtor,
+  DeprecatedCopyWithDtor,
   DeprecatedDeclarations,
   DeprecatedDynamicExceptionSpec,
   DeprecatedEnumCompare,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index aeeed560b5145..3a58d3dc5c4a8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -567,15 +567,24 @@ def warn_access_decl_deprecated : Warning<
 def err_access_decl : Error<
   "ISO C++11 does not allow access declarations; "
   "use using declarations instead">;
-def warn_deprecated_copy_operation : Warning<
+def warn_deprecated_copy : Warning<
   "definition of implicit copy %select{constructor|assignment operator}1 "
   "for %0 is deprecated because it has a user-declared copy "
   "%select{assignment operator|constructor}1">,
   InGroup, DefaultIgnore;
-def warn_deprecated_copy_dtor_operation : Warning<
+def warn_deprecated_copy_with_dtor : Warning<
   "definition of implicit copy %select{constructor|assignment operator}1 "
   "for %0 is deprecated because it has a user-declared destructor">,
-  InGroup, DefaultIgnore;
+  InGroup, DefaultIgnore;
+def warn_deprecated_copy_with_user_provided_copy: Warning<
+  "definition of implicit copy %select{constructor|assignment operator}1 "
+  "for %0 is deprecated because it has a user-provided copy "
+  "%select{assignment operator|constructor}1">,
+  InGroup, DefaultIgnore;
+def warn_deprecated_copy_with_user_provided_dtor : Warning<
+  "definition of implicit copy %select{constructor|assignment operator}1 "
+  "for %0 is deprecated because it has a user-provided destructor">,
+  InGroup, DefaultIgnore;
 def warn_cxx17_compat_exception_spec_in_signature : Warning<
   "mangled name of %0 will change in C++17 due to non-throwing exception "
   "specification in function signature">, InGroup;

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/c

[clang] 9f1e2ee - [Clang, builtins] Added aligned_alloc, memalign support

2021-04-20 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-21T00:11:54+02:00
New Revision: 9f1e2ee46251b09565eb87124aa836291aaf799d

URL: 
https://github.com/llvm/llvm-project/commit/9f1e2ee46251b09565eb87124aa836291aaf799d
DIFF: 
https://github.com/llvm/llvm-project/commit/9f1e2ee46251b09565eb87124aa836291aaf799d.diff

LOG: [Clang, builtins] Added aligned_alloc, memalign support

Added: 
clang/test/CodeGen/aligned_alloc-libcall.c
clang/test/CodeGen/memalign-libcall.c

Modified: 
clang/include/clang/Basic/Builtins.def

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 92da70ea05db3..ead84e2e62797 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -980,6 +980,8 @@ LIBBUILTIN(strtol, "LicC*c**i",   "f", "stdlib.h", 
ALL_LANGUAGES)
 LIBBUILTIN(strtoll, "LLicC*c**i", "f", "stdlib.h", ALL_LANGUAGES)
 LIBBUILTIN(strtoul, "ULicC*c**i", "f", "stdlib.h", ALL_LANGUAGES)
 LIBBUILTIN(strtoull, "ULLicC*c**i", "f",   "stdlib.h", ALL_LANGUAGES)
+// C11 stdlib.h
+LIBBUILTIN(aligned_alloc, "v*zz", "f", "stdlib.h", ALL_LANGUAGES)
 // C99 string.h
 LIBBUILTIN(memcpy, "v*v*vC*z","f", "string.h", ALL_LANGUAGES)
 LIBBUILTIN(memcmp, "ivC*vC*z","f", "string.h", ALL_LANGUAGES)
@@ -1061,6 +1063,8 @@ LIBBUILTIN(longjmp, "vJi","frT",   "setjmp.h", 
ALL_LANGUAGES)
 // all languages, because losing this attribute would result in miscompilation
 // when these functions are used in non-GNU mode. PR16138.
 LIBBUILTIN(alloca, "v*z", "f", "stdlib.h", ALL_GNU_LANGUAGES)
+// POSIX malloc.h
+LIBBUILTIN(memalign, "v*zz",  "f", "malloc.h", ALL_GNU_LANGUAGES)
 // POSIX string.h
 LIBBUILTIN(memccpy, "v*v*vC*iz",  "f", "string.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(mempcpy, "v*v*vC*z",   "f", "string.h", ALL_GNU_LANGUAGES)

diff  --git a/clang/test/CodeGen/aligned_alloc-libcall.c 
b/clang/test/CodeGen/aligned_alloc-libcall.c
new file mode 100644
index 0..ee44fc38b393f
--- /dev/null
+++ b/clang/test/CodeGen/aligned_alloc-libcall.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fno-builtin-aligned_alloc -emit-llvm < %s | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+void *aligned_alloc(size_t, size_t);
+
+void *test(size_t alignment, size_t size) {
+  // CHECK: call i8* @aligned_alloc{{.*}} #2
+  return aligned_alloc(alignment, size);
+}
+
+// CHECK: attributes #2 = { nobuiltin "no-builtin-aligned_alloc" } 
\ No newline at end of file

diff  --git a/clang/test/CodeGen/memalign-libcall.c 
b/clang/test/CodeGen/memalign-libcall.c
new file mode 100644
index 0..ec040456d885d
--- /dev/null
+++ b/clang/test/CodeGen/memalign-libcall.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fno-builtin-memalign -emit-llvm < %s | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+void *memalign(size_t, size_t);
+
+void *test(size_t alignment, size_t size) {
+  // CHECK: call i8* @memalign{{.*}} #2
+  return memalign(alignment, size);
+}
+
+// CHECK: attributes #2 = { nobuiltin "no-builtin-memalign" } 
\ No newline at end of file



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


[clang] 12a1f1d - [Pragma] Added support for GCC unroll/nounroll

2021-04-17 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-17T17:29:55+02:00
New Revision: 12a1f1d9d7e4f7ce416d0602d18991973986dfb5

URL: 
https://github.com/llvm/llvm-project/commit/12a1f1d9d7e4f7ce416d0602d18991973986dfb5
DIFF: 
https://github.com/llvm/llvm-project/commit/12a1f1d9d7e4f7ce416d0602d18991973986dfb5.diff

LOG: [Pragma] Added support for GCC unroll/nounroll

GCC 8 introduced these new pragmas to control loop unrolling. We should support 
them for compatibility reasons and the implementation itself requires few lines 
of code, since everything needed is already implemented for #pragma 
unroll/nounroll.

Added: 
clang/test/CodeGenCXX/pragma-gcc-unroll.cpp

Modified: 
clang/include/clang/Basic/AttrDocs.td
clang/lib/Parse/ParsePragma.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 867865e91056b..0af5b790d8a36 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3243,7 +3243,9 @@ def UnrollHintDocs : Documentation {
   let Content = [{
 Loop unrolling optimization hints can be specified with ``#pragma unroll`` and
 ``#pragma nounroll``. The pragma is placed immediately before a for, while,
-do-while, or c++11 range-based for loop.
+do-while, or c++11 range-based for loop. GCC's loop unrolling hints
+``#pragma GCC unroll`` and ``#pragma GCC nounroll`` are also supported and have
+identical semantics to ``#pragma unroll`` and ``#pragma nounroll``.
 
 Specifying ``#pragma unroll`` without a parameter directs the loop unroller to
 attempt to fully unroll the loop if the trip count is known at compile time and

diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 4ce8e4c4bb9d9..660d317f57d07 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -405,9 +405,11 @@ void Parser::initializePragmaHandlers() {
 
   UnrollHintHandler = std::make_unique("unroll");
   PP.AddPragmaHandler(UnrollHintHandler.get());
+  PP.AddPragmaHandler("GCC", UnrollHintHandler.get());
 
   NoUnrollHintHandler = std::make_unique("nounroll");
   PP.AddPragmaHandler(NoUnrollHintHandler.get());
+  PP.AddPragmaHandler("GCC", NoUnrollHintHandler.get());
 
   UnrollAndJamHintHandler =
   std::make_unique("unroll_and_jam");
@@ -523,9 +525,11 @@ void Parser::resetPragmaHandlers() {
   LoopHintHandler.reset();
 
   PP.RemovePragmaHandler(UnrollHintHandler.get());
+  PP.RemovePragmaHandler("GCC", UnrollHintHandler.get());
   UnrollHintHandler.reset();
 
   PP.RemovePragmaHandler(NoUnrollHintHandler.get());
+  PP.RemovePragmaHandler("GCC", NoUnrollHintHandler.get());
   NoUnrollHintHandler.reset();
 
   PP.RemovePragmaHandler(UnrollAndJamHintHandler.get());

diff  --git a/clang/test/CodeGenCXX/pragma-gcc-unroll.cpp 
b/clang/test/CodeGenCXX/pragma-gcc-unroll.cpp
new file mode 100644
index 0..ed75e0b6e3c36
--- /dev/null
+++ b/clang/test/CodeGenCXX/pragma-gcc-unroll.cpp
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | 
FileCheck %s
+
+// Check that passing -fno-unroll-loops does not impact the decision made 
using pragmas.
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - -O1 
-disable-llvm-optzns -fno-unroll-loops %s | FileCheck %s
+
+// Verify while loop is recognized after unroll pragma.
+void while_test(int *List, int Length) {
+  // CHECK: define {{.*}} @_Z10while_test
+  int i = 0;
+
+#pragma GCC unroll
+  while (i < Length) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_1:.*]]
+List[i] = i * 2;
+i++;
+  }
+}
+
+// Verify do loop is recognized after multi-option pragma clang loop directive.
+void do_test(int *List, int Length) {
+  // CHECK: define {{.*}} @_Z7do_test
+  int i = 0;
+
+#pragma GCC nounroll
+  do {
+// CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop 
![[LOOP_2:.*]]
+List[i] = i * 2;
+i++;
+  } while (i < Length);
+}
+
+// Verify for loop is recognized after unroll pragma.
+void for_test(int *List, int Length) {
+// CHECK: define {{.*}} @_Z8for_test
+#pragma GCC unroll 8
+  for (int i = 0; i < Length; i++) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_3:.*]]
+List[i] = i * 2;
+  }
+}
+
+// Verify c++11 for range loop is recognized after unroll pragma.
+void for_range_test() {
+  // CHECK: define {{.*}} @_Z14for_range_test
+  double List[100];
+
+#pragma GCC unroll(4)
+  for (int i : List) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_4:.*]]
+List[i] = i;
+  }
+}
+
+#define UNROLLCOUNT 8
+
+// Verify defines are correctly resolved in unroll pragmas.
+void for_define_test(int *List, int Length, int Value) {
+// CHECK: define {{.*}} @_Z15for_define_test
+#pragma GCC unroll(UNROLLCOUNT)
+  for (int i = 0; i < Length; i++) {
+// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_5:.*]]
+List[i] = i * Value;
+  }
+}
+
+// Verify me

[clang] 0daf273 - [Builtins] Add memory allocation builtins (PR12543)

2021-04-16 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-04-16T20:36:46+02:00
New Revision: 0daf27302518dcc521fae5cb5c7f72b783c13c35

URL: 
https://github.com/llvm/llvm-project/commit/0daf27302518dcc521fae5cb5c7f72b783c13c35
DIFF: 
https://github.com/llvm/llvm-project/commit/0daf27302518dcc521fae5cb5c7f72b783c13c35.diff

LOG: [Builtins] Add memory allocation builtins (PR12543)

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/test/CodeGen/builtins.c

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 8518f3789f51a..92da70ea05db3 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -529,6 +529,7 @@ BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
 BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
+BUILTIN(__builtin_calloc, "v*zz", "nF")
 BUILTIN(__builtin_constant_p, "i.", "nctu")
 BUILTIN(__builtin_classify_type, "i.", "nctu")
 BUILTIN(__builtin___CFStringMakeConstantString, "FC*cC*", "nc")
@@ -542,6 +543,8 @@ BUILTIN(__builtin_bcmp, "ivC*vC*z", "Fn")
 BUILTIN(__builtin_bcopy, "vv*v*z", "n")
 BUILTIN(__builtin_bzero, "vv*z", "nF")
 BUILTIN(__builtin_fprintf, "iP*cC*.", "Fp:1:")
+BUILTIN(__builtin_free, "vv*", "nF")
+BUILTIN(__builtin_malloc, "v*z", "nF")
 BUILTIN(__builtin_memchr, "v*vC*iz", "nF")
 BUILTIN(__builtin_memcmp, "ivC*vC*z", "nF")
 BUILTIN(__builtin_memcpy, "v*v*vC*z", "nF")
@@ -577,6 +580,7 @@ BUILTIN(__builtin_wmemchr, "w*wC*wz", "nF")
 BUILTIN(__builtin_wmemcmp, "iwC*wC*z", "nF")
 BUILTIN(__builtin_wmemcpy, "w*w*wC*z", "nF")
 BUILTIN(__builtin_wmemmove, "w*w*wC*z", "nF")
+BUILTIN(__builtin_realloc, "v*v*z", "nF")
 BUILTIN(__builtin_return_address, "v*IUi", "n")
 BUILTIN(__builtin_extract_return_addr, "v*v*", "n")
 BUILTIN(__builtin_frame_address, "v*IUi", "n")
@@ -586,8 +590,9 @@ BUILTIN(__builtin_longjmp, "vv**i", "r")
 BUILTIN(__builtin_unwind_init, "v", "")
 BUILTIN(__builtin_eh_return_data_regno, "iIi", "nc")
 BUILTIN(__builtin_snprintf, "ic*zcC*.", "nFp:2:")
-BUILTIN(__builtin_vsprintf, "ic*cC*a", "nFP:1:")
+BUILTIN(__builtin_sprintf, "ic*cC*.", "nFP:1:")
 BUILTIN(__builtin_vsnprintf, "ic*zcC*a", "nFP:2:")
+BUILTIN(__builtin_vsprintf, "ic*cC*a", "nFP:1:")
 BUILTIN(__builtin_thread_pointer, "v*", "nc")
 BUILTIN(__builtin_launder, "v*v*", "nt")
 LANGBUILTIN(__builtin_is_constant_evaluated, "b", "n", CXX_LANG)

diff  --git a/clang/test/CodeGen/builtins.c b/clang/test/CodeGen/builtins.c
index 2bb4a500dde5b..9ecb4a2a3c0a8 100644
--- a/clang/test/CodeGen/builtins.c
+++ b/clang/test/CodeGen/builtins.c
@@ -91,11 +91,15 @@ int main() {
   char s0[10], s1[] = "Hello";
   V(strcat, (s0, s1));
   V(strcmp, (s0, s1));
+  V(strdup, (s0));
   V(strncat, (s0, s1, n));
+  V(strndup, (s0, n));
   V(strchr, (s0, s1[0]));
   V(strrchr, (s0, s1[0]));
   V(strcpy, (s0, s1));
   V(strncpy, (s0, s1, n));
+  V(sprintf, (s0, "%s", s1));
+  V(snprintf, (s0, n, "%s", s1));
   
   // Object size checking
   V(__memset_chk, (s0, 0, sizeof s0, n));
@@ -438,6 +442,20 @@ void test_builtin_longjmp(void **buffer) {
 
 #endif
 
+// CHECK-LABEL: define{{.*}} void @test_memory_builtins
+void test_memory_builtins(int n) {
+  // CHECK: call i8* @malloc
+  void * p = __builtin_malloc(n);
+  // CHECK: call void @free
+  __builtin_free(p);
+  // CHECK: call i8* @calloc
+  p = __builtin_calloc(1, n);
+  // CHECK: call i8* @realloc
+  p = __builtin_realloc(p, n);
+  // CHECK: call void @free
+  __builtin_free(p);
+}
+
 // CHECK-LABEL: define{{.*}} i64 @test_builtin_readcyclecounter
 long long test_builtin_readcyclecounter() {
   // CHECK: call i64 @llvm.readcyclecounter()



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


[clang] 501b4fe - Fixed failing test

2021-02-19 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-02-20T07:11:42+01:00
New Revision: 501b4fe4ed7f5de2ae00cbc9da87a5b1141ec47a

URL: 
https://github.com/llvm/llvm-project/commit/501b4fe4ed7f5de2ae00cbc9da87a5b1141ec47a
DIFF: 
https://github.com/llvm/llvm-project/commit/501b4fe4ed7f5de2ae00cbc9da87a5b1141ec47a.diff

LOG: Fixed failing test

Added: 


Modified: 
clang/test/CodeGenObjC/disable-tail-call-escaping-block.m

Removed: 




diff  --git a/clang/test/CodeGenObjC/disable-tail-call-escaping-block.m 
b/clang/test/CodeGenObjC/disable-tail-call-escaping-block.m
index e8f5d6d329bb..82fcd49e1e44 100644
--- a/clang/test/CodeGenObjC/disable-tail-call-escaping-block.m
+++ b/clang/test/CodeGenObjC/disable-tail-call-escaping-block.m
@@ -17,7 +17,7 @@
 // CHECK: define internal void @[[TEST_BLOCK_INVOKE5]]({{.*}}) 
#[[DISABLEATTR]] {
 // CHECK: define internal void @[[TEST_BLOCK_INVOKE6]]({{.*}}) #[[ENABLEATTR]] 
{
 
-// CHECK: attributes #[[ENABLEATTR]] = 
{{{.*}}"disable-tail-calls"="false"{{.*}}}
+// CHECK-NOT: attributes #[[ENABLEATTR]] = 
{{{.*}}"disable-tail-calls"="false"{{.*}}}
 // CHECK: attributes #[[DISABLEATTR]] = 
{{{.*}}"disable-tail-calls"="true"{{.*}}}
 
 typedef void (^BlockTy)(void);



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


[clang] ee51c42 - Reduce the number of attributes attached to each function

2021-02-19 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2021-02-20T06:57:47+01:00
New Revision: ee51c42e0060fc98b499312e51a96bc7cf4bcc18

URL: 
https://github.com/llvm/llvm-project/commit/ee51c42e0060fc98b499312e51a96bc7cf4bcc18
DIFF: 
https://github.com/llvm/llvm-project/commit/ee51c42e0060fc98b499312e51a96bc7cf4bcc18.diff

LOG: Reduce the number of attributes attached to each function

This takes advantage of the implicit default behavior to reduce the number of
attributes.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/test/CodeGen/attr-disable-tail-calls.c
clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
clang/test/CodeGenCXX/union-tbaa2.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 992e87319943..4ea707621b33 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2116,8 +2116,8 @@ void CodeGenModule::ConstructAttributeList(
 
   return false;
 };
-FuncAttrs.addAttribute("disable-tail-calls",
-   llvm::toStringRef(shouldDisableTailCalls()));
+if (shouldDisableTailCalls())
+  FuncAttrs.addAttribute("disable-tail-calls", "true");
 
 // CPU/feature overrides.  addDefaultFunctionDefinitionAttributes
 // handles these separately to set them based on the global defaults.

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index b393c88f7751..f552b27fee5e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -859,8 +859,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType 
RetTy,
   }
 
   // Add no-jump-tables value.
-  Fn->addFnAttr("no-jump-tables",
-llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables));
+  if (CGM.getCodeGenOpts().NoUseJumpTables)
+Fn->addFnAttr("no-jump-tables", "true");
 
   // Add no-inline-line-tables value.
   if (CGM.getCodeGenOpts().NoInlineLineTables)

diff  --git a/clang/test/CodeGen/attr-disable-tail-calls.c 
b/clang/test/CodeGen/attr-disable-tail-calls.c
index cd44346037f9..7ae241922813 100644
--- a/clang/test/CodeGen/attr-disable-tail-calls.c
+++ b/clang/test/CodeGen/attr-disable-tail-calls.c
@@ -15,5 +15,5 @@ int f2() __attribute__((disable_tail_calls)) {
 }
 
 // DISABLE: attributes [[ATTRTRUE]] = { 
{{.*}}"disable-tail-calls"="true"{{.*}} }
-// ENABLE: attributes [[ATTRFALSE]] = { 
{{.*}}"disable-tail-calls"="false"{{.*}} }
+// ENABLE-NOT: attributes [[ATTRFALSE]] = { 
{{.*}}"disable-tail-calls"="false"{{.*}} }
 // ENABLE: attributes [[ATTRTRUE]] = { {{.*}}"disable-tail-calls"="true"{{.*}} 
}

diff  --git a/clang/test/CodeGenCXX/attr-disable-tail-calls.cpp 
b/clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
index abd1031848df..a7d28f2d0091 100644
--- a/clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
+++ b/clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
@@ -30,6 +30,6 @@ int foo1() {
 // CHECK: define linkonce_odr i32 @_ZN1D2m1Ev(%class.D* {{[^,]*}} %this) 
unnamed_addr [[ATTRFALSE:#[0-9]+]]
 // CHECK: define linkonce_odr i32 @_ZN1D2m2Ev(%class.D* {{[^,]*}} %this) 
unnamed_addr [[ATTRTRUE1:#[0-9]+]]
 
-// CHECK: attributes [[ATTRFALSE]] = { 
{{.*}}"disable-tail-calls"="false"{{.*}} }
+// CHECK-NOT: attributes [[ATTRFALSE]] = { 
{{.*}}"disable-tail-calls"="false"{{.*}} }
 // CHECK: attributes [[ATTRTRUE0]] = { {{.*}}"disable-tail-calls"="true"{{.*}} 
}
 // CHECK: attributes [[ATTRTRUE1]] = { {{.*}}"disable-tail-calls"="true"{{.*}} 
}

diff  --git a/clang/test/CodeGenCXX/union-tbaa2.cpp 
b/clang/test/CodeGenCXX/union-tbaa2.cpp
index 65872d4a98ae..ba2a8a222a22 100644
--- a/clang/test/CodeGenCXX/union-tbaa2.cpp
+++ b/clang/test/CodeGenCXX/union-tbaa2.cpp
@@ -20,7 +20,6 @@ struct A {
 // CHECK: tbaa ![[OCPATH:[0-9]+]]
 // CHECK: store <4 x double>
 // CHECK: tbaa ![[OCPATH]]
-// CHECK: call
 a = _mm256_setr_pd(0.0, 1.0, 2.0, 3.0);
 b = _mm256_setr_pd(4.0, 5.0, 6.0, 7.0);
   }



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


[clang] caf28b0 - [Diagnostics] Diagnose -Wsizeof-array-div for array of pointers

2020-10-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-10-09T12:56:06+02:00
New Revision: caf28b0a1288eb06720acf11d7ad09186b27b74f

URL: 
https://github.com/llvm/llvm-project/commit/caf28b0a1288eb06720acf11d7ad09186b27b74f
DIFF: 
https://github.com/llvm/llvm-project/commit/caf28b0a1288eb06720acf11d7ad09186b27b74f.diff

LOG: [Diagnostics] Diagnose  -Wsizeof-array-div for array of pointers

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/div-sizeof-array.cpp
clang/test/Sema/div-sizeof-ptr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index dd2e8f8c0d25..26271209b78d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10036,7 +10036,7 @@ static void DiagnoseDivisionSizeofPointerOrArray(Sema 
&S, Expr *LHS, Expr *RHS,
   QualType RHSTy;
 
   if (RUE->isArgumentType())
-RHSTy = RUE->getArgumentType();
+RHSTy = RUE->getArgumentType().getNonReferenceType();
   else
 RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
 

diff  --git a/clang/test/Sema/div-sizeof-array.cpp 
b/clang/test/Sema/div-sizeof-array.cpp
index 898ff42a7bd4..f4d8c2d2a5fb 100644
--- a/clang/test/Sema/div-sizeof-array.cpp
+++ b/clang/test/Sema/div-sizeof-array.cpp
@@ -46,4 +46,8 @@ void test(void) {
   int array[10];
   int narray = sizeof(array) / sizeof(int &);
   int narray2 = sizeof(array) / sizeof(decltype(array[0]));
+
+  int *arrptrs[10];  // expected-note 
{{array 'arrptrs' declared here}}
+  int len = sizeof(arrptrs) / sizeof(decltype(*arrptrs[0])); // 
expected-warning {{expression does not compute the number of elements in this 
array; element type is 'int *', not 'int'}}
+  // expected-note@-1 {{place parentheses around the 
'sizeof(decltype(*arrptrs[0]))' expression to silence this warning}}
 }

diff  --git a/clang/test/Sema/div-sizeof-ptr.cpp 
b/clang/test/Sema/div-sizeof-ptr.cpp
index abb7bbadf0e4..dcb05ccd0162 100644
--- a/clang/test/Sema/div-sizeof-ptr.cpp
+++ b/clang/test/Sema/div-sizeof-ptr.cpp
@@ -7,7 +7,7 @@ int f(Ty (&Array)[N]) {
 
 typedef int int32;
 
-void test(int *p, int **q) {  // expected-note 5 {{pointer 'p' 
declared here}}
+void test(int *p, int **q) {  // expected-note 6 {{pointer 'p' 
declared here}}
   const int *r;   // expected-note {{pointer 'r' declared 
here}}
   int a1 = sizeof(p) / sizeof(*p);// expected-warning {{'sizeof (p)' will 
return the size of the pointer, not the array itself}}
   int a2 = sizeof p / sizeof *p;  // expected-warning {{'sizeof p' will 
return the size of the pointer, not the array itself}}
@@ -21,6 +21,7 @@ void test(int *p, int **q) {  // expected-note 5 
{{pointer 'p' declared
   int a8 = sizeof(d) / sizeof(int);  // expected-warning {{'sizeof (d)' will 
return the size of the pointer, not the array itself}}
 
   int a9 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will 
return the size of the pointer, not the array itself}}
+  int a10 = sizeof(p) / sizeof(decltype(*p)); // expected-warning {{'sizeof 
(p)' will return the size of the pointer, not the array itself}}
 
   // Should not warn
   int b1 = sizeof(int *) / sizeof(int);



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


Re: [clang] 2ae1822 - [Diagnostics] Fixed -Wsizeof-array-div false positive when divisor is sizeof reference type (PR47495)

2020-09-20 Thread Dávid Bolvanský via cfe-commits
Thanks,

I uploaded https://reviews.llvm.org/D87990 to fix this issue.

ne 20. 9. 2020 o 19:58 Richard Smith  napísal(a):
>
> On Sun, 20 Sep 2020 at 08:43, Dávid Bolvanský via cfe-commits 
>  wrote:
>>
>> Author: Dávid Bolvanský
>> Date: 2020-09-20T17:43:06+02:00
>> New Revision: 2ae182258c49724e4daaae196de829ea65c116e8
>>
>> URL: 
>> https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8
>> DIFF: 
>> https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8.diff
>>
>> LOG: [Diagnostics] Fixed -Wsizeof-array-div false positive when divisor is 
>> sizeof reference type (PR47495)
>>
>> Added:
>>
>>
>> Modified:
>> clang/lib/Sema/SemaExpr.cpp
>> clang/test/Sema/div-sizeof-array.cpp
>>
>> Removed:
>>
>>
>>
>> 
>> diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
>> index 501e1aed1509..736a6c166eb3 100644
>> --- a/clang/lib/Sema/SemaExpr.cpp
>> +++ b/clang/lib/Sema/SemaExpr.cpp
>> @@ -10038,7 +10038,7 @@ static void 
>> DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS,
>>  QualType ArrayElemTy = ArrayTy->getElementType();
>>  if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) ||
>>  ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
>> -ArrayElemTy->isCharType() ||
>> +RHSTy->isReferenceType() || ArrayElemTy->isCharType() ||
>
>
> Instead of skipping the check for a reference type, could we instead replace 
> RHSTy with its referenced type for the purpose of the check when RHSTy is a 
> reference type? I think we do want to diagnose (for example) sizeof(array) / 
> sizeof(decltype(*array[0])) for an array of pointers.
>
>>
>>  S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy))
>>return;
>>  S.Diag(Loc, diag::warn_division_sizeof_array)
>>
>> diff  --git a/clang/test/Sema/div-sizeof-array.cpp 
>> b/clang/test/Sema/div-sizeof-array.cpp
>> index e295a9dec6d8..898ff42a7bd4 100644
>> --- a/clang/test/Sema/div-sizeof-array.cpp
>> +++ b/clang/test/Sema/div-sizeof-array.cpp
>> @@ -42,4 +42,8 @@ void test(void) {
>>
>>float m[4][4];
>>int d1 = sizeof(m) / sizeof(**m);
>> +
>> +  int array[10];
>> +  int narray = sizeof(array) / sizeof(int &);
>> +  int narray2 = sizeof(array) / sizeof(decltype(array[0]));
>>  }
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2ae1822 - [Diagnostics] Fixed -Wsizeof-array-div false positive when divisor is sizeof reference type (PR47495)

2020-09-20 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-09-20T17:43:06+02:00
New Revision: 2ae182258c49724e4daaae196de829ea65c116e8

URL: 
https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8
DIFF: 
https://github.com/llvm/llvm-project/commit/2ae182258c49724e4daaae196de829ea65c116e8.diff

LOG: [Diagnostics] Fixed -Wsizeof-array-div false positive when divisor is 
sizeof reference type (PR47495)

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/div-sizeof-array.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 501e1aed1509..736a6c166eb3 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10038,7 +10038,7 @@ static void DiagnoseDivisionSizeofPointerOrArray(Sema 
&S, Expr *LHS, Expr *RHS,
 QualType ArrayElemTy = ArrayTy->getElementType();
 if (ArrayElemTy != S.Context.getBaseElementType(ArrayTy) ||
 ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
-ArrayElemTy->isCharType() ||
+RHSTy->isReferenceType() || ArrayElemTy->isCharType() ||
 S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy))
   return;
 S.Diag(Loc, diag::warn_division_sizeof_array)

diff  --git a/clang/test/Sema/div-sizeof-array.cpp 
b/clang/test/Sema/div-sizeof-array.cpp
index e295a9dec6d8..898ff42a7bd4 100644
--- a/clang/test/Sema/div-sizeof-array.cpp
+++ b/clang/test/Sema/div-sizeof-array.cpp
@@ -42,4 +42,8 @@ void test(void) {
 
   float m[4][4];
   int d1 = sizeof(m) / sizeof(**m);
+
+  int array[10];
+  int narray = sizeof(array) / sizeof(int &);
+  int narray2 = sizeof(array) / sizeof(decltype(array[0]));
 }



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


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-13 Thread Dávid Bolvanský via cfe-commits
Done


> Dňa 13. 8. 2020 o 7:29 užívateľ Arthur Eubanks via Phabricator 
>  napísal:
> 
> aeubanks added a comment.
> 
> It still seems to trigger on structs at head:
> 
> $ cat /tmp/a.cc
> struct A {
> 
>  const char *a;
>  const char *b;
>  const char *c;
> 
> };
> 
> static A a = {"",
> 
>  ""
>  "",
>  ""};
> 
> $ ./build/bin/clang++ -Wstring-concatenation -o /dev/null -c /tmp/a.cc
> C:/src/tmp/a.cc:10:15: warning: suspicious concatenation of string literals 
> in an array initialization; did you mean to separate the elements with a 
> comma? [-Wstring-concatenation]
> 
>  "",
>  ^
> 
> C:/src/tmp/a.cc:9:15: note: place parentheses around the string literal to 
> silence warning
> 
>  ""
>  ^
> 
> 1 warning generated.
> 
> 
> Repository:
>  rG LLVM Github Monorepo
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D85545/new/
> 
> https://reviews.llvm.org/D85545
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2f7adf5 - [Diagnostics] Skip var decl of structs for -Wstring-concatenation

2020-08-13 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-13T20:20:26+02:00
New Revision: 2f7adf5ee37934ee5769276644fcafbc9d4dcda3

URL: 
https://github.com/llvm/llvm-project/commit/2f7adf5ee37934ee5769276644fcafbc9d4dcda3
DIFF: 
https://github.com/llvm/llvm-project/commit/2f7adf5ee37934ee5769276644fcafbc9d4dcda3.diff

LOG: [Diagnostics] Skip var decl of structs for -Wstring-concatenation

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fee748bf9f9d..ab1496337210 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12886,7 +12886,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {

AttributeCommonInfo::AS_Pragma));
   }
 
-  if (var->hasInit() && isa(var->getInit())) {
+  if (!var->getType()->isStructureType() && var->hasInit() &&
+  isa(var->getInit())) {
 const auto *ILE = cast(var->getInit());
 unsigned NumInits = ILE->getNumInits();
 if (NumInits > 2)
@@ -12927,7 +12928,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 Diag(SL->getBeginLoc(),
  diag::note_concatenated_string_literal_silence);
   }
-  // Warn just once.
+  // In any case, stop now.
   break;
 }
   }

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index b6bae9c95b0b..63abf100c020 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -148,6 +148,12 @@ const A not_warn6 =  A{"",
   ""};
 #endif
 
+static A not_warn7 = {"",
+
+  ""
+  "",
+  ""};
+
 
 // Do not warn when all the elements in the initializer are concatenated 
together.
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};



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


[clang] df3bfaa - [Driver] Change -fnostack-clash-protection to -fno-stack-clash-protection

2020-08-12 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-12T18:36:26+02:00
New Revision: df3bfaa39071a1382a59a94658ee1a2da30d92fd

URL: 
https://github.com/llvm/llvm-project/commit/df3bfaa39071a1382a59a94658ee1a2da30d92fd
DIFF: 
https://github.com/llvm/llvm-project/commit/df3bfaa39071a1382a59a94658ee1a2da30d92fd.diff

LOG: [Driver] Change -fnostack-clash-protection to  -fno-stack-clash-protection

Clang command line docs mention `-fno-stack-clash-protection`, and GCC also 
uses  -fno-stack-clash-protection.

Fixes PR47139

Reviewed By: tstellar

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/stack-clash-protection.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e09b6468eea7..99a2ec7ad2d4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1794,7 +1794,7 @@ def fstack_protector_all : Flag<["-"], 
"fstack-protector-all">, Group,
   HelpText<"Enable stack protectors for all functions">;
 def fstack_clash_protection : Flag<["-"], "fstack-clash-protection">, 
Group, Flags<[CC1Option]>,
   HelpText<"Enable stack clash protection">;
-def fnostack_clash_protection : Flag<["-"], "fnostack-clash-protection">, 
Group,
+def fno_stack_clash_protection : Flag<["-"], "fno-stack-clash-protection">, 
Group,
   HelpText<"Disable stack clash protection">;
 def fstack_protector_strong : Flag<["-"], "fstack-protector-strong">, 
Group,
   HelpText<"Enable stack protectors for some functions vulnerable to stack 
smashing. "

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 50fe1fcd1615..82cf2538338f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2978,7 +2978,7 @@ static void RenderSCPOptions(const ToolChain &TC, const 
ArgList &Args,
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,
-   options::OPT_fnostack_clash_protection, false))
+   options::OPT_fno_stack_clash_protection, false))
 CmdArgs.push_back("-fstack-clash-protection");
 }
 

diff  --git a/clang/test/Driver/stack-clash-protection.c 
b/clang/test/Driver/stack-clash-protection.c
index a2cf3f82a8fd..5217ed26a5b1 100644
--- a/clang/test/Driver/stack-clash-protection.c
+++ b/clang/test/Driver/stack-clash-protection.c
@@ -1,6 +1,6 @@
 // RUN: %clang -target i386-unknown-linux -fstack-clash-protection -### %s 
2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fnostack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fnostack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
+// RUN: %clang -target i386-unknown-linux -fno-stack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
+// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fno-stack-clash-protection -### %s 2>&1 | FileCheck %s 
-check-prefix=SCP-i386-NO
 // SCP-i386: "-fstack-clash-protection"
 // SCP-i386-NO-NOT: "-fstack-clash-protection"
 



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


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-11 Thread Dávid Bolvanský via cfe-commits
Reworked ;) Now it should ignore structs properly.

ut 11. 8. 2020 o 22:03 Arthur O'Dwyer  napísal(a):
>
> Dávid: Please just disable it for initializers of structs. That seems to be 
> the common denominator in all the false positives I've observed on this 
> thread.
>
>
> On Tue, Aug 11, 2020 at 3:07 PM Dávid Bolvanský  
> wrote:
>>
>> Ok, I will bump that limit + 1.
>>
>> ut 11. 8. 2020 o 20:52 Arthur Eubanks via Phabricator
>>  napísal(a):
>> >
>> > aeubanks added a comment.
>> >
>> > In D85545#2211070 , @xbolva00 
>> > wrote:
>> >
>> > > I check if all elements of init list are strings, so this is not
>> > > exactly true "struct checker" (I have no such info in that part of
>> > > code..) but I consider it good enough. Your test case is based on real
>> > > code? Does not seem so - well sure, we could construct many examples
>> > > where warning fires uselessly but my focus is on real world false
>> > > positive cases :)
>> > >
>> > > ut 11. 8. 2020 o 19:55 Arthur Eubanks via Phabricator
>> > >  napísal(a):
>> > >
>> > >> aeubanks added a comment.
>> > >>
>> > >> Actually sorry, it does still seem like there are false positives on 
>> > >> structs. Reduced:
>> > >>
>> > >>   $ cat /tmp/a.cpp
>> > >>
>> > >>   struct A {
>> > >> const char* a;
>> > >> const char* b;
>> > >> const char* c;
>> > >>   };
>> > >>
>> > >>   static constexpr A foo2 = A{"",
>> > >>   ""
>> > >>   "",
>> > >>   ""};
>> > >>
>> > >>   $ ~/repos/llvm-project/build_cmake/bin/clang /tmp/a.cpp -o /dev/null 
>> > >> -c -Wstring-concatenation
>> > >>   /tmp/a.cpp:10:29: warning: suspicious concatenation of string 
>> > >> literals in an array initialization; did you mean to separate the 
>> > >> elements with a comma? [-Wstring-concatenation]
>> > >>   "",
>> > >>   ^
>> > >>   /tmp/a.cpp:9:29: note: place parentheses around the string literal to 
>> > >> silence warning
>> > >>   ""
>> > >>   ^
>> > >>   1 warning generated.
>> > >>
>> > >> Repository:
>> > >>
>> > >>   rG LLVM Github Monorepo
>> > >>
>> > >> CHANGES SINCE LAST ACTION
>> > >>
>> > >>   https://reviews.llvm.org/D85545/new/
>> > >>
>> > >> https://reviews.llvm.org/D85545
>> >
>> > Yup it's reduced from real world code, same link as before: 
>> > https://source.chromium.org/chromium/chromium/src/+/master:third_party/dawn/src/dawn_native/Toggles.cpp;drc=80f927d763211ea8e6a6377f86282809c86dc107;l=32.
>> > Clearly if there are 3 strings in the struct and the initializer has three 
>> > strings, then the warning shouldn't apply.
>> >
>> >
>> > Repository:
>> >   rG LLVM Github Monorepo
>> >
>> > CHANGES SINCE LAST ACTION
>> >   https://reviews.llvm.org/D85545/new/
>> >
>> > https://reviews.llvm.org/D85545
>> >
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b9af72b - [Diagnostics] Reworked -Wstring-concatenation

2020-08-11 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-12T02:18:01+02:00
New Revision: b9af72bffe5f2769f3a7858a785981f89137a0ce

URL: 
https://github.com/llvm/llvm-project/commit/b9af72bffe5f2769f3a7858a785981f89137a0ce
DIFF: 
https://github.com/llvm/llvm-project/commit/b9af72bffe5f2769f3a7858a785981f89137a0ce.diff

LOG: [Diagnostics] Reworked -Wstring-concatenation

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 77e15f187e53..fee748bf9f9d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12886,6 +12886,53 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {

AttributeCommonInfo::AS_Pragma));
   }
 
+  if (var->hasInit() && isa(var->getInit())) {
+const auto *ILE = cast(var->getInit());
+unsigned NumInits = ILE->getNumInits();
+if (NumInits > 2)
+  for (unsigned I = 0; I < NumInits; ++I) {
+const auto *Init = ILE->getInit(I);
+if (!Init)
+  break;
+const auto *SL = dyn_cast(Init->IgnoreImpCasts());
+if (!SL)
+  break;
+
+unsigned NumConcat = SL->getNumConcatenated();
+// Diagnose missing comma in string array initialization.
+// Do not warn when all the elements in the initializer are 
concatenated
+// together. Do not warn for macros too.
+if (NumConcat == 2 && !SL->getBeginLoc().isMacroID()) {
+  bool OnlyOneMissingComma = true;
+  for (unsigned J = I + 1; J < NumInits; ++J) {
+const auto *Init = ILE->getInit(J);
+if (!Init)
+  break;
+const auto *SLJ = dyn_cast(Init->IgnoreImpCasts());
+if (!SLJ || SLJ->getNumConcatenated() > 1) {
+  OnlyOneMissingComma = false;
+  break;
+}
+  }
+
+  if (OnlyOneMissingComma) {
+SmallVector Hints;
+for (unsigned i = 0; i < NumConcat - 1; ++i)
+  Hints.push_back(FixItHint::CreateInsertion(
+  PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ","));
+
+Diag(SL->getStrTokenLoc(1),
+ diag::warn_concatenated_literal_array_init)
+<< Hints;
+Diag(SL->getBeginLoc(),
+ diag::note_concatenated_string_literal_silence);
+  }
+  // Warn just once.
+  break;
+}
+  }
+  }
+
   // All the following checks are C++ only.
   if (!getLangOpts().CPlusPlus) {
   // If this variable must be emitted, add it as an initializer for the

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bea693f999ab..5e9fca13f1d0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6870,7 +6870,6 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
   bool DiagnosedArrayDesignator = false;
   bool DiagnosedNestedDesignator = false;
   bool DiagnosedMixedDesignator = false;
-  bool DiagnosedMissingComma = false;
 
   // Check that any designated initializers are syntactically valid in the
   // current language mode.
@@ -6912,37 +6911,6 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
 << DIE->getSourceRange();
   Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed)
 << InitArgList[I]->getSourceRange();
-} else if (const auto *SL = dyn_cast(InitArgList[I])) {
-  unsigned NumConcat = SL->getNumConcatenated();
-  // Diagnose missing comma in string array initialization.
-  // Do not warn when all the elements in the initializer are concatenated
-  // together. Do not warn for macros too.
-  if (!DiagnosedMissingComma && NumConcat == 2 && E > 2 && 
!SL->getBeginLoc().isMacroID()) {
-bool OnlyOneMissingComma = true;
-for (unsigned J = 0; J < E; ++J) {
-  if (J == I)
-continue;
-  const auto *SLJ = dyn_cast(InitArgList[J]);
-  if (!SLJ || SLJ->getNumConcatenated() > 1) {
-OnlyOneMissingComma = false;
-break;
-  }
-}
-
-if (OnlyOneMissingComma) {
-  SmallVector Hints;
-  for (unsigned i = 0; i < NumConcat - 1; ++i)
-Hints.push_back(FixItHint::CreateInsertion(
-PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ","));
-
-  Diag(SL->getStrTokenLoc(1),
-   diag::warn_concatenated_literal_array_init)
-  << Hints;
-  Diag(SL->getBeginLoc(),
-   diag::note_concatenated_string_literal_silence);
-  DiagnosedMissingComma = true;
-}
-  }
 }
   }
 

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index 3dcde8844dff..b6ba

Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-11 Thread Dávid Bolvanský via cfe-commits
Ok, I will bump that limit + 1.

ut 11. 8. 2020 o 20:52 Arthur Eubanks via Phabricator
 napísal(a):
>
> aeubanks added a comment.
>
> In D85545#2211070 , @xbolva00 wrote:
>
> > I check if all elements of init list are strings, so this is not
> > exactly true "struct checker" (I have no such info in that part of
> > code..) but I consider it good enough. Your test case is based on real
> > code? Does not seem so - well sure, we could construct many examples
> > where warning fires uselessly but my focus is on real world false
> > positive cases :)
> >
> > ut 11. 8. 2020 o 19:55 Arthur Eubanks via Phabricator
> >  napísal(a):
> >
> >> aeubanks added a comment.
> >>
> >> Actually sorry, it does still seem like there are false positives on 
> >> structs. Reduced:
> >>
> >>   $ cat /tmp/a.cpp
> >>
> >>   struct A {
> >> const char* a;
> >> const char* b;
> >> const char* c;
> >>   };
> >>
> >>   static constexpr A foo2 = A{"",
> >>   ""
> >>   "",
> >>   ""};
> >>
> >>   $ ~/repos/llvm-project/build_cmake/bin/clang /tmp/a.cpp -o /dev/null -c 
> >> -Wstring-concatenation
> >>   /tmp/a.cpp:10:29: warning: suspicious concatenation of string literals 
> >> in an array initialization; did you mean to separate the elements with a 
> >> comma? [-Wstring-concatenation]
> >>   "",
> >>   ^
> >>   /tmp/a.cpp:9:29: note: place parentheses around the string literal to 
> >> silence warning
> >>   ""
> >>   ^
> >>   1 warning generated.
> >>
> >> Repository:
> >>
> >>   rG LLVM Github Monorepo
> >>
> >> CHANGES SINCE LAST ACTION
> >>
> >>   https://reviews.llvm.org/D85545/new/
> >>
> >> https://reviews.llvm.org/D85545
>
> Yup it's reduced from real world code, same link as before: 
> https://source.chromium.org/chromium/chromium/src/+/master:third_party/dawn/src/dawn_native/Toggles.cpp;drc=80f927d763211ea8e6a6377f86282809c86dc107;l=32.
> Clearly if there are 3 strings in the struct and the initializer has three 
> strings, then the warning shouldn't apply.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D85545/new/
>
> https://reviews.llvm.org/D85545
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-11 Thread Dávid Bolvanský via cfe-commits
I check if all elements of init list are strings, so this is not
exactly true "struct checker" (I have no such info in that part of
code..) but I consider it good enough. Your test case is based on real
code? Does not seem so - well sure, we could construct many examples
where warning fires uselessly but my focus is on real world false
positive cases :)

ut 11. 8. 2020 o 19:55 Arthur Eubanks via Phabricator
 napísal(a):
>
> aeubanks added a comment.
>
> Actually sorry, it does still seem like there are false positives on structs. 
> Reduced:
>
>   $ cat /tmp/a.cpp
>
>   struct A {
> const char* a;
> const char* b;
> const char* c;
>   };
>
>   static constexpr A foo2 = A{"",
>   ""
>   "",
>   ""};
>
>   $ ~/repos/llvm-project/build_cmake/bin/clang /tmp/a.cpp -o /dev/null -c 
> -Wstring-concatenation
>   /tmp/a.cpp:10:29: warning: suspicious concatenation of string literals in 
> an array initialization; did you mean to separate the elements with a comma? 
> [-Wstring-concatenation]
>   "",
>   ^
>   /tmp/a.cpp:9:29: note: place parentheses around the string literal to 
> silence warning
>   ""
>   ^
>   1 warning generated.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D85545/new/
>
> https://reviews.llvm.org/D85545
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-10 Thread Dávid Bolvanský via cfe-commits
Pushed fix. It should not warn for structs or long texts.

ut 11. 8. 2020 o 0:34 Arthur Eubanks via Phabricator
 napísal(a):
>
> aeubanks added a comment.
>
> In D85545#2208266 , @arthur.j.odwyer 
> wrote:
>
> > To decrease the number of false-positives, you could emit the warning only
> > if *exactly one* comma was missing.
> >
> >   const char *likely_a_bug[] = { "a", "b", "c" "d", "e", "f", "g", "h",
> >
> > "i" };
> >
> >   const char *likely_not_a_bug[] = { "a", "b" "c", "d" "e", "f" "g" };
> >   const char *oops_still_a_bug[] = { "a", "b", "c" "d", "e", "f" "g",
> >
> > "h", "i" };
> >
> > However, as `oops_still_a_bug` shows, that tactic would also decrease the
> > number of true positives, and it would confuse the end-user, for whom
> > predictability is key.
> >
> > I still think it would be appropriate to *stop issuing the warning for
> > structs*, though.
> > Here's my struct example from below in Godbolt: https://godbolt.org/z/6jjv6a
> > Speaking of predictability, I don't understand why `struct Y` avoids the
> > warning whereas `struct X` hits it.
> > After removing the warning for structs, neither `X` nor `Y` should hit it,
> > and that should fix pretty much all the Firefox hits as I understand them.
> >
> > –Arthur
>
> +1 to ignoring structs. See https://crbug.com/1114873 and 
> https://source.chromium.org/chromium/chromium/src/+/master:third_party/dawn/src/dawn_native/Toggles.cpp;drc=80f927d763211ea8e6a6377f86282809c86dc107;l=32.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D85545/new/
>
> https://reviews.llvm.org/D85545
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b59dc7 - [Diagnostics] Ignore structs and long text for -Wstring-concatenation

2020-08-10 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-11T00:49:58+02:00
New Revision: 4b59dc77dc473bba849c1b08f3a1ab7be5733ad1

URL: 
https://github.com/llvm/llvm-project/commit/4b59dc77dc473bba849c1b08f3a1ab7be5733ad1
DIFF: 
https://github.com/llvm/llvm-project/commit/4b59dc77dc473bba849c1b08f3a1ab7be5733ad1.diff

LOG: [Diagnostics] Ignore structs and long text for -Wstring-concatenation

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 28ac1dfeb082..0d7f81e0d01a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6865,6 +6865,7 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
   bool DiagnosedArrayDesignator = false;
   bool DiagnosedNestedDesignator = false;
   bool DiagnosedMixedDesignator = false;
+  bool DiagnosedMissingComma = false;
 
   // Check that any designated initializers are syntactically valid in the
   // current language mode.
@@ -6908,22 +6909,34 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
 << InitArgList[I]->getSourceRange();
 } else if (const auto *SL = dyn_cast(InitArgList[I])) {
   unsigned NumConcat = SL->getNumConcatenated();
-  const auto *SLPrev =
-  dyn_cast(InitArgList[I == 0 ? E - 1 : I - 1]);
   // Diagnose missing comma in string array initialization.
   // Do not warn when all the elements in the initializer are concatenated
   // together. Do not warn for macros too.
-  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() &&
-  isa(InitArgList[0]) && SLPrev &&
-  NumConcat != SLPrev->getNumConcatenated()) {
-SmallVector Hints;
-for (unsigned i = 0; i < NumConcat - 1; ++i)
-  Hints.push_back(FixItHint::CreateInsertion(
-  PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ","));
-
-Diag(SL->getStrTokenLoc(1), diag::warn_concatenated_literal_array_init)
-<< Hints;
-Diag(SL->getBeginLoc(), 
diag::note_concatenated_string_literal_silence);
+  if (!DiagnosedMissingComma && NumConcat == 2 && E > 2 && 
!SL->getBeginLoc().isMacroID()) {
+bool OnlyOneMissingComma = true;
+for (unsigned J = 0; J < E; ++J) {
+  if (J == I)
+continue;
+  const auto *SLJ = dyn_cast(InitArgList[J]);
+  if (!SLJ || SLJ->getNumConcatenated() > 1) {
+OnlyOneMissingComma = false;
+break;
+  }
+}
+
+if (OnlyOneMissingComma) {
+  SmallVector Hints;
+  for (unsigned i = 0; i < NumConcat - 1; ++i)
+Hints.push_back(FixItHint::CreateInsertion(
+PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ","));
+
+  Diag(SL->getStrTokenLoc(1),
+   diag::warn_concatenated_literal_array_init)
+  << Hints;
+  Diag(SL->getBeginLoc(),
+   diag::note_concatenated_string_literal_silence);
+  DiagnosedMissingComma = true;
+}
   }
 }
   }

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index 4e5ed4424e7c..3dcde8844dff 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -32,12 +32,6 @@ const char *missing_comma_u8[] = {
 };
 #endif
 
-const char *missing_two_commas[] = {"basic_filebuf",
-   "basic_ios" // expected-note{{place parentheses around 
the string literal to silence warning}}
-   "future"// expected-warning{{suspicious 
concatenation of string literals in an array initialization; did you mean to 
separate the elements with a comma?}}
-   "optional",
-   "packaged_task"};
-
 const char *missing_comma_same_line[] = {"basic_filebuf", "basic_ios",
"future" "optional", // expected-note{{place 
parentheses around the string literal to silence warning}}
"packaged_task", "promise"}; // 
expected-warning@-1{{suspicious concatenation of string literals in an array 
initialization; did you mean to separate the elements with a comma?}}
@@ -56,12 +50,20 @@ char missing_comma_inner[][5] = {
 "d" // expected-warning{{suspicious concatenation of string literals in an 
array initialization; did you mean to separate the elements with a comma?}}
 };
 
+const char *warn[] = { "cpll", "gpll", "hdmiphy" "usb480m" }; // 
expected-note{{place parentheses around the string literal to silence warning}}
+// expected-warning@-1{{suspicious concatenation of string literals in an 
array initialization; did you mean to separate the elements with a comma?}}
+
+const char *missing_two_commas_ignore[] = {"basic_filebuf",
+   "basic_ios" 
+   "future"  
+   "optio

Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-10 Thread Dávid Bolvanský via cfe-commits
For your godbolt example, you hit the heuristic to not warn, if
literals count is <= 2. (motivated by many false positives; and I
didnt see a true positive case, so..)

>> you could emit the warning only if exactly one comma was missing.

This could work.

ut 11. 8. 2020 o 0:04 Arthur O'Dwyer  napísal(a):
>
> To decrease the number of false-positives, you could emit the warning only if 
> exactly one comma was missing.
>
> const char *likely_a_bug[] = { "a", "b", "c" "d", "e", "f", "g", "h", "i" 
> };
> const char *likely_not_a_bug[] = { "a", "b" "c", "d" "e", "f" "g" };
> const char *oops_still_a_bug[] = { "a", "b", "c" "d", "e", "f" "g", "h", 
> "i" };
>
> However, as `oops_still_a_bug` shows, that tactic would also decrease the 
> number of true positives, and it would confuse the end-user, for whom 
> predictability is key.
>
> I still think it would be appropriate to stop issuing the warning for 
> structs, though.
> Here's my struct example from below in Godbolt: https://godbolt.org/z/6jjv6a
> Speaking of predictability, I don't understand why `struct Y` avoids the 
> warning whereas `struct X` hits it.
> After removing the warning for structs, neither `X` nor `Y` should hit it, 
> and that should fix pretty much all the Firefox hits as I understand them.
>
> –Arthur
>
>
> On Mon, Aug 10, 2020 at 5:51 PM Dávid Bolvanský  
> wrote:
>>
>> Something like this:
>>   const char *Sources[] = {
>> "// \\tparam aaa Bbb\n",
>> "// \\tparam\n"
>> "// aaa Bbb\n",
>> "// \\tparam \n"
>> "// aaa Bbb\n",
>> "// \\tparam aaa\n"
>> "// Bbb\n"
>>   };
>>
>> annoys me :/ Any idea/heuristic how to avoid warning here?
>>
>> po 10. 8. 2020 o 23:48 Dávid Bolvanský  
>> napísal(a):
>> >
>> > For your cases, we currently do not warn. If possible, fetch the
>> > latest Clang trunk and re-evaluate on Firefox.
>> >
>> > po 10. 8. 2020 o 23:46 Arthur O'Dwyer  
>> > napísal(a):
>> > >
>> > > It looks to me as if all of the false-positives so far have been not 
>> > > arrays but structs.
>> > >
>> > > struct X { int a; const char *b; int c; };
>> > > X x = { 41, "forty" "two", 43 };  // false-positive here
>> > >
>> > > The distinguishing feature here is that if you did insert a comma as 
>> > > suggested by the compiler, then the result would no longer type-check.
>> > > X x = { 41, "forty", "two", 43 };  // this is ill-formed because "two" 
>> > > is not a valid initializer for `int c`
>> > >
>> > > Dávid, can you use this in some way?
>> > > IMHO it would be appropriate to just turn the warning off if the entity 
>> > > being initialized is a struct — leave the warning enabled only for 
>> > > initializers of arrays.
>> > >
>> > > my $.02,
>> > > –Arthur
>> > >
>> > >
>> > > On Mon, Aug 10, 2020 at 5:38 PM Dávid Bolvanský 
>> > >  wrote:
>> > >>
>> > >> I moved it to -Wextra due to false positives.
>> > >>
>> > >> > Should there be some exception for line length
>> > >>
>> > >> Yeah, but sure how to define the threshold or so. :/
>> > >>
>> > >> po 10. 8. 2020 o 23:21 dmajor via Phabricator
>> > >>  napísal(a):
>> > >> >
>> > >> > dmajor added a comment.
>> > >> >
>> > >> > In the Firefox repo this warning is firing on a number of strings 
>> > >> > that were broken up by clang-format (or humans) for line length, for 
>> > >> > example 
>> > >> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/security/certverifier/ExtendedValidation.cpp#176-178
>> > >> >  or 
>> > >> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/xpcom/tests/gtest/TestEscape.cpp#103-104
>> > >> >  or 
>> > >> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/js/src/jsapi-tests/testXDR.cpp#115.
>> > >> >
>> > >> > Do you consider these to be false positives in your view? Should 
>> > >> > there be some exception for line length, perhaps?
>> > >> >
>> > >> >
>> > >> > Repository:
>> > >> >   rG LLVM Github Monorepo
>> > >> >
>> > >> > CHANGES SINCE LAST ACTION
>> > >> >   https://reviews.llvm.org/D85545/new/
>> > >> >
>> > >> > https://reviews.llvm.org/D85545
>> > >> >
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-10 Thread Dávid Bolvanský via cfe-commits
Something like this:
  const char *Sources[] = {
"// \\tparam aaa Bbb\n",
"// \\tparam\n"
"// aaa Bbb\n",
"// \\tparam \n"
"// aaa Bbb\n",
"// \\tparam aaa\n"
"// Bbb\n"
  };

annoys me :/ Any idea/heuristic how to avoid warning here?

po 10. 8. 2020 o 23:48 Dávid Bolvanský  napísal(a):
>
> For your cases, we currently do not warn. If possible, fetch the
> latest Clang trunk and re-evaluate on Firefox.
>
> po 10. 8. 2020 o 23:46 Arthur O'Dwyer  napísal(a):
> >
> > It looks to me as if all of the false-positives so far have been not arrays 
> > but structs.
> >
> > struct X { int a; const char *b; int c; };
> > X x = { 41, "forty" "two", 43 };  // false-positive here
> >
> > The distinguishing feature here is that if you did insert a comma as 
> > suggested by the compiler, then the result would no longer type-check.
> > X x = { 41, "forty", "two", 43 };  // this is ill-formed because "two" is 
> > not a valid initializer for `int c`
> >
> > Dávid, can you use this in some way?
> > IMHO it would be appropriate to just turn the warning off if the entity 
> > being initialized is a struct — leave the warning enabled only for 
> > initializers of arrays.
> >
> > my $.02,
> > –Arthur
> >
> >
> > On Mon, Aug 10, 2020 at 5:38 PM Dávid Bolvanský  
> > wrote:
> >>
> >> I moved it to -Wextra due to false positives.
> >>
> >> > Should there be some exception for line length
> >>
> >> Yeah, but sure how to define the threshold or so. :/
> >>
> >> po 10. 8. 2020 o 23:21 dmajor via Phabricator
> >>  napísal(a):
> >> >
> >> > dmajor added a comment.
> >> >
> >> > In the Firefox repo this warning is firing on a number of strings that 
> >> > were broken up by clang-format (or humans) for line length, for example 
> >> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/security/certverifier/ExtendedValidation.cpp#176-178
> >> >  or 
> >> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/xpcom/tests/gtest/TestEscape.cpp#103-104
> >> >  or 
> >> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/js/src/jsapi-tests/testXDR.cpp#115.
> >> >
> >> > Do you consider these to be false positives in your view? Should there 
> >> > be some exception for line length, perhaps?
> >> >
> >> >
> >> > Repository:
> >> >   rG LLVM Github Monorepo
> >> >
> >> > CHANGES SINCE LAST ACTION
> >> >   https://reviews.llvm.org/D85545/new/
> >> >
> >> > https://reviews.llvm.org/D85545
> >> >
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-10 Thread Dávid Bolvanský via cfe-commits
For your cases, we currently do not warn. If possible, fetch the
latest Clang trunk and re-evaluate on Firefox.

po 10. 8. 2020 o 23:46 Arthur O'Dwyer  napísal(a):
>
> It looks to me as if all of the false-positives so far have been not arrays 
> but structs.
>
> struct X { int a; const char *b; int c; };
> X x = { 41, "forty" "two", 43 };  // false-positive here
>
> The distinguishing feature here is that if you did insert a comma as 
> suggested by the compiler, then the result would no longer type-check.
> X x = { 41, "forty", "two", 43 };  // this is ill-formed because "two" is not 
> a valid initializer for `int c`
>
> Dávid, can you use this in some way?
> IMHO it would be appropriate to just turn the warning off if the entity being 
> initialized is a struct — leave the warning enabled only for initializers of 
> arrays.
>
> my $.02,
> –Arthur
>
>
> On Mon, Aug 10, 2020 at 5:38 PM Dávid Bolvanský  
> wrote:
>>
>> I moved it to -Wextra due to false positives.
>>
>> > Should there be some exception for line length
>>
>> Yeah, but sure how to define the threshold or so. :/
>>
>> po 10. 8. 2020 o 23:21 dmajor via Phabricator
>>  napísal(a):
>> >
>> > dmajor added a comment.
>> >
>> > In the Firefox repo this warning is firing on a number of strings that 
>> > were broken up by clang-format (or humans) for line length, for example 
>> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/security/certverifier/ExtendedValidation.cpp#176-178
>> >  or 
>> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/xpcom/tests/gtest/TestEscape.cpp#103-104
>> >  or 
>> > https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/js/src/jsapi-tests/testXDR.cpp#115.
>> >
>> > Do you consider these to be false positives in your view? Should there be 
>> > some exception for line length, perhaps?
>> >
>> >
>> > Repository:
>> >   rG LLVM Github Monorepo
>> >
>> > CHANGES SINCE LAST ACTION
>> >   https://reviews.llvm.org/D85545/new/
>> >
>> > https://reviews.llvm.org/D85545
>> >
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-10 Thread Dávid Bolvanský via cfe-commits
I moved it to -Wextra due to false positives.

> Should there be some exception for line length

Yeah, but sure how to define the threshold or so. :/

po 10. 8. 2020 o 23:21 dmajor via Phabricator
 napísal(a):
>
> dmajor added a comment.
>
> In the Firefox repo this warning is firing on a number of strings that were 
> broken up by clang-format (or humans) for line length, for example 
> https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/security/certverifier/ExtendedValidation.cpp#176-178
>  or 
> https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/xpcom/tests/gtest/TestEscape.cpp#103-104
>  or 
> https://searchfox.org/mozilla-central/rev/ab81b8552f4aa9696a2524f97fdfeb59d4dc31c1/js/src/jsapi-tests/testXDR.cpp#115.
>
> Do you consider these to be false positives in your view? Should there be 
> some exception for line length, perhaps?
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D85545/new/
>
> https://reviews.llvm.org/D85545
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b2c9b63 - [Diagnostics] Move -Wstring-concatenation to -Wextra

2020-08-10 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-10T23:36:33+02:00
New Revision: b2c9b631bb48087c988d798adc5465499b155a9a

URL: 
https://github.com/llvm/llvm-project/commit/b2c9b631bb48087c988d798adc5465499b155a9a
DIFF: 
https://github.com/llvm/llvm-project/commit/b2c9b631bb48087c988d798adc5465499b155a9a.diff

LOG: [Diagnostics] Move -Wstring-concatenation to -Wextra

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 5ddd37e9972a..2b13f9eca12d 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -547,6 +547,7 @@ def StaticLocalInInline : 
DiagGroup<"static-local-in-inline">;
 def GNUStaticFloatInit : DiagGroup<"gnu-static-float-init">;
 def StaticFloatInit : DiagGroup<"static-float-init", [GNUStaticFloatInit]>;
 def GNUStatementExpression : DiagGroup<"gnu-statement-expression">;
+def StringConcatation : DiagGroup<"string-concatenation">;
 def StringCompare : DiagGroup<"string-compare">;
 def StringPlusInt : DiagGroup<"string-plus-int">;
 def StringPlusChar : DiagGroup<"string-plus-char">;
@@ -880,7 +881,8 @@ def Extra : DiagGroup<"extra", [
 SignCompare,
 UnusedParameter,
 NullPointerArithmetic,
-EmptyInitStatement
+EmptyInitStatement,
+StringConcatation
   ]>;
 
 def Most : DiagGroup<"most", [

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d0bddd80b8fe..f2e939da3050 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3005,7 +3005,7 @@ def warn_objc_string_literal_comparison : Warning<
 def warn_concatenated_literal_array_init : Warning<
   "suspicious concatenation of string literals in an array initialization; "
   "did you mean to separate the elements with a comma?">,
-  InGroup>;
+  InGroup, DefaultIgnore;
 def warn_concatenated_nsarray_literal : Warning<
   "concatenated NSString literal for an NSArray expression - "
   "possibly missing a comma">,

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f38238401fc..28ac1dfeb082 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6914,7 +6914,6 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
   // Do not warn when all the elements in the initializer are concatenated
   // together. Do not warn for macros too.
   if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() &&
-  SL->getString().find(" ") == llvm::StringRef::npos &&
   isa(InitArgList[0]) && SLPrev &&
   NumConcat != SLPrev->getNumConcatenated()) {
 SmallVector Hints;

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index 09de0a9bffbe..4e5ed4424e7c 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -1,6 +1,6 @@
 
-// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
-// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c -Wstring-concatenation -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c++ -Wstring-concatenation -fsyntax-only -verify %s
 
 const char *missing_comma[] = {
 "basic_filebuf",
@@ -110,19 +110,6 @@ const char *not_warn2[] = {
 "// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"
 };
 
-const char *not_warn3[] = {
-"// \\param [in,out] aaa Bbb\n",
-"// \\param[in,out] aaa Bbb\n",
-"// \\param [in, out] aaa Bbb\n",
-"// \\param [in,\n"
-"// out] aaa Bbb\n",
-"// \\param [in,out]\n"
-"// aaa Bbb\n",
-"// \\param [in,out] aaa\n"
-"// Bbb\n"
-};
-
-
 // Do not warn when all the elements in the initializer are concatenated 
together.
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
 



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


[clang] 62223ff - [Diagnostics] Avoid false positives with -Wstring-concatenation

2020-08-10 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-10T23:05:01+02:00
New Revision: 62223ff1376b540dc9612239fdfb11b376d796d3

URL: 
https://github.com/llvm/llvm-project/commit/62223ff1376b540dc9612239fdfb11b376d796d3
DIFF: 
https://github.com/llvm/llvm-project/commit/62223ff1376b540dc9612239fdfb11b376d796d3.diff

LOG: [Diagnostics] Avoid false positives with -Wstring-concatenation

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 23b2fbd5cbbf..8f38238401fc 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6908,13 +6908,15 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
 << InitArgList[I]->getSourceRange();
 } else if (const auto *SL = dyn_cast(InitArgList[I])) {
   unsigned NumConcat = SL->getNumConcatenated();
-  const auto *SLNext =
-  dyn_cast(InitArgList[I + 1 < E ? I + 1 : 0]);
+  const auto *SLPrev =
+  dyn_cast(InitArgList[I == 0 ? E - 1 : I - 1]);
   // Diagnose missing comma in string array initialization.
   // Do not warn when all the elements in the initializer are concatenated
   // together. Do not warn for macros too.
-  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() && SLNext &&
-  NumConcat != SLNext->getNumConcatenated()) {
+  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() &&
+  SL->getString().find(" ") == llvm::StringRef::npos &&
+  isa(InitArgList[0]) && SLPrev &&
+  NumConcat != SLPrev->getNumConcatenated()) {
 SmallVector Hints;
 for (unsigned i = 0; i < NumConcat - 1; ++i)
   Hints.push_back(FixItHint::CreateInsertion(

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index 13e9656d2536..09de0a9bffbe 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -108,7 +108,20 @@ const char *not_warn2[] = {
 "// Aaa\\\n"   " Bbb\\ \n"   " Ccc?" "?/\n",
 "// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
 "// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"
-  };
+};
+
+const char *not_warn3[] = {
+"// \\param [in,out] aaa Bbb\n",
+"// \\param[in,out] aaa Bbb\n",
+"// \\param [in, out] aaa Bbb\n",
+"// \\param [in,\n"
+"// out] aaa Bbb\n",
+"// \\param [in,out]\n"
+"// aaa Bbb\n",
+"// \\param [in,out] aaa\n"
+"// Bbb\n"
+};
+
 
 // Do not warn when all the elements in the initializer are concatenated 
together.
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};



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


Re: [PATCH] D85545: [Diagnostics] Diagnose missing comma in string array initialization

2020-08-10 Thread Dávid Bolvanský via cfe-commits
Logs look quite old.

http://lab.llvm.org:8011/builders/ppc64le-lld-multistage-test/builds/11291/steps/build-stage2-unified-tree/logs/stdio
are newest logs? Maybe I can tune the warning more to avoid false
positives.

po 10. 8. 2020 o 21:46 Kamau Bridgeman via Phabricator
 napísal(a):
>
> kamaub added a comment.
>
> Hello, sorry but can you please revert this commit and recommit it when you 
> have a fix or work around that doesn't break our bots:
> It breaks 
> http://lab.llvm.org:8011/builders/ppc64le-lld-multistage-test/builds/11228 
> which builds with `-Werror`
> Please also note that it introduced 103 warnings in 
> clang-ppc64le-linux-multistage/builds/13042 
> 
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D85545/new/
>
> https://reviews.llvm.org/D85545
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eeb7c49 - [AST] Fixed string list in test

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T23:17:48+02:00
New Revision: eeb7c496e385d2a88c39a0e0ebfe8a9908762cc3

URL: 
https://github.com/llvm/llvm-project/commit/eeb7c496e385d2a88c39a0e0ebfe8a9908762cc3
DIFF: 
https://github.com/llvm/llvm-project/commit/eeb7c496e385d2a88c39a0e0ebfe8a9908762cc3.diff

LOG: [AST] Fixed string list in test

Added: 


Modified: 
clang/unittests/AST/CommentParser.cpp

Removed: 




diff  --git a/clang/unittests/AST/CommentParser.cpp 
b/clang/unittests/AST/CommentParser.cpp
index 0be01a554f72..62c461a00d16 100644
--- a/clang/unittests/AST/CommentParser.cpp
+++ b/clang/unittests/AST/CommentParser.cpp
@@ -792,8 +792,8 @@ TEST_F(CommentParserTest, ParamCommand2) {
 
 TEST_F(CommentParserTest, ParamCommand3) {
   const char *Sources[] = {
-("// \\param aaa Bbb\n",
-"// \\param\n"
+"// \\param aaa Bbb\n",
+("// \\param\n"
 "// aaa Bbb\n"),
 ("// \\param \n"
 "// aaa Bbb\n"),



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


[clang] 9658647 - [AST] Fixed string concatenation warnings

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T23:09:19+02:00
New Revision: 9658647d72d24f339f8b8129da9f116c358f30d5

URL: 
https://github.com/llvm/llvm-project/commit/9658647d72d24f339f8b8129da9f116c358f30d5
DIFF: 
https://github.com/llvm/llvm-project/commit/9658647d72d24f339f8b8129da9f116c358f30d5.diff

LOG: [AST] Fixed string concatenation warnings

Added: 


Modified: 
clang/unittests/AST/CommentParser.cpp

Removed: 




diff  --git a/clang/unittests/AST/CommentParser.cpp 
b/clang/unittests/AST/CommentParser.cpp
index ba8b34ebcd38..0be01a554f72 100644
--- a/clang/unittests/AST/CommentParser.cpp
+++ b/clang/unittests/AST/CommentParser.cpp
@@ -628,40 +628,40 @@ TEST_F(CommentParserTest, Basic3) {
 
 TEST_F(CommentParserTest, ParagraphSplitting1) {
   const char *Sources[] = {
-"// Aaa\n"
+("// Aaa\n"
 "//\n"
-"// Bbb",
+"// Bbb"),
 
-"// Aaa\n"
+("// Aaa\n"
 "// \n"
-"// Bbb",
+"// Bbb"),
 
-"// Aaa\n"
+("// Aaa\n"
 "//\t\n"
-"// Bbb",
+"// Bbb"),
 
-"// Aaa\n"
+("// Aaa\n"
 "//\n"
 "//\n"
-"// Bbb",
+"// Bbb"),
 
-"/**\n"
+("/**\n"
 " Aaa\n"
 "\n"
 " Bbb\n"
-"*/",
+"*/"),
 
-"/**\n"
+("/**\n"
 " Aaa\n"
 " \n"
 " Bbb\n"
-"*/",
+"*/"),
 
-"/**\n"
+("/**\n"
 " Aaa\n"
 "\t \n"
 " Bbb\n"
-"*/",
+"*/"),
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
@@ -792,13 +792,13 @@ TEST_F(CommentParserTest, ParamCommand2) {
 
 TEST_F(CommentParserTest, ParamCommand3) {
   const char *Sources[] = {
-"// \\param aaa Bbb\n",
+("// \\param aaa Bbb\n",
 "// \\param\n"
-"// aaa Bbb\n",
-"// \\param \n"
-"// aaa Bbb\n",
-"// \\param aaa\n"
-"// Bbb\n"
+"// aaa Bbb\n"),
+("// \\param \n"
+"// aaa Bbb\n"),
+("// \\param aaa\n"
+"// Bbb\n")
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
@@ -823,12 +823,12 @@ TEST_F(CommentParserTest, ParamCommand4) {
   const char *Sources[] = {
 "// \\param [in] aaa Bbb\n",
 "// \\param[in] aaa Bbb\n",
-"// \\param\n"
-"// [in] aaa Bbb\n",
-"// \\param [in]\n"
-"// aaa Bbb\n",
-"// \\param [in] aaa\n"
-"// Bbb\n",
+("// \\param\n"
+"// [in] aaa Bbb\n"),
+("// \\param [in]\n"
+"// aaa Bbb\n"),
+("// \\param [in] aaa\n"
+"// Bbb\n"),
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
@@ -853,12 +853,12 @@ TEST_F(CommentParserTest, ParamCommand5) {
   const char *Sources[] = {
 "// \\param [out] aaa Bbb\n",
 "// \\param[out] aaa Bbb\n",
-"// \\param\n"
-"// [out] aaa Bbb\n",
-"// \\param [out]\n"
-"// aaa Bbb\n",
-"// \\param [out] aaa\n"
-"// Bbb\n",
+("// \\param\n"
+"// [out] aaa Bbb\n"),
+("// \\param [out]\n"
+"// aaa Bbb\n"),
+("// \\param [out] aaa\n"
+"// Bbb\n"),
   };
 
   for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {



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


[clang] 898880f - [clang] Fix typo in comment

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Gousemoodhin Nadaf
Date: 2020-08-09T21:04:00+02:00
New Revision: 898880fe4e329ce7fc6bbe30f309ef3b91535c21

URL: 
https://github.com/llvm/llvm-project/commit/898880fe4e329ce7fc6bbe30f309ef3b91535c21
DIFF: 
https://github.com/llvm/llvm-project/commit/898880fe4e329ce7fc6bbe30f309ef3b91535c21.diff

LOG: [clang] Fix typo in comment

In the handleIntToFloatConversion() function, 6th parameter is ConvertFloat, 
7th parameter is ConvertInt.

Reviewed By: njames93, xbolva00

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

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 74427f8cd7ae..fe997e7719e7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1151,8 +1151,8 @@ static QualType handleFloatConversion(Sema &S, ExprResult 
&LHS,
   }
   assert(RHSFloat);
   return handleIntToFloatConversion(S, RHS, LHS, RHSType, LHSType,
-/*convertInt=*/ true,
-/*convertFloat=*/!IsCompAssign);
+/*ConvertFloat=*/ true,
+/*ConvertInt=*/!IsCompAssign);
 }
 
 /// Diagnose attempts to convert between __float128 and long double if



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


Re: [clang] 975467e - [Diagnostics] Handle string concat pattern and avoid false positives

2020-08-09 Thread Dávid Bolvanský via cfe-commits
We warn if it is just one occurance and next literal is not split too. I 
changed test to test other scenario. I could add that test back, but I think we 
have enough tests to cover code.

We should not warn for code pattern:
{
“a” “b”,
“c” “d”
}




> Dňa 9. 8. 2020 o 17:49 užívateľ Arthur O'Dwyer  
> napísal:
> 
> 
> Hi Dávid,
> Does this part of the patch imply that we don't want to warn on
> "foo" TWO
> ? and if so, why not?
> Anyway, I think at least
> "foo" TWO
> should be kept in the test suite, as a test-for-absence-of-warning.
> 
>   TWO "bar", 
> - "foo" TWO // expected-note{{place parentheses 
> around the string literal to silence warning}}
> + "foo" "bar" TWO // expected-note{{place 
> parentheses around the string literal to silence warning}}
> 
> my $.02,
> Arthur
> 
>> On Sun, Aug 9, 2020 at 10:03 AM Dávid Bolvanský via cfe-commits 
>>  wrote:
> 
>> 
>> Author: Dávid Bolvanský
>> Date: 2020-08-09T16:02:41+02:00
>> New Revision: 975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
>> 
>> URL: 
>> https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
>> DIFF: 
>> https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e.diff
>> 
>> LOG: [Diagnostics] Handle string concat pattern and avoid false positives
>> 
>> Added: 
>> 
>> 
>> Modified: 
>> clang/lib/Sema/SemaExpr.cpp
>> clang/test/Sema/string-concat.c
>> 
>> Removed: 
>> 
>> 
>> 
>> 
>> diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
>> index 35047a7b2b14..74427f8cd7ae 100644
>> --- a/clang/lib/Sema/SemaExpr.cpp
>> +++ b/clang/lib/Sema/SemaExpr.cpp
>> @@ -6908,10 +6908,13 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
>> MultiExprArg InitArgList,
>>  << InitArgList[I]->getSourceRange();
>>  } else if (const auto *SL = dyn_cast(InitArgList[I])) {
>>unsigned NumConcat = SL->getNumConcatenated();
>> +  const auto *SLNext =
>> +  dyn_cast(InitArgList[I + 1 < E ? I + 1 : 0]);
>>// Diagnose missing comma in string array initialization.
>> -  // Do not warn when all the elements in the initializer are 
>> concatenated together.
>> -  // Do not warn for macros too.
>> -  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {
>> +  // Do not warn when all the elements in the initializer are 
>> concatenated
>> +  // together. Do not warn for macros too.
>> +  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() && 
>> SLNext &&
>> +  NumConcat != SLNext->getNumConcatenated()) {
>>  SmallVector Hints;
>>  for (unsigned i = 0; i < NumConcat - 1; ++i)
>>Hints.push_back(FixItHint::CreateInsertion(
>> 
>> diff  --git a/clang/test/Sema/string-concat.c 
>> b/clang/test/Sema/string-concat.c
>> index c93bbd4eaa00..13e9656d2536 100644
>> --- a/clang/test/Sema/string-concat.c
>> +++ b/clang/test/Sema/string-concat.c
>> @@ -61,7 +61,7 @@ char missing_comma_inner[][5] = {
>>  #define TWO "foo"
>>  const char *macro_test[] = { ONE("foo") "bar", 
>>   TWO "bar", 
>> - "foo" TWO // expected-note{{place parentheses 
>> around the string literal to silence warning}}
>> + "foo" "bar" TWO // expected-note{{place 
>> parentheses around the string literal to silence warning}}
>> };  // expected-warning@-1{{suspicious 
>> concatenation of string literals in an array initialization; did you mean to 
>> separate the elements with a comma?}}
>> 
>>  // Do not warn for macros.
>> @@ -104,6 +104,12 @@ const char *not_warn[] = {
>>  "world", "test"
>>  };
>> 
>> +const char *not_warn2[] = {
>> +"// Aaa\\\n"   " Bbb\\ \n"   " Ccc?" "?/\n",
>> +"// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
>> +"// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"
>> +  };
>> +
>>  // Do not warn when all the elements in the initializer are concatenated 
>> together.
>>  const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
>> 
>> 
>> 
>> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 975467e - [Diagnostics] Handle string concat pattern and avoid false positives

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T16:02:41+02:00
New Revision: 975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e

URL: 
https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e
DIFF: 
https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e.diff

LOG: [Diagnostics] Handle string concat pattern and avoid false positives

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 35047a7b2b14..74427f8cd7ae 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6908,10 +6908,13 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
 << InitArgList[I]->getSourceRange();
 } else if (const auto *SL = dyn_cast(InitArgList[I])) {
   unsigned NumConcat = SL->getNumConcatenated();
+  const auto *SLNext =
+  dyn_cast(InitArgList[I + 1 < E ? I + 1 : 0]);
   // Diagnose missing comma in string array initialization.
-  // Do not warn when all the elements in the initializer are concatenated 
together.
-  // Do not warn for macros too.
-  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {
+  // Do not warn when all the elements in the initializer are concatenated
+  // together. Do not warn for macros too.
+  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() && SLNext &&
+  NumConcat != SLNext->getNumConcatenated()) {
 SmallVector Hints;
 for (unsigned i = 0; i < NumConcat - 1; ++i)
   Hints.push_back(FixItHint::CreateInsertion(

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index c93bbd4eaa00..13e9656d2536 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -61,7 +61,7 @@ char missing_comma_inner[][5] = {
 #define TWO "foo"
 const char *macro_test[] = { ONE("foo") "bar", 
  TWO "bar", 
- "foo" TWO // expected-note{{place parentheses 
around the string literal to silence warning}}
+ "foo" "bar" TWO // expected-note{{place 
parentheses around the string literal to silence warning}}
};  // expected-warning@-1{{suspicious 
concatenation of string literals in an array initialization; did you mean to 
separate the elements with a comma?}}
 
 // Do not warn for macros.
@@ -104,6 +104,12 @@ const char *not_warn[] = {
 "world", "test"
 };
 
+const char *not_warn2[] = {
+"// Aaa\\\n"   " Bbb\\ \n"   " Ccc?" "?/\n",
+"// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
+"// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"
+  };
+
 // Do not warn when all the elements in the initializer are concatenated 
together.
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
 



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


[clang] 04a23f1 - [Diagnostics] Turn string concat warning to avoid false positives

2020-08-09 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-09T12:22:29+02:00
New Revision: 04a23f1fe08a6ad0baf1305d7308231d2cb4843b

URL: 
https://github.com/llvm/llvm-project/commit/04a23f1fe08a6ad0baf1305d7308231d2cb4843b
DIFF: 
https://github.com/llvm/llvm-project/commit/04a23f1fe08a6ad0baf1305d7308231d2cb4843b.diff

LOG: [Diagnostics] Turn string concat warning to avoid false positives

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 7560dc996b15..35047a7b2b14 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6911,7 +6911,7 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
   // Diagnose missing comma in string array initialization.
   // Do not warn when all the elements in the initializer are concatenated 
together.
   // Do not warn for macros too.
-  if (NumConcat > 1 && E > 1 && !SL->getBeginLoc().isMacroID()) {
+  if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {
 SmallVector Hints;
 for (unsigned i = 0; i < NumConcat - 1; ++i)
   Hints.push_back(FixItHint::CreateInsertion(

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index 8f087e37d953..c93bbd4eaa00 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -19,14 +19,16 @@ typedef __WCHAR_TYPE__ wchar_t;
 const wchar_t *missing_comma_wchar[] = {
 L"basic_filebuf",
 L"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
-L"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+L"promise",  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+L"shared_future"
 };
 
 #if __cplusplus >= 201103L
 const char *missing_comma_u8[] = {
 u8"basic_filebuf",
 u8"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
-u8"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+u8"promise",  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+u8"shared_future"
 };
 #endif
 
@@ -47,10 +49,11 @@ const char *missing_comma_
diff erent_lines[] = {"basic_filebuf", "basic_ios" // e
 const char *missing_comma_same_line_all_literals[] = {"basic_filebuf", 
"future" "optional", "packaged_task"}; // expected-note{{place parentheses 
around the string literal to silence warning}}

// expected-warning@-1{{suspicious concatenation of string literals in an array 
initialization; did you mean to separate the elements with a comma?}}
 
-char missing_comma_inner[][4] = {
+char missing_comma_inner[][5] = {
 "a",
-"b" // expected-note{{place parentheses around the string literal to 
silence warning}}
-"c" // expected-warning{{suspicious concatenation of string literals in an 
array initialization; did you mean to separate the elements with a comma?}}
+"b",
+"c" // expected-note{{place parentheses around the string literal to 
silence warning}}
+"d" // expected-warning{{suspicious concatenation of string literals in an 
array initialization; did you mean to separate the elements with a comma?}}
 };
 
 
@@ -89,6 +92,18 @@ const char *macro_test4[] = {"basic_filebuf",
 #define SUPPRESS(x) x
 const char *macro_test5[] = { SUPPRESS("foo" "bar"), "baz" };
 
+typedef struct {
+int i;
+const char s[11];
+} S;
+
+S s = {1, "hello" "world"};
+
+const char *not_warn[] = {
+"hello"
+"world", "test"
+};
+
 // Do not warn when all the elements in the initializer are concatenated 
together.
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
 



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


[clang] 6cd2355 - [Clang] Fixed buildboit failure; bot defaults to older C++ standard

2020-08-08 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-08T19:37:50+02:00
New Revision: 6cd23558d3a9fbe8bc73e96d4df4e52c8261d1b5

URL: 
https://github.com/llvm/llvm-project/commit/6cd23558d3a9fbe8bc73e96d4df4e52c8261d1b5
DIFF: 
https://github.com/llvm/llvm-project/commit/6cd23558d3a9fbe8bc73e96d4df4e52c8261d1b5.diff

LOG: [Clang] Fixed buildboit failure; bot defaults to older C++ standard

Added: 


Modified: 
clang/test/Sema/string-concat.c

Removed: 




diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index bf8369b079c8..8f087e37d953 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -22,11 +22,13 @@ const wchar_t *missing_comma_wchar[] = {
 L"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
 };
 
+#if __cplusplus >= 201103L
 const char *missing_comma_u8[] = {
 u8"basic_filebuf",
 u8"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
 u8"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
 };
+#endif
 
 const char *missing_two_commas[] = {"basic_filebuf",
"basic_ios" // expected-note{{place parentheses around 
the string literal to silence warning}}



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


[clang] 0fef780 - [Clang] Avoid whitespace in fixit note

2020-08-08 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-08T19:34:07+02:00
New Revision: 0fef780aa70b48551ae6df373955b5e4f5130fa4

URL: 
https://github.com/llvm/llvm-project/commit/0fef780aa70b48551ae6df373955b5e4f5130fa4
DIFF: 
https://github.com/llvm/llvm-project/commit/0fef780aa70b48551ae6df373955b5e4f5130fa4.diff

LOG: [Clang] Avoid whitespace in fixit note

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e86c5b919698..7560dc996b15 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6915,7 +6915,7 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
 SmallVector Hints;
 for (unsigned i = 0; i < NumConcat - 1; ++i)
   Hints.push_back(FixItHint::CreateInsertion(
-  PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ", "));
+  PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ","));
 
 Diag(SL->getStrTokenLoc(1), diag::warn_concatenated_literal_array_init)
 << Hints;



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


[clang] dc096a6 - [Diagnostics] Diagnose missing comma in string array initialization

2020-08-08 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-08T19:24:30+02:00
New Revision: dc096a66cb519532121fb0fbedb13265bd4b29ec

URL: 
https://github.com/llvm/llvm-project/commit/dc096a66cb519532121fb0fbedb13265bd4b29ec
DIFF: 
https://github.com/llvm/llvm-project/commit/dc096a66cb519532121fb0fbedb13265bd4b29ec.diff

LOG: [Diagnostics] Diagnose missing comma in string array initialization

Motivation (from PR37674):

const char *ss[] = {
  "foo", "bar",
  "baz", "qux"  // <-- Missing comma!
  "abc", "xyz"
  };

This kind of bug was recently also found in LLVM codebase (see PR47030).

Solves PR47038, PR37674

Reviewed By: aaron.ballman

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

Added: 
clang/test/Sema/string-concat.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 659f1d6df39e..7fe9396dbfc3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3002,6 +3002,10 @@ def err_missing_atsign_prefix : Error<
 def warn_objc_string_literal_comparison : Warning<
   "direct comparison of a string literal has undefined behavior">,
   InGroup;
+def warn_concatenated_literal_array_init : Warning<
+  "suspicious concatenation of string literals in an array initialization; "
+  "did you mean to separate the elements with a comma?">,
+  InGroup>;
 def warn_concatenated_nsarray_literal : Warning<
   "concatenated NSString literal for an NSArray expression - "
   "possibly missing a comma">,
@@ -6142,6 +6146,9 @@ def warn_overloaded_shift_in_comparison :Warning<
 def note_evaluate_comparison_first :Note<
   "place parentheses around comparison expression to evaluate it first">;
 
+def note_concatenated_string_literal_silence :Note<
+  "place parentheses around the string literal to silence warning">;
+
 def warn_addition_in_bitshift : Warning<
   "operator '%0' has lower precedence than '%1'; "
   "'%1' will be evaluated first">, InGroup;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 28da268e637f..e86c5b919698 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6906,6 +6906,21 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, 
MultiExprArg InitArgList,
 << DIE->getSourceRange();
   Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed)
 << InitArgList[I]->getSourceRange();
+} else if (const auto *SL = dyn_cast(InitArgList[I])) {
+  unsigned NumConcat = SL->getNumConcatenated();
+  // Diagnose missing comma in string array initialization.
+  // Do not warn when all the elements in the initializer are concatenated 
together.
+  // Do not warn for macros too.
+  if (NumConcat > 1 && E > 1 && !SL->getBeginLoc().isMacroID()) {
+SmallVector Hints;
+for (unsigned i = 0; i < NumConcat - 1; ++i)
+  Hints.push_back(FixItHint::CreateInsertion(
+  PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ", "));
+
+Diag(SL->getStrTokenLoc(1), diag::warn_concatenated_literal_array_init)
+<< Hints;
+Diag(SL->getBeginLoc(), 
diag::note_concatenated_string_literal_silence);
+  }
 }
   }
 

diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
new file mode 100644
index ..bf8369b079c8
--- /dev/null
+++ b/clang/test/Sema/string-concat.c
@@ -0,0 +1,102 @@
+
+// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
+
+const char *missing_comma[] = {
+"basic_filebuf",
+"basic_ios",
+"future",
+"optional",
+"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
+"promise",  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}} 
+"shared_future"
+};
+
+#ifndef __cplusplus
+typedef __WCHAR_TYPE__ wchar_t;
+#endif
+
+const wchar_t *missing_comma_wchar[] = {
+L"basic_filebuf",
+L"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
+L"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+};
+
+const char *missing_comma_u8[] = {
+u8"basic_filebuf",
+u8"packaged_task" // expected-note{{place parentheses around the string 
literal to silence warning}}
+u8"promise"  // expected-warning{{suspicious concatenation of string 
literals in an array initialization; did you mean to separate the elements with 
a comma?}}
+};
+
+const char *missing_two_commas[] = {"basic_filebuf",
+   "basic_ios" // expecte

[clang] 47650dc - Revert "[clang-misexpect] Fixed typo which causes that --pgo-warn-misexpect option is not passed in the compiler invocation"

2020-05-19 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-05-19T23:20:54+02:00
New Revision: 47650dcbeee215f48277ed8bea5f0e43cbf125fc

URL: 
https://github.com/llvm/llvm-project/commit/47650dcbeee215f48277ed8bea5f0e43cbf125fc
DIFF: 
https://github.com/llvm/llvm-project/commit/47650dcbeee215f48277ed8bea5f0e43cbf125fc.diff

LOG: Revert "[clang-misexpect] Fixed typo which causes that 
--pgo-warn-misexpect option is not passed in the compiler invocation"

This reverts commit 6d2b75e0887ee87e247756c4d51733616bb2f356.

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 5496df79dbfb..94ba0dd8e598 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3680,7 +3680,7 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
 }
   }
 
-  if (!Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
+  if (Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
 Res.FrontendOpts.LLVMArgs.push_back("-pgo-warn-misexpect");
 
   LangOpts.FunctionAlignment =



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


[clang] 6d2b75e - [clang-misexpect] Fixed typo which causes that --pgo-warn-misexpect option is not passed in the compiler invocation

2020-05-19 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-05-19T23:12:08+02:00
New Revision: 6d2b75e0887ee87e247756c4d51733616bb2f356

URL: 
https://github.com/llvm/llvm-project/commit/6d2b75e0887ee87e247756c4d51733616bb2f356
DIFF: 
https://github.com/llvm/llvm-project/commit/6d2b75e0887ee87e247756c4d51733616bb2f356.diff

LOG: [clang-misexpect] Fixed typo which causes that --pgo-warn-misexpect option 
is not passed in the compiler invocation

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 94ba0dd8e598..5496df79dbfb 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3680,7 +3680,7 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
 }
   }
 
-  if (Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
+  if (!Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
 Res.FrontendOpts.LLVMArgs.push_back("-pgo-warn-misexpect");
 
   LangOpts.FunctionAlignment =



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


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-08 Thread Dávid Bolvanský via cfe-commits

Yeah, I tried to fix even that case but is not so simple so not worth any extra 
time/complexivity.

> Dňa 8. 10. 2019 o 19:09 užívateľ Arthur O'Dwyer  
> napísal:
> 
> 
> On Mon, Oct 7, 2019 at 6:58 PM Dávid Bolvanský  
> wrote:
> >> FWIW I found the "always evaluates to 'true'" bit important to
> >> understand the warning.
> >
> > Yeah. I moved this check somewhere else, so we can print precise message:
> > r373973 should emit "bitwise negation of a boolean expression always
> > evaluates to 'true'; did you mean logical negation?" where possible.
> > In the suspicious case like int i = ~b there is a general message
> > "bitwise negation of a boolean expression; did you mean logical
> > negation?".
> >
> > I like it now. What do you think? fine for you?
> 
> I see. Yes, all the cases I tried produce appropriate diagnostics. I like it!
> 
>> Hm, there is no "bitwise negation of a boolean expression always
>> evaluates to 'true'; did you mean logical negation?" for chromium
>> case [ https://bugs.chromium.org/p/chromium/issues/detail?id=1011810 ]. I 
>> will try to fix it.
> 
> The important part there seems to be that the result of `~b` (which must be 
> either -1 or -2) is used as the operand to `!=` or `==`.
> My opinion is that it is not worth the extra complication just to improve the 
> error message for this case.
> It would be interesting to do some kind of general-purpose dataflow before 
> emitting diagnostics...
> I notice that Clang's optimizer is smart enough to optimize
> bool foo(bool a, bool b) {
> return a == ~b;
> }
> bool bar(int x) {
> return x + 1 < -INT_MAX;
> }
> into `return 0`. If it could propagate that information up and produce a 
> diagnostic, users might appreciate that. But the challenge as always is that 
> we can never tell if the user might sometimes be doing that sort of thing on 
> purpose (in inlined code, in macros, in generated code, etc).
> 
> my $.02,
> –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
Hm, there is no "bitwise negation of a boolean expression always
evaluates to 'true'; did you mean logical negation?" for chromium
case. I will try to fix it.

ut 8. 10. 2019 o 0:03 Dávid Bolvanský  napísal(a):
>
> "FWIW I found the "always evaluates to 'true'" bit important to
> understand the warning."
>
> Yeah. I moved this check somewhere else, so we can print precise message:
> r373973 should emit "bitwise negation of a boolean expression always
> evaluates to 'true'; did you mean logical negation?" where possible.
> In the suspicious case like int i = ~b there is a general message
> "bitwise negation of a boolean expression; did you mean logical
> negation?".
>
> I like it now. What do you think? fine for you?
>
> po 7. 10. 2019 o 17:29 Dávid Bolvanský  napísal(a):
> >
> > Typo was fixed some days ago :)
> >
> > Odoslané z iPhonu
> >
> > Dňa 7. 10. 2019 o 17:22 užívateľ Arthur O'Dwyer  
> > napísal:
> >
> > 
> > On Mon, Oct 7, 2019 at 10:59 AM Dávid Bolvanský via cfe-commits 
> >  wrote:
> >>
> >> Okey, I will see what I can do (I know I need to move checking code 
> >> somewhere else).
> >>
> >> > Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  
> >> > napísal:
> >> > FWIW I found the "always evaluates to 'true'" bit important to 
> >> > understand the warning.
> >
> >
> > +1, I think "always evaluates to true" is useful, especially for people who 
> > don't immediately intuit the difference between "bitwise negation" and 
> > "logical negation." (Although the fixit will help clear up the difference.)
> >
> > Also, Dávid, you misspelled "logical" as "logicial" in the patch I saw. So 
> > you might need to push a fix for that typo, unless you already caught it.
> > My suggested message follows—
> >
> > -  "bitwise negation of a boolean expression; did you mean a logicial 
> > negation?">,
> > +  "bitwise negation of a boolean expression is always true; did you mean 
> > logical negation?">,
> >
> > my $.02,
> > –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
"FWIW I found the "always evaluates to 'true'" bit important to
understand the warning."

Yeah. I moved this check somewhere else, so we can print precise message:
r373973 should emit "bitwise negation of a boolean expression always
evaluates to 'true'; did you mean logical negation?" where possible.
In the suspicious case like int i = ~b there is a general message
"bitwise negation of a boolean expression; did you mean logical
negation?".

I like it now. What do you think? fine for you?

po 7. 10. 2019 o 17:29 Dávid Bolvanský  napísal(a):
>
> Typo was fixed some days ago :)
>
> Odoslané z iPhonu
>
> Dňa 7. 10. 2019 o 17:22 užívateľ Arthur O'Dwyer  
> napísal:
>
> 
> On Mon, Oct 7, 2019 at 10:59 AM Dávid Bolvanský via cfe-commits 
>  wrote:
>>
>> Okey, I will see what I can do (I know I need to move checking code 
>> somewhere else).
>>
>> > Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  napísal:
>> > FWIW I found the "always evaluates to 'true'" bit important to understand 
>> > the warning.
>
>
> +1, I think "always evaluates to true" is useful, especially for people who 
> don't immediately intuit the difference between "bitwise negation" and 
> "logical negation." (Although the fixit will help clear up the difference.)
>
> Also, Dávid, you misspelled "logical" as "logicial" in the patch I saw. So 
> you might need to push a fix for that typo, unless you already caught it.
> My suggested message follows—
>
> -  "bitwise negation of a boolean expression; did you mean a logicial 
> negation?">,
> +  "bitwise negation of a boolean expression is always true; did you mean 
> logical negation?">,
>
> my $.02,
> –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
Typo was fixed some days ago :)

Odoslané z iPhonu

> Dňa 7. 10. 2019 o 17:22 užívateľ Arthur O'Dwyer  
> napísal:
> 
> 
>> On Mon, Oct 7, 2019 at 10:59 AM Dávid Bolvanský via cfe-commits 
>>  wrote:
> 
>> Okey, I will see what I can do (I know I need to move checking code 
>> somewhere else).
>> 
>> > Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  napísal:
>> > FWIW I found the "always evaluates to 'true'" bit important to understand 
>> > the warning.
> 
> +1, I think "always evaluates to true" is useful, especially for people who 
> don't immediately intuit the difference between "bitwise negation" and 
> "logical negation." (Although the fixit will help clear up the difference.)
> 
> Also, Dávid, you misspelled "logical" as "logicial" in the patch I saw. So 
> you might need to push a fix for that typo, unless you already caught it.
> My suggested message follows—
> 
> -  "bitwise negation of a boolean expression; did you mean a logicial 
> negation?">,
> +  "bitwise negation of a boolean expression is always true; did you mean 
> logical negation?">,
> 
> my $.02,
> –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r371605 - [Diagnostics] Add -Wsizeof-array-div

2019-10-07 Thread Dávid Bolvanský via cfe-commits
D68526 should fix it. Take a look please.


> Dňa 7. 10. 2019 o 17:09 užívateľ Nico Weber  napísal:
> 
> 
> I gave this another try now that we have a compiler with rL372600. Another 
> thing the warning currently warns on is code like this:
> 
>   char memory[kOpcodeMemory];
>   OpcodeFactory opcode_maker(memory, sizeof(memory));
>   size_t count = sizeof(memory) / sizeof(PolicyOpcode);
> 
> or
> 
>   int32_t fds[sizeof(buffer->data) / sizeof(int32_t)], i, count;
>   size_t size;
> 
> (the latter from wayland).
> 
> What do you think about also not emitting the warning if the lhs sizeof is an 
> array of signed or unsigned char? The warning wants the rhs sizeof to be 
> sizeof(char) which is 1, and dividing by that doesn't really make sense. So 
> this might be a change that improves false negative rate while probably not 
> hurting true positive rate.
> 
>> On Mon, Sep 23, 2019 at 9:11 AM Dávid Bolvanský  
>> wrote:
>> Yeah, this needs to be handled a bit differently (if we want so).
>> 
>> po 23. 9. 2019 o 15:07 Nico Weber  napísal(a):
>>> It still warns if the inner array is in a struct. That's probably ok though.
>>> 
>>> struct Point {
>>>   int xy[2];
>>> };
>>> 
>>> void f() {
>>>   Point points[3];
>>>   for (int i = 0; i < sizeof(points) / sizeof(int); ++i)
>>> (&points[0].xy[0])[i] = 0;
>>> }
>>> 
 On Mon, Sep 23, 2019 at 8:54 AM Nico Weber  wrote:
 That was fast. Thanks much! :)
 
> On Mon, Sep 23, 2019 at 8:52 AM Dávid Bolvanský 
>  wrote:
> Hello,
> 
> Thanks for the proposed idea, implemented in rL372600.
> 
> po 23. 9. 2019 o 14:23 Nico Weber  napísal(a):
>> We're looking at turning this one.
>> 
>> One thing that this warns about that's a false positive where we've seen 
>> it is this code for nested arrays:
>> 
>>   float m[4][4];
>>   for (int i = 0; i < sizeof(m) / sizeof(**m); ++i) (&**m)[i] = 0;
>> 
>> (Why would anyone write code like this? It's a reduced example; consider 
>> e.g. wanting to call std::generate_n() on all elements of a nested 
>> array.)
>> 
>> Can we make the warning not fire when dividing the size of a nested 
>> array by the size of the deepest base type?
>> 
>>> On Wed, Sep 11, 2019 at 6:58 AM David Bolvansky via cfe-commits 
>>>  wrote:
>>> Author: xbolva00
>>> Date: Wed Sep 11 03:59:47 2019
>>> New Revision: 371605
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=371605&view=rev
>>> Log:
>>> [Diagnostics] Add -Wsizeof-array-div
>>> 
>>> Summary: Clang version of https://www.viva64.com/en/examples/v706/
>>> 
>>> Reviewers: rsmith
>>> 
>>> Differential Revision: https://reviews.llvm.org/D67287
>>> 
>>> Added:
>>> cfe/trunk/test/Sema/div-sizeof-array.cpp
>>> Modified:
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/lib/Sema/SemaExpr.cpp
>>> 
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371605&r1=371604&r2=371605&view=diff
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 11 
>>> 03:59:47 2019
>>> @@ -3406,6 +3406,10 @@ def note_pointer_declared_here : Note<
>>>  def warn_division_sizeof_ptr : Warning<
>>>"'%0' will return the size of the pointer, not the array itself">,
>>>InGroup>;
>>> +def warn_division_sizeof_array : Warning<
>>> +  "expression does not compute the number of elements in this array; 
>>> element "
>>> +  "type is %0, not %1">,
>>> +  InGroup>;
>>> 
>>>  def note_function_warning_silence : Note<
>>>  "prefix with the address-of operator to silence this warning">;
>>> 
>>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371605&r1=371604&r2=371605&view=diff
>>> ==
>>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 11 03:59:47 2019
>>> @@ -9158,17 +9158,28 @@ static void DiagnoseDivisionSizeofPointe
>>>else
>>>  RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
>>> 
>>> -  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
>>> -return;
>>> -  if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() 
>>> !=
>>> -  RHSTy.getCanonicalType().getUnqualifiedType())
>>> -return;
>>> +  if (LHSTy->isPointerType() && !RHSTy->isPointerType()) {
>>> +if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(), 
>>> RHSTy

Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
Okey, I will see what I can do (I know I need to move checking code somewhere 
else).

> Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  napísal:
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373614 - [Diagnostics] Bitwise negation of a boolean expr always evaluates to true; warn with -Wbool-operation

2019-10-03 Thread Dávid Bolvanský via cfe-commits
Fixed. I manually svncommited only specific files since I have other
changes and forgot to add that file too.
Sorry. Please evaluate this on Chromium. Since ~bool is always true, I
dont think we are gonna have any false positives..

št 3. 10. 2019 o 17:23 Nico Weber  napísal(a):
>
> ../../clang/lib/Sema/SemaExpr.cpp:13481:25: error: no member named 
> 'warn_bitwise_negation_bool' in namespace 'clang::diag'
>   Diag(OpLoc, diag::warn_bitwise_negation_bool)
>   ~~^
> 1 error generated.
>
> On Thu, Oct 3, 2019 at 11:16 AM David Bolvansky via cfe-commits 
>  wrote:
>>
>> Author: xbolva00
>> Date: Thu Oct  3 08:17:59 2019
>> New Revision: 373614
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=373614&view=rev
>> Log:
>> [Diagnostics] Bitwise negation of a boolean expr always evaluates to true; 
>> warn with -Wbool-operation
>>
>> Requested here:
>> http://lists.llvm.org/pipermail/cfe-dev/2019-October/063452.html
>>
>>
>> Added:
>> cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
>> Modified:
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373614&r1=373613&r2=373614&view=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct  3 08:17:59 2019
>> @@ -13470,7 +13470,6 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
>>  if (Input.isInvalid())
>>return ExprError();
>>  resultType = Input.get()->getType();
>> -
>>  if (resultType->isDependentType())
>>break;
>>  // C99 6.5.3.3p1. We allow complex int and float as a GCC extension.
>> @@ -13478,6 +13477,9 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
>>// C99 does not support '~' for complex conjugation.
>>Diag(OpLoc, diag::ext_integer_complement_complex)
>><< resultType << Input.get()->getSourceRange();
>> +else if (Input.get()->IgnoreParenImpCasts()->getType()->isBooleanType())
>> +  Diag(OpLoc, diag::warn_bitwise_negation_bool)
>> +  << FixItHint::CreateReplacement(OpLoc, "!");
>>  else if (resultType->hasIntegerRepresentation())
>>break;
>>  else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) 
>> {
>>
>> Added: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373614&view=auto
>> ==
>> --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (added)
>> +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Thu Oct  3 08:17:59 2019
>> @@ -0,0 +1,20 @@
>> +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wbool-operation %s
>> +// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
>> +// RUN: %clang_cc1 -x c -fsyntax-only -fdiagnostics-parseable-fixits %s 
>> 2>&1 | FileCheck %s
>> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wbool-operation %s
>> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
>> +// RUN: %clang_cc1 -x c++ -fsyntax-only -fdiagnostics-parseable-fixits %s 
>> 2>&1 | FileCheck %s
>> +
>> +#ifdef __cplusplus
>> +typedef bool boolean;
>> +#else
>> +typedef _Bool boolean;
>> +#endif
>> +
>> +void test(boolean b, int i) {
>> +  b = ~b; // expected-warning {{bitwise negation of a boolean expression 
>> always evaluates to 'true'}}
>> +  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
>> +  b = ~(b); // expected-warning {{bitwise negation of a boolean expression 
>> always evaluates to 'true'}}
>> +  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
>> +  b = ~i;
>> +}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373371 - [Diagnostics] Make -Wenum-compare-conditional off by default

2019-10-01 Thread Dávid Bolvanský via cfe-commits
I fixed it, forgot to run clang semacxx check too.

I am not sure.. I checked github and found case:
https://github.com/ros-industrial-consortium/godel/issues/115

Seems like this is very rare, not worth to make it on..

ut 1. 10. 2019 o 20:19 Nico Weber  napísal(a):
>
> This breaks emaCXX/warn-sign-conversion.cpp -- but see other thread, maybe 
> just revert this for now until we know what we want to do here :)
>
> On Tue, Oct 1, 2019 at 2:10 PM David Bolvansky via cfe-commits 
>  wrote:
>>
>> Author: xbolva00
>> Date: Tue Oct  1 11:12:13 2019
>> New Revision: 373371
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=373371&view=rev
>> Log:
>> [Diagnostics] Make -Wenum-compare-conditional off by default
>>
>> Too many false positives, eg. in Chromium.
>>
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=373371&r1=373370&r2=373371&view=diff
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Oct  1 11:12:13 
>> 2019
>> @@ -565,7 +565,7 @@ def SwitchEnum : DiagGroup<"switch-e
>>  def Switch : DiagGroup<"switch">;
>>  def EnumCompareConditional : DiagGroup<"enum-compare-conditional">;
>>  def EnumCompareSwitch : DiagGroup<"enum-compare-switch">;
>> -def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareConditional, 
>> EnumCompareSwitch]>;
>> +def EnumCompare   : DiagGroup<"enum-compare", [EnumCompareSwitch]>;
>>  def ImplicitFallthroughPerFunction :
>>DiagGroup<"implicit-fallthrough-per-function">;
>>  def ImplicitFallthrough  : DiagGroup<"implicit-fallthrough",
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373371&r1=373370&r2=373371&view=diff
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct  1 11:12:13 
>> 2019
>> @@ -6172,7 +6172,7 @@ def warn_comparison_of_mixed_enum_types
>>  def warn_conditional_mixed_enum_types : Warning<
>>"enumeration type mismatch in conditional expression"
>>"%diff{ ($ and $)|}0,1">,
>> -  InGroup;
>> +  InGroup, DefaultIgnore;
>>  def warn_comparison_of_mixed_enum_types_switch : Warning<
>>"comparison of two values with different enumeration types in switch 
>> statement"
>>"%diff{ ($ and $)|}0,1">,
>>
>> Modified: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373371&r1=373370&r2=373371&view=diff
>> ==
>> --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (original)
>> +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Tue Oct  1 
>> 11:12:13 2019
>> @@ -1,9 +1,5 @@
>>  // RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare-conditional %s
>> -// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
>> -// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
>>  // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare-conditional 
>> %s
>> -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
>> -// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
>>
>>  enum ro { A = 0x10 };
>>  enum rw { B = 0xFF };
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Dávid Bolvanský via cfe-commits
Done. rL373371.

ut 1. 10. 2019 o 19:58 Dávid Bolvanský  napísal(a):
>
> Sorry, answered on phone, missed it. I looked at your buildbots for
> chromium and yeah, so many warnings. I will make it off by default.
>
> ut 1. 10. 2019 o 19:58 Dávid Bolvanský  napísal(a):
> >
> > (Not sure if you intentionally didn't reply-all.)
> >
> > Sorry, answered on phone, missed it. I looked at your buildbots for
> > chromium and yeah, so many warnings. I will make it off by default.
> >
> > ut 1. 10. 2019 o 19:17 Nico Weber  napísal(a):
> >
> > >
> > > (Not sure if you intentionally didn't reply-all.)
> > >
> > > We should probably write it down, but clang's warning philosophy is that 
> > > warnings should be very high-signal. The usual way to prove this is to 
> > > build some large open-source codebase with the warning and counting true 
> > > and false positives.
> > >
> > > Just "gcc has it" isn't sufficient motivation – gcc has lots of not so 
> > > good warnings :)
> > >
> > > ps: To be clear, I appreciate all your work to add warnings a lot! It's 
> > > very useful. It's also possible that this warning is useful, but it's not 
> > > immediately clear, so there should be some data to back it up.
> > >
> > > On Tue, Oct 1, 2019 at 12:12 PM Dávid Bolvanský 
> > >  wrote:
> > >>
> > >> I hit this bug myself, GCC warned me with -Wenum-compare, Clang was 
> > >> silent. Clang “supports” this flag, but failed to catch it. Either Clang 
> > >> should not pretend that it supports this flag (and all related 
> > >> functionality) or should support it fully. Basically, new warnings will 
> > >> show up only for Clang-only environments.
> > >>
> > >> I think the own subgroup is a good compromise for now.  We can still 
> > >> make it off by default before next release if we decide so.
> > >>
> > >> Dňa 1. 10. 2019 o 17:56 užívateľ Nico Weber  
> > >> napísal:
> > >>
> > >> 
> > >> Thanks!
> > >>
> > >> Any thoughts on the true positive rate for this warning?
> > >>
> > >> On Tue, Oct 1, 2019 at 11:43 AM Dávid Bolvanský 
> > >>  wrote:
> > >>>
> > >>> Yeah, I moved this warning into own subgroup in rL373345. Thanks.
> > >>>
> > >>> ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
> > >>> >
> > >>> > Can we move this behind a Wenum-compare subgroup, say 
> > >>> > Wenum-compare-type? Our codebase is (well, was) Wenum-compare clean, 
> > >>> > and this new warnings fires pretty often and from a first quick 
> > >>> > glance the warning looks pretty low-signal anyways (*). Maybe the 
> > >>> > subgroup shouldn't even be on by default -- do you have any data on 
> > >>> > true / false positive rate of this?
> > >>> >
> > >>> > (But for starters, just having a way to turn this off is enough.)
> > >>> >
> > >>> > For example, we have a windows common control that's either a 
> > >>> > PGRP_DOWN or a PGRP_UP page control and depending on which you store 
> > >>> > the control state in the same int, then stuff like `return 
> > >>> > extra.inner_spin.spin_up ? UPS_DISABLED : DNS_DISABLED;`.
> > >>> >
> > >>> > On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits 
> > >>> >  wrote:
> > >>> >>
> > >>> >> Author: xbolva00
> > >>> >> Date: Mon Sep 30 12:55:50 2019
> > >>> >> New Revision: 373252
> > >>> >>
> > >>> >> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
> > >>> >> Log:
> > >>> >> [Diagnostics] Warn if enumeration type mismatch in conditional 
> > >>> >> expression
> > >>> >>
> > >>> >> Summary:
> > >>> >> - Useful warning
> > >>> >> - GCC compatibility (GCC warns in C++ mode)
> > >>> >>
> > >>> >> Reviewers: rsmith, aaron.ballman
> > >>> >>
> > >>> >> Reviewed By: aaron.ballman
> > >>> >>
> > >>> >> Subscribers: cfe-commits
> > >>> >>
> > >>> >> Tags: #clang
> > >>> >>
> > >>> >> Differential Revision: https://reviews.llvm.org/D67919
> > >>> >>
> > >>> >> Added:
> > >>> >> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> > >>> >> Modified:
> > >>> >> cfe/trunk/lib/Sema/SemaChecking.cpp
> > >>> >>
> > >>> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> > >>> >> URL: 
> > >>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
> > >>> >> ==
> > >>> >> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> > >>> >> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
> > >>> >> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
> > >>> >>return IL;
> > >>> >>  }
> > >>> >>
> > >>> >> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation 
> > >>> >> Loc,
> > >>> >> +  Expr *LHS, Expr *RHS) {
> > >>> >> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
> > >>> >> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
> > >>> >> +
> > >>> >> +  const auto *LHSEnumType = LHSStrippedType->getAs();
> > >>> >> +  if (!LHSEnumType)
> > >>> >>

Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Dávid Bolvanský via cfe-commits
Sorry, answered on phone, missed it. I looked at your buildbots for
chromium and yeah, so many warnings. I will make it off by default.

ut 1. 10. 2019 o 19:58 Dávid Bolvanský  napísal(a):
>
> (Not sure if you intentionally didn't reply-all.)
>
> Sorry, answered on phone, missed it. I looked at your buildbots for
> chromium and yeah, so many warnings. I will make it off by default.
>
> ut 1. 10. 2019 o 19:17 Nico Weber  napísal(a):
>
> >
> > (Not sure if you intentionally didn't reply-all.)
> >
> > We should probably write it down, but clang's warning philosophy is that 
> > warnings should be very high-signal. The usual way to prove this is to 
> > build some large open-source codebase with the warning and counting true 
> > and false positives.
> >
> > Just "gcc has it" isn't sufficient motivation – gcc has lots of not so good 
> > warnings :)
> >
> > ps: To be clear, I appreciate all your work to add warnings a lot! It's 
> > very useful. It's also possible that this warning is useful, but it's not 
> > immediately clear, so there should be some data to back it up.
> >
> > On Tue, Oct 1, 2019 at 12:12 PM Dávid Bolvanský  
> > wrote:
> >>
> >> I hit this bug myself, GCC warned me with -Wenum-compare, Clang was 
> >> silent. Clang “supports” this flag, but failed to catch it. Either Clang 
> >> should not pretend that it supports this flag (and all related 
> >> functionality) or should support it fully. Basically, new warnings will 
> >> show up only for Clang-only environments.
> >>
> >> I think the own subgroup is a good compromise for now.  We can still make 
> >> it off by default before next release if we decide so.
> >>
> >> Dňa 1. 10. 2019 o 17:56 užívateľ Nico Weber  napísal:
> >>
> >> 
> >> Thanks!
> >>
> >> Any thoughts on the true positive rate for this warning?
> >>
> >> On Tue, Oct 1, 2019 at 11:43 AM Dávid Bolvanský 
> >>  wrote:
> >>>
> >>> Yeah, I moved this warning into own subgroup in rL373345. Thanks.
> >>>
> >>> ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
> >>> >
> >>> > Can we move this behind a Wenum-compare subgroup, say 
> >>> > Wenum-compare-type? Our codebase is (well, was) Wenum-compare clean, 
> >>> > and this new warnings fires pretty often and from a first quick glance 
> >>> > the warning looks pretty low-signal anyways (*). Maybe the subgroup 
> >>> > shouldn't even be on by default -- do you have any data on true / false 
> >>> > positive rate of this?
> >>> >
> >>> > (But for starters, just having a way to turn this off is enough.)
> >>> >
> >>> > For example, we have a windows common control that's either a PGRP_DOWN 
> >>> > or a PGRP_UP page control and depending on which you store the control 
> >>> > state in the same int, then stuff like `return extra.inner_spin.spin_up 
> >>> > ? UPS_DISABLED : DNS_DISABLED;`.
> >>> >
> >>> > On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits 
> >>> >  wrote:
> >>> >>
> >>> >> Author: xbolva00
> >>> >> Date: Mon Sep 30 12:55:50 2019
> >>> >> New Revision: 373252
> >>> >>
> >>> >> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
> >>> >> Log:
> >>> >> [Diagnostics] Warn if enumeration type mismatch in conditional 
> >>> >> expression
> >>> >>
> >>> >> Summary:
> >>> >> - Useful warning
> >>> >> - GCC compatibility (GCC warns in C++ mode)
> >>> >>
> >>> >> Reviewers: rsmith, aaron.ballman
> >>> >>
> >>> >> Reviewed By: aaron.ballman
> >>> >>
> >>> >> Subscribers: cfe-commits
> >>> >>
> >>> >> Tags: #clang
> >>> >>
> >>> >> Differential Revision: https://reviews.llvm.org/D67919
> >>> >>
> >>> >> Added:
> >>> >> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
> >>> >> Modified:
> >>> >> cfe/trunk/lib/Sema/SemaChecking.cpp
> >>> >>
> >>> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> >>> >> URL: 
> >>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
> >>> >> ==
> >>> >> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> >>> >> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
> >>> >> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
> >>> >>return IL;
> >>> >>  }
> >>> >>
> >>> >> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc,
> >>> >> +  Expr *LHS, Expr *RHS) {
> >>> >> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
> >>> >> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
> >>> >> +
> >>> >> +  const auto *LHSEnumType = LHSStrippedType->getAs();
> >>> >> +  if (!LHSEnumType)
> >>> >> +return;
> >>> >> +  const auto *RHSEnumType = RHSStrippedType->getAs();
> >>> >> +  if (!RHSEnumType)
> >>> >> +return;
> >>> >> +
> >>> >> +  // Ignore anonymous enums.
> >>> >> +  if (!LHSEnumType->getDecl()->hasNameForLinkage())
> >>> >> +return;
> >>> >> +  if (!RHSEnumType->getDecl()->hasNameForLinkage

Re: r373252 - [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-10-01 Thread Dávid Bolvanský via cfe-commits
Yeah, I moved this warning into own subgroup in rL373345. Thanks.

ut 1. 10. 2019 o 16:24 Nico Weber  napísal(a):
>
> Can we move this behind a Wenum-compare subgroup, say Wenum-compare-type? Our 
> codebase is (well, was) Wenum-compare clean, and this new warnings fires 
> pretty often and from a first quick glance the warning looks pretty 
> low-signal anyways (*). Maybe the subgroup shouldn't even be on by default -- 
> do you have any data on true / false positive rate of this?
>
> (But for starters, just having a way to turn this off is enough.)
>
> For example, we have a windows common control that's either a PGRP_DOWN or a 
> PGRP_UP page control and depending on which you store the control state in 
> the same int, then stuff like `return extra.inner_spin.spin_up ? UPS_DISABLED 
> : DNS_DISABLED;`.
>
> On Mon, Sep 30, 2019 at 3:53 PM David Bolvansky via cfe-commits 
>  wrote:
>>
>> Author: xbolva00
>> Date: Mon Sep 30 12:55:50 2019
>> New Revision: 373252
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=373252&view=rev
>> Log:
>> [Diagnostics] Warn if enumeration type mismatch in conditional expression
>>
>> Summary:
>> - Useful warning
>> - GCC compatibility (GCC warns in C++ mode)
>>
>> Reviewers: rsmith, aaron.ballman
>>
>> Reviewed By: aaron.ballman
>>
>> Subscribers: cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D67919
>>
>> Added:
>> cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>> Modified:
>> cfe/trunk/lib/Sema/SemaChecking.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373252&r1=373251&r2=373252&view=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 30 12:55:50 2019
>> @@ -11308,6 +11308,32 @@ static const IntegerLiteral *getIntegerL
>>return IL;
>>  }
>>
>> +static void CheckConditionalWithEnumTypes(Sema &S, SourceLocation Loc,
>> +  Expr *LHS, Expr *RHS) {
>> +  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
>> +  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
>> +
>> +  const auto *LHSEnumType = LHSStrippedType->getAs();
>> +  if (!LHSEnumType)
>> +return;
>> +  const auto *RHSEnumType = RHSStrippedType->getAs();
>> +  if (!RHSEnumType)
>> +return;
>> +
>> +  // Ignore anonymous enums.
>> +  if (!LHSEnumType->getDecl()->hasNameForLinkage())
>> +return;
>> +  if (!RHSEnumType->getDecl()->hasNameForLinkage())
>> +return;
>> +
>> +  if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType))
>> +return;
>> +
>> +  S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
>> +  << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
>> +  << RHS->getSourceRange();
>> +}
>> +
>>  static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
>>E = E->IgnoreParenImpCasts();
>>SourceLocation ExprLoc = E->getExprLoc();
>> @@ -11799,6 +11825,8 @@ static void CheckConditionalOperator(Sem
>>bool Suspicious = false;
>>CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
>>CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
>> +  CheckConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
>> +E->getFalseExpr());
>>
>>if (T->isBooleanType())
>>  DiagnoseIntInBoolContext(S, E);
>>
>> Added: cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c?rev=373252&view=auto
>> ==
>> --- cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c (added)
>> +++ cfe/trunk/test/Sema/warn-conditional-emum-types-mismatch.c Mon Sep 30 
>> 12:55:50 2019
>> @@ -0,0 +1,39 @@
>> +// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
>> +// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
>> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
>> +// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
>> +
>> +enum ro { A = 0x10 };
>> +enum rw { B = 0xFF };
>> +enum { C = 0x1A};
>> +
>> +enum {
>> +  STATUS_SUCCESS,
>> +  STATUS_FAILURE,
>> +  MAX_BASE_STATUS_CODE
>> +};
>> +
>> +enum ExtendedStatusCodes {
>> +  STATUS_SOMETHING_INTERESTING = MAX_BASE_STATUS_CODE + 1000,
>> +};
>> +
>> +
>> +int get_flag(int cond) {
>> +  return cond ? A : B;
>> +  #ifdef __cplusplus
>> +  // expected-warning@-2 {{enumeration type mismatch in conditional 
>> expression ('ro' and 'rw')}}
>> +  #else
>> +  // expected-no-diagnostics
>> +  #endif
>> +}
>> +
>> +// In the following cases we purposefully differ from GCC and dont warn 
>> because
>> +// this code pattern is quite sensitive and we dont want to produce so many 
>> false posi

Re: r371605 - [Diagnostics] Add -Wsizeof-array-div

2019-09-23 Thread Dávid Bolvanský via cfe-commits
Yeah, this needs to be handled a bit differently (if we want so).

po 23. 9. 2019 o 15:07 Nico Weber  napísal(a):

> It still warns if the inner array is in a struct. That's probably ok
> though.
>
> struct Point {
>   int xy[2];
> };
>
> void f() {
>   Point points[3];
>   for (int i = 0; i < sizeof(points) / sizeof(int); ++i)
> (&points[0].xy[0])[i] = 0;
> }
>
> On Mon, Sep 23, 2019 at 8:54 AM Nico Weber  wrote:
>
>> That was fast. Thanks much! :)
>>
>> On Mon, Sep 23, 2019 at 8:52 AM Dávid Bolvanský <
>> david.bolvan...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Thanks for the proposed idea, implemented in rL372600.
>>>
>>> po 23. 9. 2019 o 14:23 Nico Weber  napísal(a):
>>>
 We're looking at turning this one.

 One thing that this warns about that's a false positive where we've
 seen it is this code for nested arrays:

   float m[4][4];
   for (int i = 0; i < sizeof(m) / sizeof(**m); ++i) (&**m)[i] = 0;

 (Why would anyone write code like this? It's a reduced example;
 consider e.g. wanting to call std::generate_n() on all elements of a nested
 array.)

 Can we make the warning not fire when dividing the size of a nested
 array by the size of the deepest base type?

 On Wed, Sep 11, 2019 at 6:58 AM David Bolvansky via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:

> Author: xbolva00
> Date: Wed Sep 11 03:59:47 2019
> New Revision: 371605
>
> URL: http://llvm.org/viewvc/llvm-project?rev=371605&view=rev
> Log:
> [Diagnostics] Add -Wsizeof-array-div
>
> Summary: Clang version of https://www.viva64.com/en/examples/v706/
>
> Reviewers: rsmith
>
> Differential Revision: https://reviews.llvm.org/D67287
>
> Added:
> cfe/trunk/test/Sema/div-sizeof-array.cpp
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaExpr.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371605&r1=371604&r2=371605&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 11
> 03:59:47 2019
> @@ -3406,6 +3406,10 @@ def note_pointer_declared_here : Note<
>  def warn_division_sizeof_ptr : Warning<
>"'%0' will return the size of the pointer, not the array itself">,
>InGroup>;
> +def warn_division_sizeof_array : Warning<
> +  "expression does not compute the number of elements in this array;
> element "
> +  "type is %0, not %1">,
> +  InGroup>;
>
>  def note_function_warning_silence : Note<
>  "prefix with the address-of operator to silence this warning">;
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371605&r1=371604&r2=371605&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 11 03:59:47 2019
> @@ -9158,17 +9158,28 @@ static void DiagnoseDivisionSizeofPointe
>else
>  RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
>
> -  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
> -return;
> -  if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType()
> !=
> -  RHSTy.getCanonicalType().getUnqualifiedType())
> -return;
> +  if (LHSTy->isPointerType() && !RHSTy->isPointerType()) {
> +if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(),
> RHSTy))
> +  return;
>
> -  S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS <<
> LHS->getSourceRange();
> -  if (const auto *DRE = dyn_cast(LHSArg)) {
> -if (const ValueDecl *LHSArgDecl = DRE->getDecl())
> -  S.Diag(LHSArgDecl->getLocation(),
> diag::note_pointer_declared_here)
> -  << LHSArgDecl;
> +S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS <<
> LHS->getSourceRange();
> +if (const auto *DRE = dyn_cast(LHSArg)) {
> +  if (const ValueDecl *LHSArgDecl = DRE->getDecl())
> +S.Diag(LHSArgDecl->getLocation(),
> diag::note_pointer_declared_here)
> +<< LHSArgDecl;
> +}
> +  } else if (const auto *ArrayTy = S.Context.getAsArrayType(LHSTy)) {
> +QualType ArrayElemTy = ArrayTy->getElementType();
> +if (ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
> +S.Context.getTypeSize(ArrayElemTy) ==
> S.Context.getTypeSize(RHSTy))
> +  return;
> +S.Diag(Loc, diag::warn_division_sizeof_array)
> + 

Re: r371605 - [Diagnostics] Add -Wsizeof-array-div

2019-09-23 Thread Dávid Bolvanský via cfe-commits
Hello,

Thanks for the proposed idea, implemented in rL372600.

po 23. 9. 2019 o 14:23 Nico Weber  napísal(a):

> We're looking at turning this one.
>
> One thing that this warns about that's a false positive where we've seen
> it is this code for nested arrays:
>
>   float m[4][4];
>   for (int i = 0; i < sizeof(m) / sizeof(**m); ++i) (&**m)[i] = 0;
>
> (Why would anyone write code like this? It's a reduced example; consider
> e.g. wanting to call std::generate_n() on all elements of a nested array.)
>
> Can we make the warning not fire when dividing the size of a nested array
> by the size of the deepest base type?
>
> On Wed, Sep 11, 2019 at 6:58 AM David Bolvansky via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: xbolva00
>> Date: Wed Sep 11 03:59:47 2019
>> New Revision: 371605
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=371605&view=rev
>> Log:
>> [Diagnostics] Add -Wsizeof-array-div
>>
>> Summary: Clang version of https://www.viva64.com/en/examples/v706/
>>
>> Reviewers: rsmith
>>
>> Differential Revision: https://reviews.llvm.org/D67287
>>
>> Added:
>> cfe/trunk/test/Sema/div-sizeof-array.cpp
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371605&r1=371604&r2=371605&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 11
>> 03:59:47 2019
>> @@ -3406,6 +3406,10 @@ def note_pointer_declared_here : Note<
>>  def warn_division_sizeof_ptr : Warning<
>>"'%0' will return the size of the pointer, not the array itself">,
>>InGroup>;
>> +def warn_division_sizeof_array : Warning<
>> +  "expression does not compute the number of elements in this array;
>> element "
>> +  "type is %0, not %1">,
>> +  InGroup>;
>>
>>  def note_function_warning_silence : Note<
>>  "prefix with the address-of operator to silence this warning">;
>>
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371605&r1=371604&r2=371605&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 11 03:59:47 2019
>> @@ -9158,17 +9158,28 @@ static void DiagnoseDivisionSizeofPointe
>>else
>>  RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
>>
>> -  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
>> -return;
>> -  if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() !=
>> -  RHSTy.getCanonicalType().getUnqualifiedType())
>> -return;
>> +  if (LHSTy->isPointerType() && !RHSTy->isPointerType()) {
>> +if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(),
>> RHSTy))
>> +  return;
>>
>> -  S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS <<
>> LHS->getSourceRange();
>> -  if (const auto *DRE = dyn_cast(LHSArg)) {
>> -if (const ValueDecl *LHSArgDecl = DRE->getDecl())
>> -  S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here)
>> -  << LHSArgDecl;
>> +S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS <<
>> LHS->getSourceRange();
>> +if (const auto *DRE = dyn_cast(LHSArg)) {
>> +  if (const ValueDecl *LHSArgDecl = DRE->getDecl())
>> +S.Diag(LHSArgDecl->getLocation(),
>> diag::note_pointer_declared_here)
>> +<< LHSArgDecl;
>> +}
>> +  } else if (const auto *ArrayTy = S.Context.getAsArrayType(LHSTy)) {
>> +QualType ArrayElemTy = ArrayTy->getElementType();
>> +if (ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
>> +S.Context.getTypeSize(ArrayElemTy) ==
>> S.Context.getTypeSize(RHSTy))
>> +  return;
>> +S.Diag(Loc, diag::warn_division_sizeof_array)
>> +<< LHSArg->getSourceRange() << ArrayElemTy << RHSTy;
>> +if (const auto *DRE = dyn_cast(LHSArg)) {
>> +  if (const ValueDecl *LHSArgDecl = DRE->getDecl())
>> +S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here)
>> +<< LHSArgDecl;
>> +}
>>}
>>  }
>>
>>
>> Added: cfe/trunk/test/Sema/div-sizeof-array.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371605&view=auto
>>
>> ==
>> --- cfe/trunk/test/Sema/div-sizeof-array.cpp (added)
>> +++ cfe/trunk/test/Sema/div-sizeof-array.cpp Wed Sep 11 03:59:47 2019
>> @@ -0,0 +1,28 @@
>> +// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only
>> +
>> +template 
>> +int f(Ty (&Array)[N]) {
>> +  return sizeof(Array) / sizeof(Ty); // Should not warn
>> +}
>> +
>> +typ

Re: r371605 - [Diagnostics] Add -Wsizeof-array-div

2019-09-11 Thread Dávid Bolvanský via cfe-commits
Thanks,

Reproduced with -triple armv7–. Added triple to run line, hopefully it will fix 
the bots. I will check this buildbot if all ok.

rL371646

Dňa 11. 9. 2019 o 20:35 užívateľ Yvan Roux  napísal:

> Hi David,
> 
> This commit broken ARMv7 bots, logs are available here:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-quick/builds/10203/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Adiv-sizeof-array.cpp
> 
> Thanks,
> Yvan
> 
> 
> 
> On Wed, 11 Sep 2019 at 12:58, David Bolvansky via cfe-commits
>  wrote:
>> 
>> Author: xbolva00
>> Date: Wed Sep 11 03:59:47 2019
>> New Revision: 371605
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=371605&view=rev
>> Log:
>> [Diagnostics] Add -Wsizeof-array-div
>> 
>> Summary: Clang version of https://www.viva64.com/en/examples/v706/
>> 
>> Reviewers: rsmith
>> 
>> Differential Revision: https://reviews.llvm.org/D67287
>> 
>> Added:
>>cfe/trunk/test/Sema/div-sizeof-array.cpp
>> Modified:
>>cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>cfe/trunk/lib/Sema/SemaExpr.cpp
>> 
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371605&r1=371604&r2=371605&view=diff
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 11 03:59:47 
>> 2019
>> @@ -3406,6 +3406,10 @@ def note_pointer_declared_here : Note<
>> def warn_division_sizeof_ptr : Warning<
>>   "'%0' will return the size of the pointer, not the array itself">,
>>   InGroup>;
>> +def warn_division_sizeof_array : Warning<
>> +  "expression does not compute the number of elements in this array; 
>> element "
>> +  "type is %0, not %1">,
>> +  InGroup>;
>> 
>> def note_function_warning_silence : Note<
>> "prefix with the address-of operator to silence this warning">;
>> 
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371605&r1=371604&r2=371605&view=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 11 03:59:47 2019
>> @@ -9158,17 +9158,28 @@ static void DiagnoseDivisionSizeofPointe
>>   else
>> RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
>> 
>> -  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
>> -return;
>> -  if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() !=
>> -  RHSTy.getCanonicalType().getUnqualifiedType())
>> -return;
>> +  if (LHSTy->isPointerType() && !RHSTy->isPointerType()) {
>> +if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(), RHSTy))
>> +  return;
>> 
>> -  S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << 
>> LHS->getSourceRange();
>> -  if (const auto *DRE = dyn_cast(LHSArg)) {
>> -if (const ValueDecl *LHSArgDecl = DRE->getDecl())
>> -  S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here)
>> -  << LHSArgDecl;
>> +S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << 
>> LHS->getSourceRange();
>> +if (const auto *DRE = dyn_cast(LHSArg)) {
>> +  if (const ValueDecl *LHSArgDecl = DRE->getDecl())
>> +S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here)
>> +<< LHSArgDecl;
>> +}
>> +  } else if (const auto *ArrayTy = S.Context.getAsArrayType(LHSTy)) {
>> +QualType ArrayElemTy = ArrayTy->getElementType();
>> +if (ArrayElemTy->isDependentType() || RHSTy->isDependentType() ||
>> +S.Context.getTypeSize(ArrayElemTy) == S.Context.getTypeSize(RHSTy))
>> +  return;
>> +S.Diag(Loc, diag::warn_division_sizeof_array)
>> +<< LHSArg->getSourceRange() << ArrayElemTy << RHSTy;
>> +if (const auto *DRE = dyn_cast(LHSArg)) {
>> +  if (const ValueDecl *LHSArgDecl = DRE->getDecl())
>> +S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here)
>> +<< LHSArgDecl;
>> +}
>>   }
>> }
>> 
>> 
>> Added: cfe/trunk/test/Sema/div-sizeof-array.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/div-sizeof-array.cpp?rev=371605&view=auto
>> ==
>> --- cfe/trunk/test/Sema/div-sizeof-array.cpp (added)
>> +++ cfe/trunk/test/Sema/div-sizeof-array.cpp Wed Sep 11 03:59:47 2019
>> @@ -0,0 +1,28 @@
>> +// RUN: %clang_cc1 %s -verify -Wsizeof-array-div -fsyntax-only
>> +
>> +template 
>> +int f(Ty (&Array)[N]) {
>> +  return sizeof(Array) / sizeof(Ty); // Should not warn
>> +}
>> +
>> +typedef int int32;
>> +
>> +void test(void) {
>> +  int arr[12];// expected-note 2 {{array 'arr' declared 
>> here}}
>> +  unsigned long long arr2[4];
>> +  int *p = &arr[0];
>> +  int a1 = sizeof(arr) 

Re: r369217 - [Diagnostics] Diagnose misused xor as pow

2019-08-19 Thread Dávid Bolvanský via cfe-commits
Yes,
#define ALPHA_OFFSET 0x3

should turn off the diagnostic. (We skip hex decimals).


Dňa 19. 8. 2019 o 20:06 užívateľ Arthur O'Dwyer  
napísal:

>> On Mon, Aug 19, 2019 at 1:53 PM Nico Weber via cfe-commits 
>>  wrote:
> 
>> Hi,
>> 
>> this results in a false positive on webrtc, on this code:
>> 
>> https://cs.chromium.org/chromium/src/third_party/libwebp/src/enc/picture_csp_enc.c?q=picture_csp_enc.c&sq=package:chromium&dr&l=1002
>> 
>> The code does this:
>> 
>> #ifdef WORDS_BIGENDIAN
>> #define ALPHA_OFFSET 0   // uint32_t 0xff00 is 0xff,00,00,00 in memory
>> #else
>> #define ALPHA_OFFSET 3   // uint32_t 0xff00 is 0x00,00,00,ff in memory
>> #endif
>> 
>> // ...
>> 
>> const uint8_t* const argb = (const uint8_t*)picture->argb;
>> const uint8_t* const a = argb + (0 ^ ALPHA_OFFSET);
>> const uint8_t* const r = argb + (1 ^ ALPHA_OFFSET);
>> const uint8_t* const g = argb + (2 ^ ALPHA_OFFSET);
>> const uint8_t* const b = argb + (3 ^ ALPHA_OFFSET);
>> 
>> The idea is to get bytes 0, 1, 2, 3 as a, r, g, b if ALPHA_OFFSET is 0, or 
>> bytes 3, 2, 1, 0 if ALPHA_OFFSET is 3.
>> 
>> Maybe this shouldn't fire if the rhs is a macro?
> 
> Does it show a fix-it that suggests replacing
> #define ALPHA_OFFSET 3
> with
> #define ALPHA_OFFSET 0x3
> ? That would be the quickest way to shut up the warning, if I understand 
> correctly. The use of hexadecimal or octal or binary indicates unambiguously 
> that you mean to do a bitwise operation (xor), not an arithmetic one (pow).
> 
> If the use of a macro here prevents the hex workaround from working, then I'd 
> call that a bug in the diagnostic.
> 
> It would be great if Clang could do what humans do instinctively, and see 
> that this "2 ^ FOO" is actually part of a larger pattern — "0 ^ FOO, 1 ^ FOO, 
> 2 ^ FOO, 3 ^ FOO" — and therefore it probably isn't wrong unless the three 
> surrounding lines are also wrong. However, I'm pretty sure that Clang isn't 
> set up to discover "patterns" like this in general.  It sees "2 ^ 
> LITERAL_EXPONENT" and gives a warning regardless of the surrounding lines.
> 
> –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r338385 - [RISCV] Add driver for riscv32-unknown-elf baremetal target

2018-08-03 Thread Dávid Bolvanský via cfe-commits
Such filename fix could be part of https://reviews.llvm.org/D50246

pi 3. 8. 2018 o 15:17 Nico Weber  napísal(a):

> I'm getting this warning from the mac linker after this commit:
>
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool:
> warning same member name (libclangDriver.RISCV.o) in output file used for
> input files: obj/clang/lib/Driver/ToolChains/Arch/libclangDriver.RISCV.o
> and: obj/clang/lib/Driver/ToolChains/libclangDriver.RISCV.o (due to use of
> basename, truncation, blank padding or duplicate input files)
>
> Could we rename the file to fix that warning?
>
> On Tue, Jul 31, 2018 at 10:40 AM David Bolvansky via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: xbolva00
>> Date: Tue Jul 31 07:21:46 2018
>> New Revision: 338385
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=338385&view=rev
>> Log:
>> [RISCV] Add driver for riscv32-unknown-elf baremetal target
>>
>> Summary:
>> This patch adds a driver for the baremetal RISC-V target (i.e.
>> riscv32-unknown-elf). For reference, D39963 added basic target info and
>> added support for riscv32-linux-unknown-elf.
>>
>> Patch by: asb (Alex Bradbury)
>>
>> Reviewers: efriedma, phosek, apazos, espindola, mgrang
>>
>> Reviewed By: mgrang
>>
>> Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe,
>> emaste, mgorny, arichardson, rbar, johnrusso, simoncook,
>> jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng,
>> edward-jones, mgrang, cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D46822
>>
>> Added:
>> cfe/trunk/lib/Driver/ToolChains/RISCV.cpp
>> cfe/trunk/lib/Driver/ToolChains/RISCV.h
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/bin/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/bin/riscv32-unknown-elf-ld
>>  (with props)
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/crtbegin.o
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/crtend.o
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/c++/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/c++/8.0.1/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/c++/8.0.1/.keep
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/lib/
>>
>> cfe/trunk/test/Driver/Inputs/basic_riscv32_tree/riscv32-unknown-elf/lib/crt0.o
>> Modified:
>> cfe/trunk/lib/Driver/CMakeLists.txt
>> cfe/trunk/lib/Driver/Driver.cpp
>> cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
>> cfe/trunk/test/Driver/riscv32-toolchain.c
>>
>> Modified: cfe/trunk/lib/Driver/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CMakeLists.txt?rev=338385&r1=338384&r2=338385&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Driver/CMakeLists.txt (original)
>> +++ cfe/trunk/lib/Driver/CMakeLists.txt Tue Jul 31 07:21:46 2018
>> @@ -57,6 +57,7 @@ add_clang_library(clangDriver
>>ToolChains/NetBSD.cpp
>>ToolChains/OpenBSD.cpp
>>ToolChains/PS4CPU.cpp
>> +  ToolChains/RISCV.cpp
>>ToolChains/Solaris.cpp
>>ToolChains/TCE.cpp
>>ToolChains/WebAssembly.cpp
>>
>> Modified: cfe/trunk/lib/Driver/Driver.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=338385&r1=338384&r2=338385&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Driver/Driver.cpp (original)
>> +++ cfe/trunk/lib/Driver/Driver.cpp Tue Jul 31 07:21:46 2018
>> @@ -37,6 +37,7 @@
>>  #include "ToolChains/NetBSD.h"
>>  #include "ToolChains/OpenBSD.h"
>>  #include "ToolChains/PS4CPU.h"
>> +#include "ToolChains/RISCV.h"
>>  #include "ToolChains/Solaris.h"
>>  #include "ToolChains/TCE.h"
>>  #include "ToolChains/WebAssembly.h"
>> @@ -4399,6 +4400,10 @@ const ToolChain &Driver::getToolChain(co
>>case llvm::Triple::avr:
>>  TC = llvm::make_unique(*this, Target,
>> Args);
>>  break;
>> +  case llvm::Triple::riscv32:
>> +  case llvm::Triple::riscv64:
>> +TC = llvm::make_unique(*this,
>> Target, Args);
>> +break;
>>default:
>>  if (Target.getVendor() == llvm::Triple::Myriad)
>>TC = llvm::make_unique(*this,
>> Target,
>>
>> Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
>> URL:
>> h