[PATCH] D155370: [CodeComplete] Don't emit parameters when not FunctionCanBeCall

2023-07-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I'm not sure switching to RK_Pattern is ideal, but I think there are a couple 
of (easy?) alternatives that achieve the same.

> Regard to the heuristic itself, it's currently a bit inconvenient that I have 
> to switch headers and sources back and forth and do copy-pastes when I'm 
> writing member function definitions outside of a class.

Yeah, it would be nice to have completions that provide the declaration syntax.
There's currently support for adding declarations of method overrides to 
derived classes: see `AddOverrideResults` in SemaCodeComplete, this should be 
kind-of similar.
These *do* use RK_Pattern, and I think it's appropriate there. (Though it does 
cause some ranking problems...)




Comment at: clang-tools-extra/clangd/CodeComplete.cpp:441
C.SemaResult->CursorKind, &Completion.RequiredQualifier);
-  if (!C.SemaResult->FunctionCanBeCall)
-S.SnippetSuffix.clear();

I guess an alternative to this patch would be to clear S.Signature here too?



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:1425
+Method, Builder);
+Result R(Builder.TakeString(), /*Priority=*/CCP_Declaration,
+ /*CursorKind=*/CXCursor_CXXMethod,

the problem (from clangd's perspective) with emitting this as a pattern is we 
don't know which decl this is, and so we lose:

 - ranking information (score popular decls higher)
 - semantic information (this is a function and should be marked in LSP as such)

Is it possible to change the behavior of Result::CreateCodeCompletionString() 
instead, based on Result::FunctionCanBeCall? Then we get to keep RK_Declaration 
and get the right string


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155370/new/

https://reviews.llvm.org/D155370

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


[PATCH] D155380: [clang] Fix delayed template parsing

2023-07-16 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 540764.
sepavloff added a comment.

Use calculated default FP options


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155380/new/

https://reviews.llvm.org/D155380

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/PCH/late-parsed-instantiations.cpp


Index: clang/test/PCH/late-parsed-instantiations.cpp
===
--- clang/test/PCH/late-parsed-instantiations.cpp
+++ clang/test/PCH/late-parsed-instantiations.cpp
@@ -4,7 +4,9 @@
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch 
-fpch-instantiate-templates %s -o %t.pch -verify
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -include-pch %t.pch 
%s -verify
 
-// XFAIL: target={{.*}}-aix{{.*}}
+// Run this test for i686 as this is the target that modifies default FP 
options.
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing 
-std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing 
-std=c++14 -include-pch %t.pch %s -verify
 
 #ifndef HEADER_INCLUDED
 
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -1744,6 +1744,7 @@
 
   // Parsing should occur with empty FP pragma stack and FP options used in the
   // point of the template definition.
+  Sema::FpPragmaStackSaveRAII SavedStack(Actions);
   Actions.resetFPOptions(LPT.FPO);
 
   assert(!LPT.Toks.empty() && "Empty body!");
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -710,6 +710,15 @@
 return result;
   }
 
+  class FpPragmaStackSaveRAII {
+  public:
+FpPragmaStackSaveRAII(Sema &S) : S(S), SavedStack(S.FpPragmaStack) {}
+~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); }
+  private:
+Sema &S;
+PragmaStack SavedStack;
+  };
+
   void resetFPOptions(FPOptions FPO) {
 CurFPFeatures = FPO;
 FpPragmaStack.Stack.clear();


Index: clang/test/PCH/late-parsed-instantiations.cpp
===
--- clang/test/PCH/late-parsed-instantiations.cpp
+++ clang/test/PCH/late-parsed-instantiations.cpp
@@ -4,7 +4,9 @@
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -include-pch %t.pch %s -verify
 
-// XFAIL: target={{.*}}-aix{{.*}}
+// Run this test for i686 as this is the target that modifies default FP options.
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing -std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing -std=c++14 -include-pch %t.pch %s -verify
 
 #ifndef HEADER_INCLUDED
 
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -1744,6 +1744,7 @@
 
   // Parsing should occur with empty FP pragma stack and FP options used in the
   // point of the template definition.
+  Sema::FpPragmaStackSaveRAII SavedStack(Actions);
   Actions.resetFPOptions(LPT.FPO);
 
   assert(!LPT.Toks.empty() && "Empty body!");
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -710,6 +710,15 @@
 return result;
   }
 
+  class FpPragmaStackSaveRAII {
+  public:
+FpPragmaStackSaveRAII(Sema &S) : S(S), SavedStack(S.FpPragmaStack) {}
+~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); }
+  private:
+Sema &S;
+PragmaStack SavedStack;
+  };
+
   void resetFPOptions(FPOptions FPO) {
 CurFPFeatures = FPO;
 FpPragmaStack.Stack.clear();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154903: clangd: Provide the resource dir via environment variable

2023-07-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I'm a little nervous about this. On the one hand it's simple and I want to get 
you unblocked but:

- the more ways to initialize resource dir and the more places this needs to be 
propagated to, the more likely this is to get out of sync
- we might want to remove the need for resource-dir one day and embed the 
built-in-headers in the binary, it's not clear what this would do in such a 
world.
- I don't understand how the technique this enables can be robust. Using the 
built-in headers from one compiler with a different compiler may work sometimes 
but is going to break in mysterious ways. I don't want to stop you using this 
technique, but if we add a feature for this people will want support in using 
it correctly.

It seems like you can *almost* do this with no new support though - the driver 
will always be invoked by clangd, so you can ask the OS where the invoking 
binary is. This assumes:

- you're on an OS where this is reasonably possible
- you're not customizing the resource-dir path, so we can use the same 
heuristics clangd does to find it

Proof of concept (works on my machine!) to access the resource dir from the 
driver - this just sets it as an include path but you could do whatever:

  #!/bin/bash
  # /home/sammccall/qd/driver.sh
  echo "Target: x86_64-linux-gnu" >&2
  echo "#include \"...\" search starts here:" >&2
  echo "#include <...> search starts here:" >&2
  echo $(dirname $(dirname $(readlink /proc/$PPID/exe)))/lib/clang/*/include >&2
  echo "End of search list." >&2

  # /home/sammccall/qd/.clangd
  CompileFlags:
Compiler: /home/sammccall/qd/driver.sh

  $ env CLANGD_FLAGS=--query-driver="/home/sammccall/qd/driver.sh" clangd 
--check=/home/sammccall/qd/hello.cc -log=verbose
  ...
  I[10:09:51.174] Failed to find compilation database for 
/home/sammccall/qd/hello.cc
  V[10:09:51.177] System include extraction: target extracted: 
"x86_64-linux-gnu"
  V[10:09:51.177] System include extraction: adding 
/usr/lib/clangd/lib/clang/16/include
  I[10:09:51.177] System includes extractor: successfully executed 
/home/sammccall/qd/driver.sh
got includes: "/usr/lib/clangd/lib/clang/16/include"
got target: "x86_64-linux-gnu"
  I[10:09:51.177] Generic fallback command is: [/home/sammccall/qd] 
/home/sammccall/qd/driver.sh -isystem /usr/lib/clangd/lib/clang/16/include 
--target=x86_64-linux-gnu -resource-dir=/usr/lib/clangd/lib/clang/16 -- 
/home/sammccall/qd/hello.cc
  ...

If this doesn't seem workable, can you explain a bit more about your setup?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154903/new/

https://reviews.llvm.org/D154903

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


[PATCH] D155394: [clang][Interp] Implement __builtin_fpclassify

2023-07-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155394

Files:
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp


Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -116,3 +116,16 @@
   char isfpclass_snan_2   [__builtin_isfpclass(__builtin_nansl(""), 0x0207) ? 
1 : -1]; // ~fcFinite
   char isfpclass_snan_3   [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 
1 : -1]; // fcFinite
 }
+
+namespace fpclassify {
+  char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nan(""))];
+  char classify_snan[__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nans(""))];
+  char classify_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, 
__builtin_inf())];
+  char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, 
-__builtin_inf())];
+  char classify_normal  [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];
+  char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)];
+  char classify_denorm  [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)];
+  char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)];
+  char classify_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];
+  char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -234,6 +234,37 @@
   return true;
 }
 
+/// Five int32 values followed by one floating value.
+static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func) {
+  const Floating &Val = S.Stk.peek();
+
+  unsigned Index;
+  switch (Val.getCategory()) {
+  case APFloat::fcNaN:
+Index = 0;
+break;
+  case APFloat::fcInfinity:
+Index = 1;
+break;
+  case APFloat::fcNormal:
+Index = Val.isDenormal() ? 3 : 2;
+break;
+  case APFloat::fcZero:
+Index = 4;
+break;
+  }
+
+  // The last argument is first on the stack.
+  unsigned Offset = align(primSize(PT_Float)) +
+((1 + (4 - Index)) * align(primSize(PT_Sint32)));
+
+  const Integral<32, true> &I = S.Stk.peek>(Offset);
+  S.Stk.push>(I);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -316,6 +347,10 @@
 if (interp__builtin_isfpclass(S, OpPC, Frame, F))
   return Ret(S, OpPC, Dummy);
 break;
+  case Builtin::BI__builtin_fpclassify:
+if (interp__builtin_fpclassify(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
 
   default:
 return false;
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -97,7 +97,9 @@
   bool isInf() const { return F.isInfinity(); }
   bool isFinite() const { return F.isFinite(); }
   bool isNormal() const { return F.isNormal(); }
+  bool isDenormal() const { return F.isDenormal(); }
   llvm::FPClassTest classify() const { return F.classify(); }
+  APFloat::fltCategory getCategory() const { return F.getCategory(); }
 
   ComparisonCategoryResult compare(const Floating &RHS) const {
 return Compare(F, RHS.F);


Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -116,3 +116,16 @@
   char isfpclass_snan_2   [__builtin_isfpclass(__builtin_nansl(""), 0x0207) ? 1 : -1]; // ~fcFinite
   char isfpclass_snan_3   [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 1 : -1]; // fcFinite
 }
+
+namespace fpclassify {
+  char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))];
+  char classify_snan[__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nans(""))];
+  char classify_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())];
+  char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())];
+  char classify_normal  [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];
+  char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)];
+  char classify_denorm  [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)];
+  char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1,

[PATCH] D155396: [Sema][ObjC] Propagating value-dependent errors into BlockExpr

2023-07-16 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added a reviewer: aaron.ballman.
danix800 added a project: clang.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Fix https://github.com/llvm/llvm-project/issues/63863


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155396

Files:
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaObjC/crash-on-val-dep-block-expr.m


Index: clang/test/SemaObjC/crash-on-val-dep-block-expr.m
===
--- /dev/null
+++ clang/test/SemaObjC/crash-on-val-dep-block-expr.m
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+// no crash
+
+int (^a)() = ^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+};
+
+int (^b)() = (^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+});
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16746,7 +16746,11 @@
   AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy();
   PoppedFunctionScopePtr ScopeRAII = PopFunctionScopeInfo(&WP, BD, BlockTy);
 
-  BlockExpr *Result = new (Context) BlockExpr(BD, BlockTy);
+  bool ContainsError = llvm::any_of(BSI->Returns, [](const ReturnStmt *Return) 
{
+const auto *RetValExpr = Return->getRetValue();
+return RetValExpr && RetValExpr->containsErrors();
+  });
+  BlockExpr *Result = new (Context) BlockExpr(BD, BlockTy, ContainsError);
 
   // If the block isn't obviously global, i.e. it captures anything at
   // all, then we need to do a few things in the surrounding context:
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -252,10 +252,12 @@
   return E->getBase()->getDependence();
 }
 
-ExprDependence clang::computeDependence(BlockExpr *E) {
+ExprDependence clang::computeDependence(BlockExpr *E, bool ContainsError) {
   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
   if (E->getBlockDecl()->isDependentContext())
 D |= ExprDependence::Instantiation;
+  if ((D & ExprDependence::Value) && ContainsError)
+D |= ExprDependence::Error;
   return D;
 }
 
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -5974,9 +5974,9 @@
 protected:
   BlockDecl *TheBlock;
 public:
-  BlockExpr(BlockDecl *BD, QualType ty)
+  BlockExpr(BlockDecl *BD, QualType ty, bool ContainsError = false)
   : Expr(BlockExprClass, ty, VK_PRValue, OK_Ordinary), TheBlock(BD) {
-setDependence(computeDependence(this));
+setDependence(computeDependence(this, ContainsError));
   }
 
   /// Build an empty block expression.
Index: clang/include/clang/AST/ComputeDependence.h
===
--- clang/include/clang/AST/ComputeDependence.h
+++ clang/include/clang/AST/ComputeDependence.h
@@ -131,7 +131,7 @@
 ExprDependence computeDependence(ImplicitValueInitExpr *E);
 ExprDependence computeDependence(InitListExpr *E);
 ExprDependence computeDependence(ExtVectorElementExpr *E);
-ExprDependence computeDependence(BlockExpr *E);
+ExprDependence computeDependence(BlockExpr *E, bool ContainsError);
 ExprDependence computeDependence(AsTypeExpr *E);
 ExprDependence computeDependence(DeclRefExpr *E, const ASTContext &Ctx);
 ExprDependence computeDependence(RecoveryExpr *E);


Index: clang/test/SemaObjC/crash-on-val-dep-block-expr.m
===
--- /dev/null
+++ clang/test/SemaObjC/crash-on-val-dep-block-expr.m
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+// no crash
+
+int (^a)() = ^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+};
+
+int (^b)() = (^() {
+  return c; // expected-error {{use of undeclared identifier 'c'}}
+});
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16746,7 +16746,11 @@
   AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy();
   PoppedFunctionScopePtr ScopeRAII = PopFunctionScopeInfo(&WP, BD, BlockTy);
 
-  BlockExpr *Result = new (Context) BlockExpr(BD, BlockTy);
+  bool ContainsError = llvm::any_of(BSI->Returns, [](const ReturnStmt *Return) {
+const auto *RetValExpr = Return->getRetValue();
+return RetValExpr && RetValExpr->containsErrors();
+  });
+  BlockExpr *Result = new (Context) BlockExpr(BD, BlockTy, ContainsError);
 
   // If the block isn't obviously global, i.e. it

[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 540773.
cor3ntin added a comment.

Fix the evaluation context of member initializers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155175/new/

https://reviews.llvm.org/D155175

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -164,3 +164,128 @@
 int i = g(x); // expected-error {{call to immediate function 'ConstevalConstructor::g' is not a constant expression}} \
   // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}}
 }
+
+
+
+namespace Aggregate {
+consteval int f(int); // expected-note {{declared here}}
+struct S {
+  int x = f(42); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+};
+
+constexpr S immediate(auto) {
+return S{};
+}
+
+void test_runtime() {
+(void)immediate(0); // expected-error {{call to immediate function 'Aggregate::immediate' is not a constant expression}} \
+// expected-note {{in call to 'immediate(0)'}}
+}
+consteval int f(int i) {
+return i;
+}
+consteval void test() {
+constexpr S s = immediate(0);
+static_assert(s.x == 42);
+}
+}
+
+
+
+namespace GH63742 {
+void side_effect(); // expected-note  {{declared here}}
+consteval int f(int x) {
+if (!x) side_effect(); // expected-note {{non-constexpr function 'side_effect' cannot be used in a constant expression}}
+return x;
+}
+struct SS {
+  int x = f(0); // expected-error {{call to consteval function 'GH63742::f' is not a constant expression}} \
+// expected-note  {{declared here}} \
+// expected-note  {{in call to 'f(0)'}}
+  SS();
+};
+SS::SS(){} // expected-note {{in the default initializer of 'x'}}
+
+consteval int f2(int x) {
+if (!__builtin_is_constant_evaluated()) side_effect();
+return x;
+}
+struct S2 {
+int x = f2(0);
+constexpr S2();
+};
+
+constexpr S2::S2(){}
+S2 s = {};
+
+struct S3 {
+int x = f2(0);
+S3();
+};
+S3::S3(){}
+
+}
+
+namespace Defaulted {
+consteval int f(int x);
+struct SS {
+  int x = f(0);
+  SS() = default;
+};
+}
+
+namespace DefaultedUse{
+consteval int f(int x);  // expected-note {{declared here}}
+struct SS {
+  int x = f(0); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+  SS() = default;
+};
+
+void test() {
+[[maybe_unused]] SS s; // expected-error {{call to immediate function 'DefaultedUse::SS::SS' is not a constant expression}} \
+   //  expected-note {{in call to 'SS()'}}
+}
+}
+
+namespace UserDefinedConstructors {
+consteval int f(int x) {
+return x;
+}
+extern int NonConst; // expected-note 2{{declared here}}
+
+struct ConstevalCtr {
+int y;
+int x = f(y);
+consteval ConstevalCtr(int yy)
+: y(f(yy)) {}
+};
+
+ConstevalCtr c1(1);
+ConstevalCtr c2(NonConst);
+// expected-error@-1 {{call to consteval function 'UserDefinedConstructors::ConstevalCtr::ConstevalCtr' is not a constant expression}} \
+// expected-note@-1 {{read of non-const variable 'NonConst' is not allowed in a constant expression}}
+
+struct ImmediateEscalating {
+int y;
+int x = f(y);
+template
+constexpr ImmediateEscalating(T yy)
+: y(f(yy)) {}
+};
+
+ImmediateEscalating c3(1);
+ImmediateEscalating c4(NonConst);
+// expected-error@-1 {{call to immediate function 'UserDefinedConstructors::ImmediateEscalating::ImmediateEscalating' is not a constant expression}} \
+// expected-note@-1 {{read of non-const variable 'NonConst' is not allowed in a constant expression}}
+
+
+struct NonEscalating {
+int y;
+int x = f(this->y); // expected-error {{call to consteval function 'UserDefinedConstructors::f' is not a constant expression}} \
+// expected-note  {{declared here}} \
+// expected-note  {{use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}}
+constexpr NonEscalating(int yy) : y(yy) {} // expected-note {{in the default initializer of 'x'}}
+};
+NonEscalating s = {1};
+
+}
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -41,19 +41,21 @@
 }();
 };
 
-consteval int ub(int n) { // expected-note {{declared here}}
+consteval int ub(int n) {
 return 0/n;
 }
 
 struct InitWithLambda {
-int b = [](int error = undefined()) {

[PATCH] D155367: [clang][Interp] Implement __builtin_inf() etc.

2023-07-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 540774.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155367/new/

https://reviews.llvm.org/D155367

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp


Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -116,6 +116,15 @@
   return true;
 }
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  S.Stk.push(Floating::getInf(TargetSemantics));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -147,6 +156,20 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_huge_val:
+  case Builtin::BI__builtin_huge_valf:
+  case Builtin::BI__builtin_huge_vall:
+  case Builtin::BI__builtin_huge_valf16:
+  case Builtin::BI__builtin_huge_valf128:
+  case Builtin::BI__builtin_inf:
+  case Builtin::BI__builtin_inff:
+  case Builtin::BI__builtin_infl:
+  case Builtin::BI__builtin_inff16:
+  case Builtin::BI__builtin_inff128:
+if (interp__builtin_inf(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }


Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -116,6 +116,15 @@
   return true;
 }
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  S.Stk.push(Floating::getInf(TargetSemantics));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -147,6 +156,20 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_huge_val:
+  case Builtin::BI__builtin_huge_valf:
+  case Builtin::BI__builtin_huge_vall:
+  case Builtin::BI__builtin_huge_valf16:
+  case Builtin::BI__builtin_huge_valf128:
+  case Builtin::BI__builtin_inf:
+  case Builtin::BI__builtin_inff:
+  case Builtin::BI__builtin_infl:
+  case Builtin::BI__builtin_inff16:
+  case Builtin::BI__builtin_inff128:
+if (interp__builtin_inf(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155400: [clang][Interp] Implement __builtin_fabs()

2023-07-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155400

Files:
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp


Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -129,3 +129,7 @@
   char classify_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];
   char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];
 }
+
+namespace fabs {
+  static_assert(__builtin_fabs(-14.0) == 14.0, "");
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -265,6 +265,20 @@
   return true;
 }
 
+// The C standard says "fabs raises no floating-point exceptions,
+// even if x is a signaling NaN. The returned value is independent of
+// the current rounding direction mode."  Therefore constant folding can
+// proceed without regard to the floating point settings.
+// Reference, WG14 N2478 F.10.4.3
+static bool interp__builtin_fabs(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func) {
+  const Floating &Val = getParam(Frame, 0);
+
+  S.Stk.push(Floating::abs(Val));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -358,6 +372,14 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_fabs:
+  case Builtin::BI__builtin_fabsf:
+  case Builtin::BI__builtin_fabsl:
+  case Builtin::BI__builtin_fabsf128:
+if (interp__builtin_fabs(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -149,6 +149,13 @@
 return bitcastFromMemory(Buff + sizeof(void *), *Sem);
   }
 
+  static Floating abs(const Floating &F) {
+APFloat V = F.F;
+if (V.isNegative())
+  V.changeSign();
+return Floating(V);
+  }
+
   // ---
 
   static APFloat::opStatus add(const Floating &A, const Floating &B,


Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -129,3 +129,7 @@
   char classify_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];
   char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];
 }
+
+namespace fabs {
+  static_assert(__builtin_fabs(-14.0) == 14.0, "");
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -265,6 +265,20 @@
   return true;
 }
 
+// The C standard says "fabs raises no floating-point exceptions,
+// even if x is a signaling NaN. The returned value is independent of
+// the current rounding direction mode."  Therefore constant folding can
+// proceed without regard to the floating point settings.
+// Reference, WG14 N2478 F.10.4.3
+static bool interp__builtin_fabs(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func) {
+  const Floating &Val = getParam(Frame, 0);
+
+  S.Stk.push(Floating::abs(Val));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -358,6 +372,14 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_fabs:
+  case Builtin::BI__builtin_fabsf:
+  case Builtin::BI__builtin_fabsl:
+  case Builtin::BI__builtin_fabsf128:
+if (interp__builtin_fabs(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -149,6 +149,13 @@
 return bitcastFromMemory(Buff + sizeof(void *), *Sem);
   }
 
+  static Floating abs(const Floating &F) {
+APFloat V = F.F;
+if (V.isNegative())
+  V.changeSign();
+return Floating(V);
+  }
+
   // ---
 
   static APFloat::opStatus add(const Floating &A, const Floating &B,
___

[PATCH] D155401: [clang][Interp] Implement __builtin_fmax

2023-07-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155401

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/Sema/constant-builtins-fmax.cpp


Index: clang/test/Sema/constant-builtins-fmax.cpp
===
--- clang/test/Sema/constant-builtins-fmax.cpp
+++ clang/test/Sema/constant-builtins-fmax.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify 
-fexperimental-new-constant-interpreter %s
 // expected-no-diagnostics
 
 constexpr double NaN = __builtin_nan("");
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -169,6 +169,26 @@
   return true;
 }
 
+static bool interp__builtin_fmax(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func) {
+  const Floating &LHS = getParam(Frame, 0);
+  const Floating &RHS = getParam(Frame, 1);
+
+  Floating Result;
+
+  // When comparing zeroes, return +0.0 if one of the zeroes is positive.
+  if (LHS.isZero() && RHS.isZero() && LHS.isNegative())
+Result = RHS;
+  else if (LHS.isNan() || RHS > LHS)
+Result = RHS;
+  else
+Result = LHS;
+
+  S.Stk.push(Result);
+  return true;
+}
+
 /// Defined as __builtin_isnan(...), to accommodate the fact that it can
 /// take a float, double, long double, etc.
 /// But for us, that's all a Floating anyway.
@@ -340,6 +360,15 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_fmax:
+  case Builtin::BI__builtin_fmaxf:
+  case Builtin::BI__builtin_fmaxl:
+  case Builtin::BI__builtin_fmaxf16:
+  case Builtin::BI__builtin_fmaxf128:
+if (interp__builtin_fmax(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   case Builtin::BI__builtin_isnan:
 if (interp__builtin_isnan(S, OpPC, Frame, F))
   return Ret(S, OpPC, Dummy);


Index: clang/test/Sema/constant-builtins-fmax.cpp
===
--- clang/test/Sema/constant-builtins-fmax.cpp
+++ clang/test/Sema/constant-builtins-fmax.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
 // expected-no-diagnostics
 
 constexpr double NaN = __builtin_nan("");
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -169,6 +169,26 @@
   return true;
 }
 
+static bool interp__builtin_fmax(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func) {
+  const Floating &LHS = getParam(Frame, 0);
+  const Floating &RHS = getParam(Frame, 1);
+
+  Floating Result;
+
+  // When comparing zeroes, return +0.0 if one of the zeroes is positive.
+  if (LHS.isZero() && RHS.isZero() && LHS.isNegative())
+Result = RHS;
+  else if (LHS.isNan() || RHS > LHS)
+Result = RHS;
+  else
+Result = LHS;
+
+  S.Stk.push(Result);
+  return true;
+}
+
 /// Defined as __builtin_isnan(...), to accommodate the fact that it can
 /// take a float, double, long double, etc.
 /// But for us, that's all a Floating anyway.
@@ -340,6 +360,15 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_fmax:
+  case Builtin::BI__builtin_fmaxf:
+  case Builtin::BI__builtin_fmaxl:
+  case Builtin::BI__builtin_fmaxf16:
+  case Builtin::BI__builtin_fmaxf128:
+if (interp__builtin_fmax(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   case Builtin::BI__builtin_isnan:
 if (interp__builtin_isnan(S, OpPC, Frame, F))
   return Ret(S, OpPC, Dummy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155081: Specify the developer policy around links to external resources

2023-07-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D155081#4499046 , @lattner wrote:

> Thank you so much for raising this issue Aaron.
>
> Documenting the policy in the developer policy is totally the right thing to 
> do given this cross-cuts individual subprojects, but I don't think we have 
> consensus on what the right approach is.  This is a pretty important issue to 
> a number of LLVM contributors, and I think we should have a first-principles 
> discussion about it on the forum before instituting a policy.
> https://discourse.llvm.org/t/code-review-reminder-about-links-in-code-commit-messages/71847/43?u=clattner

You're linking to that very discussion; I've not seen a whole lot of new input 
on that thread which did seem to come to a consensus, but I'm happy to wait 
longer for folks to weigh in before proceeding.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155081/new/

https://reviews.llvm.org/D155081

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


[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 540798.
xgupta marked an inline comment as done.
xgupta added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s bugprone-switch-missing-default-case -- %t
+
+typedef int MyInt;
+enum EnumType { eE2 };
+typedef EnumType MyEnum;
+
+void positive() {
+  int I1 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I1) {
+  case 0:
+break;
+  }
+
+  MyInt I2 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I2) {
+  case 0:
+break;
+  }
+
+  int getValue();
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (getValue()) {
+  case 0:
+break;
+  }
+}
+
+void negative() {
+  enum E { eE1 };
+  E E1 = eE1;
+  switch (E1) { // no-warning
+  case eE1:
+break;
+  }
+
+  MyEnum E2 = eE2;
+  switch (E2) { // no-warning
+  case eE2:
+break;
+  }
+
+  int I1 = 0;
+  switch (I1) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  MyInt I2 = 0;
+  switch (I2) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  int getValue();
+  switch (getValue()) { // no-warning
+  case 0:
+break;
+default:
+break;
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -92,6 +92,7 @@
`bugprone-forwarding-reference-overload `_,
`bugprone-implicit-widening-of-multiplication-result `_, "Yes"
`bugprone-inaccurate-erase `_, "Yes"
+   `bugprone-switch-missing-default-case `_, "Yes"
`bugprone-incorrect-roundings `_,
`bugprone-infinite-loop `_,
`bugprone-integer-division `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
@@ -0,0 +1,56 @@
+.. title:: clang-tidy - bugprone-switch-missing-default-case
+
+bugprone-switch-missing-default-case
+
+
+Ensures that switch statements without default cases are flagged, focuses only
+on covering cases with non-enums where the compiler may not issue warnings.
+
+Switch statements without a default case can lead to unexpected
+behavior and incomplete handling of all possible cases. When a switch statement
+lacks a default case, if a value is encountered that does not match any of the
+specified cases, the program will continue execution without any defined
+behavior or handling.
+
+This check helps identify switch statements that are missing a default case,
+allowing developers to ensure that all possible cases are handled properly.
+Adding a default case allows for graceful handling of unexpected or unmatched
+values, reducing the risk of program errors and unexpected behavior.
+
+Example:
+
+.. code-block:: c++
+
+  // Example 1:
+  // warning: switching on non-enum value without default case may not cover all cases
+  switch (i) {
+  case 0:
+break;
+  }
+
+  // Example 2:
+  enum E { eE1 };
+  E e = eE1;
+  switch (e) { // no-warning
+  case eE1:
+break;
+  }
+
+  // Example 3:
+  int i = 0;
+  switch (i) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+.. note::
+   Enum types are already covered by compiler warnings (comes under -Wswitch)
+   when a switch statement does not handle all enum values. This check focuses
+   on non-enum types where the compiler warnings may not be present.
+
+.. seealso::
+   The `CppCoreGuideline ES.79 `_
+   prov

[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta marked 3 inline comments as done.
xgupta added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:16-29
+void SwitchMissingDefaultCaseCheck::registerMatchers(
+ast_matchers::MatchFinder *Finder) {
+  Finder->addMatcher(
+  switchStmt(has(implicitCastExpr().bind("cast")),
+ unless(hasAncestor(switchStmt(has(defaultStmt())
+  .bind("switch"),
+  this);

PiotrZSL wrote:
> I do not like that implicitCastExpr.
> 
> this is AST for your example:
> ```
>`-SwitchStmt 
>   |-ImplicitCastExpr  'int' 
>   | `-DeclRefExpr  'int' lvalue Var 0x555de93bc200 'i' 'int'
>   `-CompoundStmt 
> `-CaseStmt 
>   |-ConstantExpr  'int'
>   | |-value: Int 0
>   | `-IntegerLiteral  'int' 0
>   `-BreakStmt 
> ```
> 
> look that case there is only because we got cast from rvalue to lvalue.
> if you write example like this:
> 
> ```
> int getValue();
> 
> void Positive() {
>   switch (getValue()) {
>   case 0:
> break;
>   }
> }
> 
> ```
> 
> there is not cast because AST will look like this:
> ```
> -SwitchStmt 
>   |-CallExpr  'int'
>   | `-ImplicitCastExpr  'int (*)()' 
>   |   `-DeclRefExpr  'int ()' lvalue Function 0x5573a3b38100 
> 'getValue' 'int ()'
>   `-CompoundStmt 
> `-CaseStmt 
>   |-ConstantExpr  'int'
>   | |-value: Int 0
>   | `-IntegerLiteral  'int' 0
>   `-BreakStmt 
> ```
> 
> So add test with rvalue int... remove that implicit cast checks, and use 
> IgnoreUnlessSpelledInSource (it will remove IntegralCast cast from enum to 
> int, so hasCondition would match enum directly)
Removed the implicit cast but couldn't get how to use 
IgnoreUnlessSpelledInSource here.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:19
+  Finder->addMatcher(
+  switchStmt(has(implicitCastExpr().bind("cast")),
+ unless(hasAncestor(switchStmt(has(defaultStmt())

PiotrZSL wrote:
> this should be something like:
> ```hasCondition(expr(hasType(qualType(hasCanonicalType(unless(hasDeclaration(enumDecl()))```
> Or you can verify just if type is integral type.
> Note that with modern C++ you may have init statements in enums.
> 
For some reason, the check is giving warning for enum cases and I couldn't 
understand why, can you please help?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

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


[PATCH] D154795: [clang][Interp] Check pointers for live-ness when returning them

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

LGTM. It may be worth submitting an issue for the current behavior which is 
wrong.
Do you want to add a quote to the standard? 
(https://eel.is/c++draft/expr.const#13.3)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154795/new/

https://reviews.llvm.org/D154795

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


[PATCH] D155367: [clang][Interp] Implement __builtin_inf() etc.

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:119
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {

why does that return a bool? you could make it void, and get rid of the if 
statement


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155367/new/

https://reviews.llvm.org/D155367

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


[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Sema/Lookup.h:197-200
+DiagnoseAccess(std::move(Other.DiagnoseAccess)),
+DiagnoseAmbiguous(std::move(Other.DiagnoseAmbiguous)),
 AllowHidden(std::move(Other.AllowHidden)),
 Shadowed(std::move(Other.Shadowed)),

these std::move are a bit superfluous :)



Comment at: clang/include/clang/Sema/Lookup.h:228-229
 Other.Paths = nullptr;
-Other.Diagnose = false;
+Other.DiagnoseAccess = false;
+Other.DiagnoseAmbiguous = false;
 return *this;

Does anything break if you remove these two lines? they don't appear useful


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155387/new/

https://reviews.llvm.org/D155387

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


[PATCH] D134475: [Clang] Add support for [[msvc::constexpr]] C++11 attribute

2023-07-16 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 540803.
RIscRIpt marked an inline comment as done.
RIscRIpt added a comment.

Bump

Renamed clang/test/AST/msvc-* to ms-*
Tried to improve doc note.
Rebased onto one of stable commits from main.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134475/new/

https://reviews.llvm.org/D134475

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ms-attrs-invalid.cpp
  clang/test/AST/ms-attrs.cpp
  clang/test/AST/ms-constexpr-new.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -84,6 +84,7 @@
 // CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
+// CHECK-NEXT: MSConstexpr (SubjectMatchRule_function)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
 // CHECK-NEXT: MaybeUndef (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
Index: clang/test/AST/ms-constexpr-new.cpp
===
--- /dev/null
+++ clang/test/AST/ms-constexpr-new.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -ast-dump %s | FileCheck %s
+
+// CHECK: used operator new
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+[[nodiscard]] [[msvc::constexpr]] inline void* __cdecl operator new(decltype(sizeof(void*)), void* p) noexcept { return p; }
+
+// CHECK: used constexpr construct_at
+// CHECK: AttributedStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: MSConstexprAttr 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: ReturnStmt 0x{{[0-9a-f]+}} 
+constexpr int* construct_at(int* p, int v) { [[msvc::constexpr]] return ::new (p) int(v); }
+
+constexpr bool check_construct_at() { int x; return *construct_at(&x, 42) == 42; }
+
+static_assert(check_construct_at());
Index: clang/test/AST/ms-attrs.cpp
===
--- /dev/null
+++ clang/test/AST/ms-attrs.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -ast-dump %s | FileCheck %s
+
+// [[msvc::constexpr]] tests
+
+// MSConstexprDocs (1)
+// CHECK: used f1 'bool ()'
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+[[msvc::constexpr]] bool f1() { return true; }
+
+// MSConstexprDocs (2)
+// CHECK: used constexpr f2 'bool ()'
+// CHECK: AttributedStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: MSConstexprAttr 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: ReturnStmt 0x{{[0-9a-f]+}} 
+constexpr bool f2() { [[msvc::constexpr]] return f1(); }
+
+static_assert(f2());
+
+constexpr bool f3() { [[msvc::constexpr]] return f1() || f1() && f1(); }
+static_assert(f3());
+
+[[msvc::constexpr]] int f4(int x) { [[msvc::constexpr]] return x > 1 ? 1 + f4(x / 2) : 0; }
+constexpr bool f5() { [[msvc::constexpr]] return f4(32) == 5; }
+static_assert(f5());
+
+[[msvc::constexpr]] int f6(int x)
+{
+switch (x)
+{
+case 42: return 1337;
+default:
+ if (x < 0) [[msvc::constexpr]] return f4(-x);
+ else return x;
+}
+}
+
+constexpr bool f7() { [[msvc::constexpr]] return f6(f6(42) - 1337 + f6(-32) - 5 + (f6(1) ? f6(0) : f6(2))) == f6(0); }
+static_assert(f7());
+
+constexpr bool f8() { return true; }
+[[msvc::constexpr]] bool f9() { return f8(); }
+constexpr bool f10() { [[msvc::constexpr]] return f9(); }
+static_assert(f10());
+
+struct S1 {
+[[msvc::constexpr]] virtual bool vm() { return true; }
+constexpr bool cm() { [[msvc::constexpr]] return vm(); }
+};
+static_assert(S1{}.cm());
+
+/*
+// TODO: Add support for [[msvc::constexpr]] constructor
+struct S2 {
+[[msvc::constexpr]] S2() {}
+[[msvc::constexpr]] bool value() { return true; }
+static constexpr bool check() { [[msvc::constexpr]] return S2{}.value(); }
+};
+static_assert(S2::check());
+*/
Index: clang/test/AST/ms-attrs-invalid.cpp
===
--- /dev/null
+++ clang/test/AST/ms-attrs-invalid.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -verify %s
+// RUN: %clang_cc1 -fms-extensions -std=c++17 -verify=cpp17 %s
+
+#if __cplusplus >= 202002L
+// Check explicitly invalid code
+
+void runtime() {} // expected-note {{declared here}}
+
+[[msvc::constexpr]] void f0() { runtime(); } // expected-error {{[[msvc::constexpr]] function

[PATCH] D134475: [Clang] Add support for [[msvc::constexpr]] C++11 attribute

2023-07-16 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:3543
+definition or a return statement. It has no effect on function declarations.
+This attribute permits constant evaluation of ``[[msvc::constexpr]]`` functions
+in ``[[msvc::constexpr]] return`` statements inside ``constexpr`` or

RIscRIpt wrote:
> erichkeane wrote:
> > Does it prohibit the inverse?  I think this documentation overall needs a 
> > much better description of what the semantics are here, particularly 
> > anything that you found in experimentation on the MS implementation.
> > Does it prohibit the inverse?
> Do you mean, can `[[msvc::constexpr]]` function call `constexpr` and remain 
> const-evaluated? Yes.
> 
> I elaborated on semantics in non-inline comment.
Tried to make doc notes more clear.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134475/new/

https://reviews.llvm.org/D134475

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


[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:16-29
+void SwitchMissingDefaultCaseCheck::registerMatchers(
+ast_matchers::MatchFinder *Finder) {
+  Finder->addMatcher(
+  switchStmt(has(implicitCastExpr().bind("cast")),
+ unless(hasAncestor(switchStmt(has(defaultStmt())
+  .bind("switch"),
+  this);

xgupta wrote:
> PiotrZSL wrote:
> > I do not like that implicitCastExpr.
> > 
> > this is AST for your example:
> > ```
> >`-SwitchStmt 
> >   |-ImplicitCastExpr  'int' 
> >   | `-DeclRefExpr  'int' lvalue Var 0x555de93bc200 'i' 'int'
> >   `-CompoundStmt 
> > `-CaseStmt 
> >   |-ConstantExpr  'int'
> >   | |-value: Int 0
> >   | `-IntegerLiteral  'int' 0
> >   `-BreakStmt 
> > ```
> > 
> > look that case there is only because we got cast from rvalue to lvalue.
> > if you write example like this:
> > 
> > ```
> > int getValue();
> > 
> > void Positive() {
> >   switch (getValue()) {
> >   case 0:
> > break;
> >   }
> > }
> > 
> > ```
> > 
> > there is not cast because AST will look like this:
> > ```
> > -SwitchStmt 
> >   |-CallExpr  'int'
> >   | `-ImplicitCastExpr  'int (*)()' 
> >   |   `-DeclRefExpr  'int ()' lvalue Function 0x5573a3b38100 
> > 'getValue' 'int ()'
> >   `-CompoundStmt 
> > `-CaseStmt 
> >   |-ConstantExpr  'int'
> >   | |-value: Int 0
> >   | `-IntegerLiteral  'int' 0
> >   `-BreakStmt 
> > ```
> > 
> > So add test with rvalue int... remove that implicit cast checks, and use 
> > IgnoreUnlessSpelledInSource (it will remove IntegralCast cast from enum to 
> > int, so hasCondition would match enum directly)
> Removed the implicit cast but couldn't get how to use 
> IgnoreUnlessSpelledInSource here.
Just add 
```
 std::optional getCheckTraversalKind() const override {
return TK_IgnoreUnlessSpelledInSource;
  }

```

to header, like it is in other checks.
this should also solve template handling, so add test like this:

```
template
void testTemplate(T value)
{
   switch(value)  {
   ...
   }
}

testTemplate(5);
testTemplate(SomeEnum);
```



Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:95
`bugprone-inaccurate-erase `_, "Yes"
+   `bugprone-switch-missing-default-case 
`_, "Yes"
`bugprone-incorrect-roundings `_,

check does not provide fixes, so remove that "Yes"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

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


[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:19
+  Finder->addMatcher(
+  switchStmt(has(implicitCastExpr().bind("cast")),
+ unless(hasAncestor(switchStmt(has(defaultStmt())

xgupta wrote:
> PiotrZSL wrote:
> > this should be something like:
> > ```hasCondition(expr(hasType(qualType(hasCanonicalType(unless(hasDeclaration(enumDecl()))```
> > Or you can verify just if type is integral type.
> > Note that with modern C++ you may have init statements in enums.
> > 
> For some reason, the check is giving warning for enum cases and I couldn't 
> understand why, can you please help?
Add getCheckTraversalKind and check again


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

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


[PATCH] D155380: [clang] Fix delayed template parsing

2023-07-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

Thanks. I can confirm that the tests pass for me with this applied.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155380/new/

https://reviews.llvm.org/D155380

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


[PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:1546
 
 def warn_consteval_if_always_true : Warning<
+  "consteval if is always %select{true|false}0 in this context">,

To be consistent with other tautological warnings



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8821
   "operand to 'typeid'">, InGroup;
+def warn_is_constant_evaluated_tauto_constexpr : Warning<
+  "'%select{std::is_constant_evaluated|__builtin_is_constant_evaluated}0' will 
always evaluate to %select{false|true}1 in this context">,





Comment at: clang/include/clang/Sema/Sema.h:1277
+/// as PotentiallyEvaluated.
+RuntimeEvaluated
   };

hazohelet wrote:
> cor3ntin wrote:
> > I think I'd prefer a boolean for that, `ExpressionEvaluationContext` 
> > somewhat matches standard definitions.
> > I think we might mostly be able to reuse PotentiallyEvaluatedIfUsed | 
> > PotentiallyEvaluated.
> > 
> > RuntimeEvaluated is anything that does not have a parent context that is 
> > constant evaluated/immediate/unevaluated. Maybe you could try to make a 
> > function for that?
> I made it a boolean instead of a new expression evaluation context.
> 
> > RuntimeEvaluated is anything that does not have a parent context that is 
> > constant evaluated/immediate/unevaluated. Maybe you could try to make a 
> > function for that?
> I dont't think it is correct. The definitions body of constexpr-qualified 
> function and non-qualified function both push `PotentiallyEvaluated`, so we 
> need some way to distinguish them, and this time it is a boolean.
Right, thanks for clarifying, i missed that



Comment at: clang/lib/Parse/ParseDecl.cpp:2440
+S.ExprEvalContexts.back().Context;
+if ((D.getDeclSpec().getTypeQualifiers() == DeclSpec::TQ_const ||
+ isNonlocalVariable(ThisDecl)) &&

Why are we looking at whether static vars are const qualified?



Comment at: clang/lib/Parse/ParseStmt.cpp:1513-1516
+EnterExpressionEvaluationContext Consteval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+Sema::ExpressionEvaluationContextRecord::EK_Other, IsConstexpr);

hazohelet wrote:
> cor3ntin wrote:
> > This seems wrong, the condition of a if statement is not constant evaluated.
> In this case `/*ShouldEnter=*/IsConstexpr`, so the constant evaluation 
> context is pushed only when it is a condition of constexpr if. The condition 
> of constexpr if shall be a constant expression as per 
> https://eel.is/c++draft/stmt.if#2
I missed that, makes sense!



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:17962-18006
-/// Determine whether the given declaration is a global variable or
-/// static data member.
-static bool isNonlocalVariable(const Decl *D) {
-  if (const VarDecl *Var = dyn_cast_or_null(D))
-return Var->hasGlobalStorage();
-
-  return false;

hazohelet wrote:
> cor3ntin wrote:
> > Can you explain the changes to this file? they seems to affect test cases 
> > unrelated to the goal of this PR
> When we push/pop evaluation context here, it behaves synchronously with 
> `InitializerScopeRAII`, in ParseDecl.cpp, which makes the evaluation of 
> `Actions.AddInitializerToDecl` happen outside of the initializer expression 
> evaluation context (e.g. initializer scope popped in 2581 and 
> AddInitializerToDecl evaluated in 2592 in ParseDecl.cpp). This is causing a 
> bug BEFORE this patch (https://godbolt.org/z/b18jxKT54 and the removed FIXME 
> in test/SemaCXX/cxx2a-consteval.cpp) because  we were pushing evaluation 
> context if the variable `isNonlocalVariable`. This PR separates the handling 
> of expression evaluation context of initializers from `InitializerScopeRAII` 
> to resolve these bugs.
> 
> The arguable changes in diagnostics caused by this are the removals of
> `warn_uninit_self_reference_in_reference_init` against `constexpr int &n = 
> n;` (You mentioned) and
> `warn_impcast_integer_precision_constant` against `constexpr signed char a = 
> 2*100;`
> Both are diagnosed by calling `Sema::DiagRuntimeBehavior`, and 
> `Sema::DiagIfReachable` called by this intentionally avoids emitting 
> diagnostics against initializer of constexpr variables. 
> (https://github.com/llvm/llvm-project/blob/ab73bd3897b58ecde22ec5eea14b6252f2d69b6e/clang/lib/Sema/SemaExpr.cpp#L20712-L20719)
> They were diagnosed BEFORE this patch because the expression evaluation 
> context was outside of the initializer evaluation context, and it emitted 
> false positives against cases like `constexpr signed char a = true ? 3 : 
> 200;` (https://godbolt.org/z/9z1rer7E3)
> I think if the evaluated result of constexpr variable initializer does not 
> fit the variable type it should be diagnosed, but the logic should be added 
> t

[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-07-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I don't have a problem with this, but I'm not an ObjC person so I can't really 
review from the validity of what its changing. If @owenpan and 
@HazardyKnusperkeks don't have an problem with this then I don't either as it 
likely won't impact most C++ users.




Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:10
 /// \file
-/// This file implements LeftRightQualifierAlignmentFixer, a TokenAnalyzer that
+/// This file implements QualifierAlignmentFixer, a TokenAnalyzer that
 /// enforces either left or right const depending on the style.

This is an unrelated change, it wrong and that was probably my fault, we should 
do this as a NFC



Comment at: llvm/utils/gn/secondary/clang/lib/Format/BUILD.gn:23
 "NamespaceEndCommentsFixer.cpp",
+"ObjCPropertyAttributeOrderFixer.cpp",
 "QualifierAlignmentFixer.cpp",

I never change these file either I think there is a bot or something that does 
this.



Comment at: llvm/utils/gn/secondary/clang/unittests/Format/BUILD.gn:39
 "NamespaceEndCommentsFixerTest.cpp",
+"ObjCPropertyAttributeOrderFixerTest.cpp",
 "QualifierFixerTest.cpp",

I never change these file either I think there is a bot or something that does 
this.



Comment at: utils/bazel/llvm-project-overlay/clang/BUILD.bazel:1360
 "lib/Format/Macros.h",
+"lib/Format/ObjCPropertyAttributeOrderFixer.h",
 "lib/Format/QualifierAlignmentFixer.h",

I never change these files I don't think we need to?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

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


[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-07-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

may remove the other build system files, I don't think its our responsiblity to 
keep them upto date.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D155175#4498788 , @efriedma wrote:

> Do we need CodeGen testcases here for full coverage?  The testcases from the 
> issue passed with -fsyntax-only.

You have something specific in mind?
The examples in the issues now lead to sema errors.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155175/new/

https://reviews.llvm.org/D155175

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


[PATCH] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4046
+   ? (Style.SpacesInParens == FormatStyle::SIPO_Always ||
+  Style.SpacesInParentheses)
+   : true;

isn't SpacesInParentheses mapped to Style.SpacesInParens == 
FormatStyle::SIPO_Always?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155239/new/

https://reviews.llvm.org/D155239

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 540809.
cor3ntin added a comment.

Assert if we try to generate code for a CallExpr to an immediate function


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155175/new/

https://reviews.llvm.org/D155175

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -164,3 +164,128 @@
 int i = g(x); // expected-error {{call to immediate function 'ConstevalConstructor::g' is not a constant expression}} \
   // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}}
 }
+
+
+
+namespace Aggregate {
+consteval int f(int); // expected-note {{declared here}}
+struct S {
+  int x = f(42); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+};
+
+constexpr S immediate(auto) {
+return S{};
+}
+
+void test_runtime() {
+(void)immediate(0); // expected-error {{call to immediate function 'Aggregate::immediate' is not a constant expression}} \
+// expected-note {{in call to 'immediate(0)'}}
+}
+consteval int f(int i) {
+return i;
+}
+consteval void test() {
+constexpr S s = immediate(0);
+static_assert(s.x == 42);
+}
+}
+
+
+
+namespace GH63742 {
+void side_effect(); // expected-note  {{declared here}}
+consteval int f(int x) {
+if (!x) side_effect(); // expected-note {{non-constexpr function 'side_effect' cannot be used in a constant expression}}
+return x;
+}
+struct SS {
+  int x = f(0); // expected-error {{call to consteval function 'GH63742::f' is not a constant expression}} \
+// expected-note  {{declared here}} \
+// expected-note  {{in call to 'f(0)'}}
+  SS();
+};
+SS::SS(){} // expected-note {{in the default initializer of 'x'}}
+
+consteval int f2(int x) {
+if (!__builtin_is_constant_evaluated()) side_effect();
+return x;
+}
+struct S2 {
+int x = f2(0);
+constexpr S2();
+};
+
+constexpr S2::S2(){}
+S2 s = {};
+
+struct S3 {
+int x = f2(0);
+S3();
+};
+S3::S3(){}
+
+}
+
+namespace Defaulted {
+consteval int f(int x);
+struct SS {
+  int x = f(0);
+  SS() = default;
+};
+}
+
+namespace DefaultedUse{
+consteval int f(int x);  // expected-note {{declared here}}
+struct SS {
+  int x = f(0); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+  SS() = default;
+};
+
+void test() {
+[[maybe_unused]] SS s; // expected-error {{call to immediate function 'DefaultedUse::SS::SS' is not a constant expression}} \
+   //  expected-note {{in call to 'SS()'}}
+}
+}
+
+namespace UserDefinedConstructors {
+consteval int f(int x) {
+return x;
+}
+extern int NonConst; // expected-note 2{{declared here}}
+
+struct ConstevalCtr {
+int y;
+int x = f(y);
+consteval ConstevalCtr(int yy)
+: y(f(yy)) {}
+};
+
+ConstevalCtr c1(1);
+ConstevalCtr c2(NonConst);
+// expected-error@-1 {{call to consteval function 'UserDefinedConstructors::ConstevalCtr::ConstevalCtr' is not a constant expression}} \
+// expected-note@-1 {{read of non-const variable 'NonConst' is not allowed in a constant expression}}
+
+struct ImmediateEscalating {
+int y;
+int x = f(y);
+template
+constexpr ImmediateEscalating(T yy)
+: y(f(yy)) {}
+};
+
+ImmediateEscalating c3(1);
+ImmediateEscalating c4(NonConst);
+// expected-error@-1 {{call to immediate function 'UserDefinedConstructors::ImmediateEscalating::ImmediateEscalating' is not a constant expression}} \
+// expected-note@-1 {{read of non-const variable 'NonConst' is not allowed in a constant expression}}
+
+
+struct NonEscalating {
+int y;
+int x = f(this->y); // expected-error {{call to consteval function 'UserDefinedConstructors::f' is not a constant expression}} \
+// expected-note  {{declared here}} \
+// expected-note  {{use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}}
+constexpr NonEscalating(int yy) : y(yy) {} // expected-note {{in the default initializer of 'x'}}
+};
+NonEscalating s = {1};
+
+}
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -41,19 +41,21 @@
 }();
 };
 
-consteval int ub(int n) { // expected-note {{declared here}}
+consteval int ub(int n) {
 return 0/n;
 }
 
 struct Init

[clang] b0697a1 - Create diagnostic group for definition deprecation warning

2023-07-16 Thread Aaron Ballman via cfe-commits

Author: Nuri Amari
Date: 2023-07-16T12:36:26-04:00
New Revision: b0697a1cb0b539c773548f62402816e2d9b6f107

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

LOG: Create diagnostic group for definition deprecation warning

In https://reviews.llvm.org/D126664, a warning is introduced
warning against the deprecated out of line definition of a
static constexpr member in C++17 and later. Prior to this patch,
the only diagnostic group controlling this diagnostic was -Wdeprecated,
which controls many many diagnostics. This patch creates
a diagnostic group specifically for this warning so it can
be controlled in isolation, while also being included with -Wdeprecated.

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

Added: 

clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c501903815955d..8f3bd70f7a2aa1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -386,6 +386,13 @@ Improvements to Clang's diagnostics
   on overload resolution, when the actual reason for the failure is loss of 
other qualifiers.
 - Clang's notes about unconvertible types in overload resolution failure now 
covers
   the source range of parameter declaration of the candidate function 
declaration.
+- Added a new diagnostic warning group
+  ``-Wdeprecated-redundant-constexpr-static-def``, under the existing
+  ``-Wdeprecated`` group. This controls warnings about out-of-line definitions
+  of 'static constexpr' data members that are unnecessary from C++17 onwards.
+
+ Bug Fixes in This Version
+ -
 
   *Example Code*:
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index cfc1c9bc15bd2d..c0797166585e44 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -186,6 +186,7 @@ def DeprecatedCopyWithDtor : 
DiagGroup<"deprecated-copy-with-dtor", [DeprecatedC
 // For compatibility with GCC.
 def : DiagGroup<"deprecated-copy-dtor", [DeprecatedCopyWithDtor]>;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
+def DeprecatedRedundantConstexprStaticDef : 
DiagGroup<"deprecated-redundant-constexpr-static-def">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
 def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
 def UnguardedAvailability : DiagGroup<"unguarded-availability",
@@ -224,7 +225,9 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,
-  DeprecatedWritableStr]>,
+  DeprecatedWritableStr,
+  
DeprecatedRedundantConstexprStaticDef,
+  ]>,
  DiagCategory<"Deprecations">;
 
 def CXX20Designator : DiagGroup<"c++20-designator">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eea4d4961c077a..d9932e0aa31a2a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -447,7 +447,7 @@ def warn_qual_return_type : Warning<
 def warn_deprecated_redundant_constexpr_static_def : Warning<
   "out-of-line definition of constexpr static data member is redundant "
   "in C++17 and is deprecated">,
-  InGroup, DefaultIgnore;
+  InGroup, DefaultIgnore;
 
 def warn_decl_shadow :
   Warning<"declaration shadows a %select{"

diff  --git 
a/clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp 
b/clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
new file mode 100644
index 00..873fbf1b32cac3
--- /dev/null
+++ 
b/clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s -Werror -Wdeprecated 
-Wno-error=deprecated-redundant-constexpr-static-def
+
+namespace {
+  struct A {
+static constexpr int n = 0;
+static constexpr int m = 0;
+  };
+  constexpr int A::n; // expected-warning{{out-of-line definition of constexpr 
static data member is redundant in C++17 and is deprecated}}
+  const int A::m; // expected-warning{{out-of-line definition of constexpr 
static data member is redundant in C++

[PATCH] D153881: Create diagnostic group for definition deprecation warning

2023-07-16 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0697a1cb0b5: Create diagnostic group for definition 
deprecation warning (authored by nuriamari, committed by aaron.ballman).

Changed prior to commit:
  https://reviews.llvm.org/D153881?vs=538751&id=540816#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153881/new/

https://reviews.llvm.org/D153881

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp


Index: 
clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
===
--- /dev/null
+++ 
clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s -Werror -Wdeprecated 
-Wno-error=deprecated-redundant-constexpr-static-def
+
+namespace {
+  struct A {
+static constexpr int n = 0;
+static constexpr int m = 0;
+  };
+  constexpr int A::n; // expected-warning{{out-of-line definition of constexpr 
static data member is redundant in C++17 and is deprecated}}
+  const int A::m; // expected-warning{{out-of-line definition of constexpr 
static data member is redundant in C++17 and is deprecated}}
+}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -447,7 +447,7 @@
 def warn_deprecated_redundant_constexpr_static_def : Warning<
   "out-of-line definition of constexpr static data member is redundant "
   "in C++17 and is deprecated">,
-  InGroup, DefaultIgnore;
+  InGroup, DefaultIgnore;
 
 def warn_decl_shadow :
   Warning<"declaration shadows a %select{"
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -186,6 +186,7 @@
 // For compatibility with GCC.
 def : DiagGroup<"deprecated-copy-dtor", [DeprecatedCopyWithDtor]>;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
+def DeprecatedRedundantConstexprStaticDef : 
DiagGroup<"deprecated-redundant-constexpr-static-def">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
 def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
 def UnguardedAvailability : DiagGroup<"unguarded-availability",
@@ -224,7 +225,9 @@
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,
-  DeprecatedWritableStr]>,
+  DeprecatedWritableStr,
+  
DeprecatedRedundantConstexprStaticDef,
+  ]>,
  DiagCategory<"Deprecations">;
 
 def CXX20Designator : DiagGroup<"c++20-designator">;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -386,6 +386,13 @@
   on overload resolution, when the actual reason for the failure is loss of 
other qualifiers.
 - Clang's notes about unconvertible types in overload resolution failure now 
covers
   the source range of parameter declaration of the candidate function 
declaration.
+- Added a new diagnostic warning group
+  ``-Wdeprecated-redundant-constexpr-static-def``, under the existing
+  ``-Wdeprecated`` group. This controls warnings about out-of-line definitions
+  of 'static constexpr' data members that are unnecessary from C++17 onwards.
+
+ Bug Fixes in This Version
+ -
 
   *Example Code*:
 


Index: clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s -Werror -Wdeprecated -Wno-error=deprecated-redundant-constexpr-static-def
+
+namespace {
+  struct A {
+static constexpr int n = 0;
+static constexpr int m = 0;
+  };
+  constexpr int A::n; // expected-warning{{out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated}}
+  const int A::m; // expected-warning{{out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated}}
+}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
==

[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-07-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Sema/Lookup.h:228-229
 Other.Paths = nullptr;
-Other.Diagnose = false;
+Other.DiagnoseAccess = false;
+Other.DiagnoseAmbiguous = false;
 return *this;

cor3ntin wrote:
> Does anything break if you remove these two lines? they don't appear useful
I think these make sense: if we move a lookup result into this one, then the 
other lookup result shouldn't issue diagnostics any more. (Otherwise we could 
see the same diagnostics twice.)



Comment at: clang/lib/Sema/SemaOverload.cpp:14930
   LookupQualifiedName(R, Record->getDecl());
-  R.suppressDiagnostics();
+  R.suppressAccessDiagnostics();
 

shafik wrote:
> I was a bit conservative where I changed this but maybe we should do this 
> everywhere.
Most of the other calls in this file all look wrong. `DiagnoseTwoPhaseLookup` 
and `BuildRecoveryCallExpr` are doing error recovery and I think it's 
appropriate for them to suppress all diagnostics, but the rest are doing 
standard-mandated searches, and so should diagnose lookup ambiguity.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155387/new/

https://reviews.llvm.org/D155387

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


[PATCH] D154869: [Flang] [FlangRT] Implement FlangRT library as solution to Flang's runtime LLVM integration

2023-07-16 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:934-936
+  // Default to the /../lib and
+  // /../runtimes/runtimes-bins/lib directories. This works fine
+  // on the platforms that we have tested so far. We will probably have to

Am I correct thinking that:
* "/../lib" is for `Fortran_main.a`, and
* "/../runtimes/runtimes-bins/lib " is for `libflang-rt`?

Could you document this? Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154869/new/

https://reviews.llvm.org/D154869

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


[PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

2023-07-16 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added inline comments.



Comment at: 
libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp:96
 int main(int, char**) {
-  if (!std::is_constant_evaluated()) {
-test_containers, std::deque>();

cor3ntin wrote:
> this is a funny one, what's the history of that?
Probably some code moving around. I think this was originally in another 
function.



Comment at: 
libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.verify.cpp:27
   static_assert(!std::is_constant_evaluated(), "");
-  // expected-warning@-1 0-1 {{'std::is_constant_evaluated' will always 
evaluate to 'true' in a manifestly constant-evaluated expression}}
+  // expected-warning@-1 0-1 {{'std::is_constant_evaluated' will always 
evaluate to true in this context}}
 #endif

cor3ntin wrote:
> Mordante wrote:
> > hazohelet wrote:
> > > philnik wrote:
> > > > Mordante wrote:
> > > > > Since libc++ support the latest ToT Clang and the last two official 
> > > > > releases this wont work. The `expected-warning` needs to be a 
> > > > > `expected-warning-re` that works for both the new and old diagnostic
> > > > You can also just shorten it to `'std::is_constant_evaluated' will 
> > > > always evaluate to`. Seems good enough to me.
> > > Thanks!
> > I really would like a regex. To me the current message misses an important 
> > piece of information; the `true` part. I care less about the rest of the 
> > message, but stripping the `true` means a warning like 
> > `std::is_constant_evaluated' will always evaluate to FALSE` would be valid 
> > too.
> Agreed with Mordante
We're not in the business of testing the compiler though. Taking a closer look, 
I'm not actually sure why this test exists at all. It doesn't seem like it 
tests anything useful w.r.t. the library. This has been added in 2fc5a78, but 
there the warning isn't checked, so that was clearly not the original intention.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155064/new/

https://reviews.llvm.org/D155064

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


[PATCH] D153458: [clang-tidy] Model noexcept more properly in bugprone-exception-escape

2023-07-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Looks good, great to see all these issues fixed! Have a couple small comments.




Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:319
 
+static bool cannotThrow(const FunctionDecl *Func) {
+  const auto *FunProto = Func->getType()->getAs();

PiotrZSL wrote:
> isuckatcs wrote:
> > Put this in the anonymous namespace above please to remain consistent.
> well, llvm style require `static`, if we want to be consistent, I can change 
> all other into static later.
Nit: I personally find it more readable as "canThrow". People with issues 
reading double negations will probably appreciate that too :) But if you 
strongly prefer this name I won't oppose.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:330-332
+return NoexceptExpr && !NoexceptExpr->isValueDependent() &&
+   NoexceptExpr->EvaluateAsBooleanCondition(
+   Result, Func->getASTContext(), true) &&

Would be good to write a small comment documenting this logic.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:332
+   NoexceptExpr->EvaluateAsBooleanCondition(
+   Result, Func->getASTContext(), true) &&
+   Result;

Would be good to use the syntax `/* Parameter = */true` to document what this 
magic `true` means.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153458/new/

https://reviews.llvm.org/D153458

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


[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 540818.
xgupta marked 5 inline comments as done.
xgupta added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
@@ -0,0 +1,59 @@
+// RUN: %check_clang_tidy %s bugprone-switch-missing-default-case -- %t
+
+typedef int MyInt;
+enum EnumType { eE2 };
+typedef EnumType MyEnum;
+
+template
+void testTemplate(T Value)
+{
+// CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+switch (Value) {
+case 0:
+break;
+}
+}
+
+void positive() {
+int I1 = 0;
+testTemplate(I1);
+
+MyInt I2 = 0;
+testTemplate(I2);
+
+int getValue();
+testTemplate(getValue());
+}
+
+void negative() {
+enum E { eE1 };
+E E1 = eE1;
+testTemplate(E1);
+
+MyEnum E2 = eE2;
+testTemplate(E2);
+
+int I1 = 0;
+switch (I1) {
+case 0:
+break;
+default:
+break;
+}
+
+MyInt I2 = 0;
+switch (I2) {
+case 0:
+break;
+default:
+break;
+}
+
+int getValue();
+switch (getValue()) {
+case 0:
+break;
+default:
+break;
+}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -92,6 +92,7 @@
`bugprone-forwarding-reference-overload `_,
`bugprone-implicit-widening-of-multiplication-result `_, "Yes"
`bugprone-inaccurate-erase `_, "Yes"
+   `bugprone-switch-missing-default-case `_,
`bugprone-incorrect-roundings `_,
`bugprone-infinite-loop `_,
`bugprone-integer-division `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
@@ -0,0 +1,56 @@
+.. title:: clang-tidy - bugprone-switch-missing-default-case
+
+bugprone-switch-missing-default-case
+
+
+Ensures that switch statements without default cases are flagged, focuses only
+on covering cases with non-enums where the compiler may not issue warnings.
+
+Switch statements without a default case can lead to unexpected
+behavior and incomplete handling of all possible cases. When a switch statement
+lacks a default case, if a value is encountered that does not match any of the
+specified cases, the program will continue execution without any defined
+behavior or handling.
+
+This check helps identify switch statements that are missing a default case,
+allowing developers to ensure that all possible cases are handled properly.
+Adding a default case allows for graceful handling of unexpected or unmatched
+values, reducing the risk of program errors and unexpected behavior.
+
+Example:
+
+.. code-block:: c++
+
+  // Example 1:
+  // warning: switching on non-enum value without default case may not cover all cases
+  switch (i) {
+  case 0:
+break;
+  }
+
+  // Example 2:
+  enum E { eE1 };
+  E e = eE1;
+  switch (e) { // no-warning
+  case eE1:
+break;
+  }
+
+  // Example 3:
+  int i = 0;
+  switch (i) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+.. note::
+   Enum types are already covered by compiler warnings (comes under -Wswitch)
+   when a switch statement does not handle all enum values. This check focuses
+   on non-enum types where the compiler warnings may not be present.
+
+.. seealso::
+   The `CppCoreGuideline ES.79 `_
+   provide guidelines on switch statements, including the recommendation to
+   always provide a default case.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-ex

[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:19
+  Finder->addMatcher(
+  switchStmt(has(implicitCastExpr().bind("cast")),
+ unless(hasAncestor(switchStmt(has(defaultStmt())

PiotrZSL wrote:
> xgupta wrote:
> > PiotrZSL wrote:
> > > this should be something like:
> > > ```hasCondition(expr(hasType(qualType(hasCanonicalType(unless(hasDeclaration(enumDecl()))```
> > > Or you can verify just if type is integral type.
> > > Note that with modern C++ you may have init statements in enums.
> > > 
> > For some reason, the check is giving warning for enum cases and I couldn't 
> > understand why, can you please help?
> Add getCheckTraversalKind and check again
Wow, feel like a magic!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

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


[PATCH] D151495: [clang-tidy] Improve build-in type handling in bugprone-swapped-arguments

2023-07-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for the fix!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151495/new/

https://reviews.llvm.org/D151495

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


[PATCH] D154838: [analyzer] Add check for null pointer passed to %p of printf family

2023-07-16 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Expect a review on around the next weekend due to vacations from me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154838/new/

https://reviews.llvm.org/D154838

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


[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Sema/Lookup.h:228-229
 Other.Paths = nullptr;
-Other.Diagnose = false;
+Other.DiagnoseAccess = false;
+Other.DiagnoseAmbiguous = false;
 return *this;

rsmith wrote:
> cor3ntin wrote:
> > Does anything break if you remove these two lines? they don't appear useful
> I think these make sense: if we move a lookup result into this one, then the 
> other lookup result shouldn't issue diagnostics any more. (Otherwise we could 
> see the same diagnostics twice.)
The reason I'm asking is that we don't seem consistent about resetting the 
state of the moved-from lookup, so i  don;t know if moved from lookup are ever 
reused. and if they are, should we use std::exchange or something along those 
lines?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155387/new/

https://reviews.llvm.org/D155387

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


[clang-tools-extra] cc4f865 - [clang-tidy] Improve build-in type handling in bugprone-swapped-arguments

2023-07-16 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-07-16T18:29:29Z
New Revision: cc4f86562127f29560abb54d0c11f277b3373a2a

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

LOG: [clang-tidy] Improve build-in type handling in bugprone-swapped-arguments

Improved detection of argument swaps involving integral and floating-point
types by enhancing handling of implicit conversions. Now implicit casts
from float to double are also considered, same for integers.
Improved documentation.

Fixes: #62926

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/swapped-arguments.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
index 078aed6911c5f0..8989444dde1300 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
@@ -17,7 +17,8 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::bugprone {
 
 void SwappedArgumentsCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(callExpr().bind("call"), this);
+  
Finder->addMatcher(callExpr(unless(isInTemplateInstantiation())).bind("call"),
+ this);
 }
 
 /// Look through lvalue to rvalue and nop casts. This filters out
@@ -41,7 +42,42 @@ static bool isImplicitCastCandidate(const CastExpr *Cast) {
  Cast->getCastKind() == CK_IntegralToBoolean ||
  Cast->getCastKind() == CK_IntegralToFloating ||
  Cast->getCastKind() == CK_MemberPointerToBoolean ||
- Cast->getCastKind() == CK_PointerToBoolean;
+ Cast->getCastKind() == CK_PointerToBoolean ||
+ (Cast->getCastKind() == CK_IntegralCast &&
+  Cast->getSubExpr()->getType()->isBooleanType());
+}
+
+static bool areTypesSemiEqual(const QualType L, const QualType R) {
+  if (L == R)
+return true;
+
+  if (!L->isBuiltinType() || !R->isBuiltinType())
+return false;
+
+  return (L->isFloatingType() && R->isFloatingType()) ||
+ (L->isIntegerType() && R->isIntegerType()) ||
+ (L->isBooleanType() && R->isBooleanType());
+}
+
+static bool areArgumentsPotentiallySwapped(const QualType LTo,
+   const QualType RTo,
+   const QualType LFrom,
+   const QualType RFrom) {
+  if (LTo == RTo || LFrom == RFrom)
+return false;
+
+  const bool REq = areTypesSemiEqual(RTo, LFrom);
+  if (LTo == RFrom && REq)
+return true;
+
+  bool LEq = areTypesSemiEqual(LTo, RFrom);
+  if (RTo == LFrom && LEq)
+return true;
+
+  if (REq && LEq && !areTypesSemiEqual(RTo, LTo))
+return true;
+
+  return false;
 }
 
 void SwappedArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
@@ -75,18 +111,16 @@ void SwappedArgumentsCheck::check(const 
MatchFinder::MatchResult &Result) {
 // heuristic.
 const Expr *LHSFrom = ignoreNoOpCasts(LHSCast->getSubExpr());
 const Expr *RHSFrom = ignoreNoOpCasts(RHSCast->getSubExpr());
-if (LHS->getType() == RHS->getType() ||
-LHS->getType() != RHSFrom->getType() ||
-RHS->getType() != LHSFrom->getType())
+if (!areArgumentsPotentiallySwapped(LHS->getType(), RHS->getType(),
+LHSFrom->getType(), 
RHSFrom->getType()))
   continue;
 
 // Emit a warning and fix-its that swap the arguments.
 diag(Call->getBeginLoc(), "argument with implicit conversion from %0 "
   "to %1 followed by argument converted from "
   "%2 to %3, potentially swapped arguments.")
-<< LHS->getType() << LHSFrom->getType() << RHS->getType()
-<< RHSFrom->getType()
-<< tooling::fixit::createReplacement(*LHS, *RHS, Ctx)
+<< LHSFrom->getType() << LHS->getType() << RHSFrom->getType()
+<< RHS->getType() << tooling::fixit::createReplacement(*LHS, *RHS, Ctx)
 << tooling::fixit::createReplacement(*RHS, *LHS, Ctx);
 
 // Remember that we emitted a warning for this argument.

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7c6efe60a013ae..e2b2ea3491aa8f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -313,6 +313,11 @@ Changes in existing checks
   sequenced when constructor call is written as list-initialization. Understand
  

[PATCH] D151495: [clang-tidy] Improve build-in type handling in bugprone-swapped-arguments

2023-07-16 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc4f86562127: [clang-tidy] Improve build-in type handling in 
bugprone-swapped-arguments (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D151495?vs=525786&id=540822#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151495/new/

https://reviews.llvm.org/D151495

Files:
  clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/swapped-arguments.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp
@@ -8,26 +8,31 @@
 void G(T a, U b) {
   F(a, b); // no-warning
   F(2.0, 4);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.
 // CHECK-FIXES: F(4, 2.0)
 }
 
+void funShortFloat(short, float);
+void funFloatFloat(float, float);
+void funBoolShort(bool, short);
+void funBoolFloat(bool, float);
+
 void foo() {
   F(1.0, 3);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.
 // CHECK-FIXES: F(3, 1.0)
 
 #define M(x, y) x##y()
 
   double b = 1.0;
   F(b, M(Some, Function));
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.
 // CHECK-FIXES: F(M(Some, Function), b);
 
 #define N F(b, SomeFunction())
 
   N;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.
 // In macro, don't emit fixits.
 // CHECK-FIXES: #define N F(b, SomeFunction())
 
@@ -42,12 +47,32 @@
 
 #define APPLY(f, x, y) f(x, y)
   APPLY(F, 1.0, 3);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.
 // CHECK-FIXES: APPLY(F, 3, 1.0);
 
 #define PARAMS 1.0, 3
 #define CALL(P) F(P)
   CALL(PARAMS);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.
 // In macro, don't emit fixits.
+
+  funShortFloat(5.0, 1U);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'short' followed by argument converted from 'unsigned int' to 'float', potentially swapped arguments.
+  // CHECK-FIXES: funShortFloat(1U, 5.0);
+  funShortFloat(5.0, 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'short' followed by argument converted from 'int' to 'float', potentially swapped arguments.
+  // CHECK-FIXES: funShortFloat(1, 5.0);
+  funShortFloat(5.0f, 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'float' to 'short' followed by argument converted from 'int' to 'float', potentially swapped arguments.
+  // CHECK-FIXES: funShortFloat(1, 5.0f);
+
+  funFloatFloat(1.0f, 2.0);
+
+  funBoolShort(1U, true);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'unsigned int' to 'bool' followed by argument conve

[PATCH] D153458: [clang-tidy] Model noexcept more properly in bugprone-exception-escape

2023-07-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 540823.
PiotrZSL marked 5 inline comments as done.
PiotrZSL added a comment.

Fix review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153458/new/

https://reviews.llvm.org/D153458

Files:
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -152,7 +152,7 @@
 }
 
 // FIXME: In this case 'a' is convertible to the handler and should be caught
-// but in reality it's thrown. Note that clang doesn't report a warning for 
+// but in reality it's thrown. Note that clang doesn't report a warning for
 // this either.
 void throw_catch_multi_ptr_5() noexcept {
   try {
@@ -249,7 +249,7 @@
 void throw_derived_catch_base_ptr_c() noexcept {
   try {
 derived d;
-throw &d; 
+throw &d;
   } catch(const base *) {
   }
 }
@@ -259,7 +259,7 @@
   try {
 derived d;
 const derived *p = &d;
-throw p; 
+throw p;
   } catch(base *) {
   }
 }
@@ -282,7 +282,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
   try {
 B b;
-throw b; 
+throw b;
   } catch(A) {
   }
 }
@@ -291,7 +291,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private_ptr' which should not throw exceptions
   try {
 B b;
-throw &b; 
+throw &b;
   } catch(A *) {
   }
 }
@@ -300,7 +300,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected' which should not throw exceptions
   try {
 C c;
-throw c; 
+throw c;
   } catch(A) {
   }
 }
@@ -309,7 +309,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected_ptr' which should not throw exceptions
   try {
 C c;
-throw &c; 
+throw &c;
   } catch(A *) {
   }
 }
@@ -318,7 +318,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -327,7 +327,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous_ptr' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -703,3 +703,22 @@
   throw 1;
   return 0;
 }
+
+// The following function all incorrectly throw exceptions, *but* calling them
+// should not yield a warning because they are marked as noexcept.
+
+void test_basic_no_throw() noexcept { throw 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'test_basic_no_throw' which should not throw exceptions
+
+void test_basic_throw() noexcept(false) { throw 42; }
+
+void only_calls_non_throwing() noexcept {
+  test_basic_no_throw();
+}
+
+void calls_non_and_throwing() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'calls_non_and_throwing' which should not throw exceptions
+  test_basic_no_throw();
+  test_basic_throw();
+}
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -269,7 +269,8 @@
 
 - Improved :doc:`bugprone-exception-escape
   ` to not emit warnings for
-  forward declarations of functions.
+  forward declarations of functions and additionally modified it to skip
+  ``noexcept`` functions during call stack analysis.
 
 - Fixed :doc:`bugprone-exception-escape`
   for coroutines where previously a warning would be emitted with coroutines
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -316,6 +316,34 @@
 }
 } // namespace
 
+static bool canThrow(const FunctionDecl *Func) {
+  const auto *FunProto = Func->getType()->getAs();
+  if (!FunProto)
+return true;
+
+  switch (FunProto->canThrow()) {
+  case CT_Cannot:
+return false;
+  case CT_Dependent: {
+const Expr *NoexceptExpr = FunProto->getNoexceptExpr();
+if (!NoexceptExpr)
+  return true; // no noexept - can throw
+
+if (NoexceptExpr->isValueDependent())
+  return true; // depend on template - 

[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Tests need to be reverted, and template handling corrected (check comments).
After that it looks good to me.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:29
+  Finder->addMatcher(
+  switchStmt(hasCondition(expr(hasType(qualType(
+ hasCanonicalType(unless(hasDeclaration(enumDecl(,





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp:1
+// RUN: %check_clang_tidy %s bugprone-switch-missing-default-case -- %t
+





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp:19
+int I1 = 0;
+testTemplate(I1);
+

wrong, do not change everything to use only testTemplates, leave previous one, 
template should be additional test, this is why test fail. Previous tests were 
fine, just some additional should be added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

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


[PATCH] D78038: [clangd] WIP: fix several bugs relating to include insertion

2023-07-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added reviewers: hokein, kadircet, VitaNuo.
nridge added a comment.

Let's try adding some reviewers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78038/new/

https://reviews.llvm.org/D78038

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> You have something specific in mind?

I was thinking something along the lines of the original testcase in 63742, 
which successfully compiled in 16, started producing an assertion on main, and 
successfully compiles with this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155175/new/

https://reviews.llvm.org/D155175

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


[PATCH] D78038: [clangd] WIP: fix several bugs relating to include insertion

2023-07-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Also adding links to the open issues this fixes:

- https://github.com/clangd/clangd/issues/333
- https://github.com/clangd/clangd/issues/337

Note the second issue is not specific to include insertion; it's a false 
positive diagnostic, which I think makes it a more severe bug than include 
insertion misbehaving. That issue likely has some duplicates lying around (at 
least I remember it coming up multiple times) though I can't find them at the 
moment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78038/new/

https://reviews.llvm.org/D78038

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


[PATCH] D155407: [Driver] Warn about all instances -mios-version-min not just the last

2023-07-16 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: arphaman, t.p.northover, MaskRay, ahatanak.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Follow-up to D155123 , uniformly handle cases 
where there are duplicate
-mios-verion-min arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155407

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154853: [clangd][c++20]Consider the constraint of a constrained auto in FindTarget.

2023-07-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:581
+
+[[Fooable]] auto i = 42;
+  )cpp";

sammccall wrote:
> this is going to have the same behavior on the `auto` token, right?
> 
> This is my main practical concern, that go-to-definition, hover, find-refs, 
> go-to-type etc on `auto` will now treat `Fooable` as their target.
> 
> (That said, I'm not sure exactly how common it is for `auto` to be 
> constrained in a non-dependent context...)
> That said, I'm not sure exactly how common it is for `auto` to be constrained 
> in a non-dependent context...

I think it may be reasonably common. For example, in this [hello world 
example](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2300r7.html#example-hello-world)
 for the C++23 asynchronous programming proposal we have things like `scheduler 
auto` and `sender auto` (where `scheduler` and `sender` are concepts).

So, do think we want `auto` linked to the concrete deduced type in situations 
like this, and only the concept name linked to the concept definition.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154853/new/

https://reviews.llvm.org/D154853

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


[PATCH] D154853: [clangd][c++20]Consider the constraint of a constrained auto in FindTarget.

2023-07-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:581
+
+[[Fooable]] auto i = 42;
+  )cpp";

nridge wrote:
> sammccall wrote:
> > this is going to have the same behavior on the `auto` token, right?
> > 
> > This is my main practical concern, that go-to-definition, hover, find-refs, 
> > go-to-type etc on `auto` will now treat `Fooable` as their target.
> > 
> > (That said, I'm not sure exactly how common it is for `auto` to be 
> > constrained in a non-dependent context...)
> > That said, I'm not sure exactly how common it is for `auto` to be 
> > constrained in a non-dependent context...
> 
> I think it may be reasonably common. For example, in this [hello world 
> example](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2300r7.html#example-hello-world)
>  for the C++23 asynchronous programming proposal we have things like 
> `scheduler auto` and `sender auto` (where `scheduler` and `sender` are 
> concepts).
> 
> So, do think we want `auto` linked to the concrete deduced type in situations 
> like this, and only the concept name linked to the concept definition.
> in this [hello world 
> example](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2300r7.html#example-hello-world)
>  for the C++23 asynchronous programming proposal

(Slight correction: this is a C++26 proposal. My point remains though.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154853/new/

https://reviews.llvm.org/D154853

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


[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-07-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Sema/Lookup.h:228-229
 Other.Paths = nullptr;
-Other.Diagnose = false;
+Other.DiagnoseAccess = false;
+Other.DiagnoseAmbiguous = false;
 return *this;

cor3ntin wrote:
> rsmith wrote:
> > cor3ntin wrote:
> > > Does anything break if you remove these two lines? they don't appear 
> > > useful
> > I think these make sense: if we move a lookup result into this one, then 
> > the other lookup result shouldn't issue diagnostics any more. (Otherwise we 
> > could see the same diagnostics twice.)
> The reason I'm asking is that we don't seem consistent about resetting the 
> state of the moved-from lookup, so i  don;t know if moved from lookup are 
> ever reused. and if they are, should we use std::exchange or something along 
> those lines?
I don't think moved-from `LookupResult`s are ever reused, and I don't think 
it's the intent for this function to leave a moved-from result in a state 
suitable for use in further lookups. (If you assign over a moved-from lookup 
result, that'd presumably work fine, though I doubt we ever do that.) The point 
here, I think, is just to leave the source of the move in a state where the 
destructor doesn't have side-effects any more.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155387/new/

https://reviews.llvm.org/D155387

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


[PATCH] D155367: [clang][Interp] Implement __builtin_inf() etc.

2023-07-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:119
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {

cor3ntin wrote:
> why does that return a bool? you could make it void, and get rid of the if 
> statement
No reason other than that all the evaluation functions (also in `Interp.h`) 
return `bool`, even if they always succeed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155367/new/

https://reviews.llvm.org/D155367

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


[PATCH] D155408: [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min

2023-07-16 Thread Cassie Jones via Phabricator via cfe-commits
porglezomp created this revision.
porglezomp added reviewers: arphaman, t.p.northover, MaskRay, ahatanak.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
porglezomp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Sometimes users pass this option when targeting embedded architectures like 
armv7m on non-darwin platforms.
This applies to watchOS and tvOS as well as iOS.

Depends on D155407 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155408

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,14 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos 
-mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-mios-version-min=5'
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: 
'-m{{ios|watchos|tvos}}-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -85,10 +85,16 @@
   if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
-// Don't reject -mios-version-min= if we have an iOS triple.
+// Don't reject these -version-min= if we have the appropriate triple.
 if (T.isiOS())
   for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
+if (T.isWatchOS())
+  for (Arg *A : Args.filtered(options::OPT_mwatchos_version_min_EQ))
+A->ignoreTargetSpecific();
+if (T.isTvOS())
+  for (Arg *A : Args.filtered(options::OPT_mtvos_version_min_EQ))
+A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
 T.setObjectFormat(llvm::Triple::MachO);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -8,12 +8,14 @@
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-watchos -mwatchos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-tvos -mtvos-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-APCS: "-target-abi" "apcs-gnu"
 
-// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-mios-version-min=5'
+// CHECK-MACHO-EMBEDDED-DIAG: warning: argument unused during compilation: '-m{{ios|watchos|tvos}}-version-min=5'
 // CHECK-MACHO-EMBEDDED: "-triple" "{{thumbv[67]e?m}}-apple-unknown-macho"
 // CHECK-MACHO-EMBEDDED: "-mrelocation-model" "pic"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -85,10 +85,16 @@
   if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7M ||
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
-// Don't reject -mios-version-min= if we have an iOS triple.
+// Don't reject these -version-min= if we have the appropriate triple.
 if (T.isiOS())
   for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific(

[PATCH] D155410: [clang][Interp] Fix comparing nan/inf floating point values

2023-07-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155410

Files:
  clang/lib/AST/Interp/Floating.h
  clang/test/AST/Interp/floats.cpp


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -148,3 +148,12 @@
   };
   static_assert(f() == __LDBL_MAX__);
 }
+
+namespace Compare {
+  constexpr float nan = __builtin_nan("");
+  constexpr float inf = __builtin_inf();
+  static_assert(!(nan == nan), "");
+  static_assert(nan != nan, "");
+  static_assert(!(inf < nan), "");
+  static_assert(!(inf > nan), "");
+}
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -102,7 +102,18 @@
   APFloat::fltCategory getCategory() const { return F.getCategory(); }
 
   ComparisonCategoryResult compare(const Floating &RHS) const {
-return Compare(F, RHS.F);
+llvm::APFloatBase::cmpResult CmpRes = F.compare(RHS.F);
+switch (CmpRes) {
+case llvm::APFloatBase::cmpLessThan:
+  return ComparisonCategoryResult::Less;
+case llvm::APFloatBase::cmpEqual:
+  return ComparisonCategoryResult::Equal;
+case llvm::APFloatBase::cmpGreaterThan:
+  return ComparisonCategoryResult::Greater;
+case llvm::APFloatBase::cmpUnordered:
+  return ComparisonCategoryResult::Unordered;
+}
+llvm_unreachable("Inavlid cmpResult value");
   }
 
   static APFloat::opStatus fromIntegral(APSInt Val,


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -148,3 +148,12 @@
   };
   static_assert(f() == __LDBL_MAX__);
 }
+
+namespace Compare {
+  constexpr float nan = __builtin_nan("");
+  constexpr float inf = __builtin_inf();
+  static_assert(!(nan == nan), "");
+  static_assert(nan != nan, "");
+  static_assert(!(inf < nan), "");
+  static_assert(!(inf > nan), "");
+}
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -102,7 +102,18 @@
   APFloat::fltCategory getCategory() const { return F.getCategory(); }
 
   ComparisonCategoryResult compare(const Floating &RHS) const {
-return Compare(F, RHS.F);
+llvm::APFloatBase::cmpResult CmpRes = F.compare(RHS.F);
+switch (CmpRes) {
+case llvm::APFloatBase::cmpLessThan:
+  return ComparisonCategoryResult::Less;
+case llvm::APFloatBase::cmpEqual:
+  return ComparisonCategoryResult::Equal;
+case llvm::APFloatBase::cmpGreaterThan:
+  return ComparisonCategoryResult::Greater;
+case llvm::APFloatBase::cmpUnordered:
+  return ComparisonCategoryResult::Unordered;
+}
+llvm_unreachable("Inavlid cmpResult value");
   }
 
   static APFloat::opStatus fromIntegral(APSInt Val,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-07-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14930
   LookupQualifiedName(R, Record->getDecl());
-  R.suppressDiagnostics();
+  R.suppressAccessDiagnostics();
 

rsmith wrote:
> shafik wrote:
> > I was a bit conservative where I changed this but maybe we should do this 
> > everywhere.
> Most of the other calls in this file all look wrong. `DiagnoseTwoPhaseLookup` 
> and `BuildRecoveryCallExpr` are doing error recovery and I think it's 
> appropriate for them to suppress all diagnostics, but the rest are doing 
> standard-mandated searches, and so should diagnose lookup ambiguity.
So it looks like `BuildOverloadedArrowExpr` catches the ambiguous lookup when 
calling `CandidateSet.BestViableFunction(...)` while 
`BuildCallToObjectOfClassType(...)` does not. So if I change the 
`suppressDiagnostics()` call in `BuildOverloadedArrowExpr` we get double 
diagnostic. I am not seeing why we have the inconsistency here.  


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155387/new/

https://reviews.llvm.org/D155387

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


[clang] f7ad7d1 - [Driver] Warn about all instances -mios-version-min not just the last

2023-07-16 Thread Cassie Jones via cfe-commits

Author: Cassie Jones
Date: 2023-07-16T16:45:49-07:00
New Revision: f7ad7d147b9c1e45e3f80f9e50be9984a8798e1a

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

LOG: [Driver] Warn about all instances -mios-version-min not just the last

Follow-up to D155123, uniformly handle cases where there are duplicate
-mios-verion-min arguments.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/macho-embedded.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 0f9474c45822f8..a73f46bb320294 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@ void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, 
StringRef Str,
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);

diff  --git a/clang/test/Driver/macho-embedded.c 
b/clang/test/Driver/macho-embedded.c
index 6b93b967e25448..14b933ba256de0 100644
--- a/clang/test/Driver/macho-embedded.c
+++ b/clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 



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


[PATCH] D155407: [Driver] Warn about all instances -mios-version-min not just the last

2023-07-16 Thread Cassie Jones via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf7ad7d147b9c: [Driver] Warn about all instances 
-mios-version-min not just the last (authored by porglezomp).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155407/new/

https://reviews.llvm.org/D155407

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/macho-embedded.c


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 
-mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);


Index: clang/test/Driver/macho-embedded.c
===
--- clang/test/Driver/macho-embedded.c
+++ clang/test/Driver/macho-embedded.c
@@ -7,6 +7,7 @@
 // RUN: %clang -arch armv7em -target thumbv7-apple-darwin -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED
 
 // RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
+// RUN: %clang -arch armv7m --target=thumbv7-apple-ios -mios-version-min=5 -mios-version-min=5 -fdriver-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-MACHO-EMBEDDED-DIAG
 
 // CHECK-IOS: "-triple" "thumbv7" "thumbv7-apple-ios
 
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -87,7 +87,7 @@
   ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
 // Don't reject -mios-version-min= if we have an iOS triple.
 if (T.isiOS())
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_mios_version_min_EQ))
+  for (Arg *A : Args.filtered(options::OPT_mios_version_min_EQ))
 A->ignoreTargetSpecific();
 
 T.setOS(llvm::Triple::UnknownOS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155413: [NFC] Add `push_back` to `llvm::Function`

2023-07-16 Thread Evan Wilde via Phabricator via cfe-commits
etcwilde created this revision.
etcwilde added reviewers: compnerd, vporpo.
etcwilde added a project: LLVM.
Herald added a project: All.
etcwilde requested review of this revision.
Herald added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits.

Appending a basic block to a function is a fairly common operation. The basic 
block list is private now, so pushing back is currently done by 
`myFunction->insert(myFunction->getEnd(), bb);`, which feels a bit redundant. 
This patch adds a `push_back` convenience function to `llvm::Function` to make 
appending basic blocks a bit easier again.

  +  /// append \p BB to the end of the function
  +  void push_back(BasicBlock *BB) {
  +return BasicBlocks.push_back(BB);
  +  }

I've also gone through and migrated the usage in kaleidoscope, the getting 
started docs, and in clang where I saw it.
I'm open to leaving that part of the change off, but it makes it a little bit 
clearer what the intended goal is.

I was going back and forth a little regarding the naming. `appendBasicBlock` is 
clearest, `push_back` is most consistent though.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155413

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl05.rst
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
  llvm/examples/Kaleidoscope/Chapter5/toy.cpp
  llvm/examples/Kaleidoscope/Chapter6/toy.cpp
  llvm/examples/Kaleidoscope/Chapter7/toy.cpp
  llvm/examples/Kaleidoscope/Chapter8/toy.cpp
  llvm/examples/Kaleidoscope/Chapter9/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp
  llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
  llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
  llvm/include/llvm/IR/Function.h

Index: llvm/include/llvm/IR/Function.h
===
--- llvm/include/llvm/IR/Function.h
+++ llvm/include/llvm/IR/Function.h
@@ -693,6 +693,11 @@
 return BasicBlocks.insert(Position, BB);
   }
 
+  /// append \p BB to the end of the function
+  void push_back(BasicBlock *BB) {
+return BasicBlocks.push_back(BB);
+  }
+
   /// Transfer all blocks from \p FromF to this function at \p ToIt.
   void splice(Function::iterator ToIt, Function *FromF) {
 splice(ToIt, FromF, FromF->begin(), FromF->end());
Index: llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
+++ llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
@@ -1025,7 +1025,7 @@
   ThenBB = Builder.GetInsertBlock();
 
   // Emit else block.
-  TheFunction->insert(TheFunction->end(), ElseBB);
+  TheFunction->push_back(ElseBB);
   Builder.SetInsertPoint(ElseBB);
 
   Value *ElseV = Else->Codegen();
@@ -1036,7 +1036,7 @@
   ElseBB = Builder.GetInsertBlock();
 
   // Emit merge block.
-  TheFunction->insert(TheFunction->end(), MergeBB);
+  TheFunction->push_back(MergeBB);
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
 
Index: llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
+++ llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
@@ -745,7 +745,7 @@
   ThenBB = Builder.GetInsertBlock();
   
   // Emit else block.
-  TheFunction->insert(TheFunction->end(), ElseBB);
+  TheFunction->push_back(ElseBB);
   Builder.SetInsertPoint(ElseBB);
   
   Value *ElseV = Else->Codegen();
@@ -756,7 +756,7 @@
   ElseBB = Builder.GetInsertBlock();
   
   // Emit merge block.
-  TheFunction->insert(TheFunction->end(), MergeBB);
+  TheFunction->push_back(MergeBB);
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
 
Index: llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
+++ llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
@@ -985,7 +985,7 @@
   ThenBB = Builder.GetInsertBlock();
 
   // Emit else block.
-  TheFunction->insert(TheFunction->end(), ElseBB);
+  TheFunction->push_back(ElseBB);
   Builder.SetInsertPoint(ElseBB);
 
   Value *ElseV = Else->Codegen();
@@ -996,7 +996,7 @@
   ElseBB = Builder.GetInsertBlock();
 
   // Emit merge block.
-  TheFunction->insert(TheFunction->end(), MergeBB);
+  TheFunction->push_back(MergeBB);
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
 
Index: l

[PATCH] D128648: [Clang][AArch64][SME] Add vector read/write (mova) intrinsics

2023-07-16 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc marked an inline comment as done.
bryanpkc added inline comments.



Comment at: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_read.c:13
+#else
+#define ARM_STREAMING_ATTR __attribute__((arm_streaming))
+#endif

sdesmalen wrote:
> The spelling has recently changed to the `__arm_streaming`. Also with the new 
> attribute keywords, the position of the attributes is more strict and need 
> sto be after the function arguments (e.g. `svint8_t test_svread_..(...) 
> ARM_STREAMING_ATTR {`)
> 
> Sorry if I previously gave you the wrong steer here to add these macros, but 
> I've changed my mind and think it's better to remove them for now. That means 
> we won't have any streaming attributes on the functions in the tests, but we 
> can (and will need to) add those when we add diagnostics for missing 
> attributes, for example when using a `shared ZA` intrinsic  when the function 
> misses `__arm_shared_za/__arm_new_za`, or when using a streaming intrinsic 
> when the function is not `__arm_streaming`. Writing this also made me realise 
> the functions below would be missing `__arm_shared_za` attributes.
> 
> Can you remove these macros from the patches? Again, my apologies for the 
> wrong steer!
@sdesmalen Thanks for the clarification and sorry for the late reply as I was 
on vacation. I have updated the patch as you suggested. I can also look into 
adding support for more attributes and corresponding semantic checks, if you 
guys haven't started already.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128648/new/

https://reviews.llvm.org/D128648

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


[PATCH] D134677: [Clang][AArch64][SME] Add ZA zeroing intrinsics

2023-07-16 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc updated this revision to Diff 540838.
bryanpkc added a comment.

Removed the attribute macro as suggested.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134677/new/

https://reviews.llvm.org/D134677

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/include/clang/Basic/arm_sve_sme_incl.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -192,6 +192,13 @@
   SVE_ACLE_FUNC(svwrite_ver_za8, _s8, _m,)(0, -1, 16, pg, svundef_s8());
 }
 
+void test_range_0_255(svbool_t pg, void *ptr) {
+  // expected-error@+1 {{argument value 256 is outside the valid range [0, 255]}}
+  SVE_ACLE_FUNC(svzero_mask_za,,,)(256);
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 255]}}
+  SVE_ACLE_FUNC(svzero_mask_za,,,)(-1);
+}
+
 void test_constant(uint64_t u64, svbool_t pg, void *ptr) {
   SVE_ACLE_FUNC(svld1_hor_za8,,,)(u64, u64, 0, pg, ptr);  // expected-error {{argument to 'svld1_hor_za8' must be a constant integer}}
   SVE_ACLE_FUNC(svld1_ver_za16,,,)(0, u64, u64, pg, ptr); // expected-error {{argument to 'svld1_ver_za16' must be a constant integer}}
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
@@ -0,0 +1,46 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+// CHECK-C-LABEL: @test_svzero_mask_za(
+// CHECK-CXX-LABEL: @_Z19test_svzero_mask_zav(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 0)
+// CHECK-NEXT:ret void
+//
+void test_svzero_mask_za() {
+  svzero_mask_za(0);
+}
+
+// CHECK-C-LABEL: @test_svzero_mask_za_1(
+// CHECK-CXX-LABEL: @_Z21test_svzero_mask_za_1v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 176)
+// CHECK-NEXT:ret void
+//
+void test_svzero_mask_za_1() {
+  svzero_mask_za(176);
+}
+
+// CHECK-C-LABEL: @test_svzero_mask_za_2(
+// CHECK-CXX-LABEL: @_Z21test_svzero_mask_za_2v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 255)
+// CHECK-NEXT:ret void
+//
+void test_svzero_mask_za_2() {
+  svzero_mask_za(255);
+}
+
+// CHECK-C-LABEL: @test_svzero_za(
+// CHECK-CXX-LABEL: @_Z14test_svzero_zav(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 255)
+// CHECK-NEXT:ret void
+//
+void test_svzero_za() {
+  svzero_za();
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3003,6 +3003,10 @@
   if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 15))
 HasError = true;
   break;
+case SVETypeFlags::ImmCheck0_255:
+  if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 255))
+HasError = true;
+  break;
 }
   }
 
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4283,6 +4283,9 @@
   llvm::Value *EmitSMEReadWrite(SVETypeFlags TypeFlags,
 llvm::SmallVectorImpl &Ops,
 unsigned IntID);
+  llvm::Value *EmitSMEZero(SVETypeFlags TypeFlags,
+   llvm::SmallVectorImpl &Ops,
+   unsigned IntID);
   llvm::Value *EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
 
   llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -9495,6 +9495,16 @@
   return Builder.CreateCall(F, Ops);
 }
 
+Value *CodeGenFunction::EmitSMEZero(SVETypeFlags TypeFlags,
+SmallVectorImpl &Ops,
+unsigned IntID) {
+  // svzero_za() intrinsic zeros the entire za tile and

[PATCH] D134678: [Clang][AArch64][SME] Add intrinsics for ZA array load/store (LDR/STR)

2023-07-16 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc updated this revision to Diff 540839.
bryanpkc added a comment.

Removed the attribute macro from tests, as @sdesmalen suggested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134678/new/

https://reviews.llvm.org/D134678

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -174,6 +174,11 @@
   // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}}
   SVE_ACLE_FUNC(svst1_ver_vnum_za8,,,)(0, -1, 16, pg, ptr, 1);
 
+  // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}}
+  SVE_ACLE_FUNC(svldr_vnum_za,,,)(-1, 16, ptr);
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 15]}}
+  SVE_ACLE_FUNC(svstr_vnum_za,,,)(-1, -1, ptr);
+
   // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 15]}}
   SVE_ACLE_FUNC(svread_hor_za128, _s8, _m,)(svundef_s8(), pg, -1, -1, 0);
   // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}}
@@ -209,6 +214,9 @@
   SVE_ACLE_FUNC(svst1_hor_vnum_za32,,,)(u64, u64, 0, pg, ptr, u64); // expected-error {{argument to 'svst1_hor_vnum_za32' must be a constant integer}}
   SVE_ACLE_FUNC(svst1_ver_vnum_za64,,,)(0, u64, u64, pg, ptr, u64); // expected-error {{argument to 'svst1_ver_vnum_za64' must be a constant integer}}
 
+  SVE_ACLE_FUNC(svldr_vnum_za,,,)(u64, u64, ptr); // expected-error {{argument to 'svldr_vnum_za' must be a constant integer}}
+  SVE_ACLE_FUNC(svstr_vnum_za,,,)(u64, u64, ptr); // expected-error {{argument to 'svstr_vnum_za' must be a constant integer}}
+
   SVE_ACLE_FUNC(svread_hor_za8, _s8, _m,)(svundef_s8(), pg, 0, u64, u64); // expected-error-re {{argument to 'svread_hor_za8{{.*}}_m' must be a constant integer}}
   SVE_ACLE_FUNC(svread_ver_za16, _s16, _m,)(svundef_s16(), pg, u64, u64, 0);  // expected-error-re {{argument to 'svread_ver_za16{{.*}}_m' must be a constant integer}}
   SVE_ACLE_FUNC(svwrite_hor_za32, _s32, _m,)(0, u64, u64, pg, svundef_s32()); // expected-error-re {{argument to 'svwrite_hor_za32{{.*}}_m' must be a constant integer}}
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c
@@ -0,0 +1,29 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+// CHECK-C-LABEL: @test_svstr_vnum_za(
+// CHECK-CXX-LABEL: @_Z18test_svstr_vnum_zajPv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str(i32 [[SLICE_BASE:%.*]], ptr [[PTR:%.*]])
+// CHECK-NEXT:ret void
+//
+void test_svstr_vnum_za(uint32_t slice_base, void *ptr) {
+  svstr_vnum_za(slice_base, 0, ptr);
+}
+
+// CHECK-C-LABEL: @test_svstr_vnum_za_1(
+// CHECK-CXX-LABEL: @_Z20test_svstr_vnum_za_1jPv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VSCALE:%.*]] = tail call i64 @llvm.vscale.i64()
+// CHECK-NEXT:[[MULVL:%.*]] = mul nuw nsw i64 [[VSCALE]], 240
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 [[MULVL]]
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str(i32 [[SLICE_BASE:%.*]], ptr [[TMP0]])
+// CHECK-NEXT:ret void
+//
+void test_svstr_vnum_za_1(uint32_t slice_base, void *ptr) {
+  svstr_vnum_za(slice_base, 15, ptr);
+}
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -0,0 +1,29 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S 

[PATCH] D134680: [Clang][AArch64][SME] Add intrinsics for adding vector elements to ZA tile

2023-07-16 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc updated this revision to Diff 540840.
bryanpkc added a comment.

Removed the attribute macro from tests, as @sdesmalen suggested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134680/new/

https://reviews.llvm.org/D134680

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -118,6 +118,11 @@
   SVE_ACLE_FUNC(svwrite_hor_za32, _s32, _m,)(0, -1, -1, pg, svundef_s32());
   // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
   SVE_ACLE_FUNC(svwrite_ver_za32, _s32, _m,)(3, -1, 4, pg, svundef_s32());
+
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svaddha_za32, _s32, _m,)(4, pg, pg, svundef_s32());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svaddva_za32, _s32, _m,)(-1, pg, pg, svundef_s32());
 }
 
 void test_range_0_7(svbool_t pg, void *ptr) {
@@ -154,6 +159,11 @@
   SVE_ACLE_FUNC(svwrite_hor_za16, _s16, _m,)(0, -1, -1, pg, svundef_s16());
   // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
   SVE_ACLE_FUNC(svwrite_ver_za16, _s16, _m,)(1, -1, 8, pg, svundef_s16());
+
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svaddha_za64, _s64, _m,)(8, pg, pg, svundef_s64());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svaddva_za64, _s64, _m,)(-1, pg, pg, svundef_s64());
 }
 
 void test_range_0_15(svbool_t pg, void *ptr) {
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c
@@ -0,0 +1,110 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+#ifdef SME_OVERLOADED_FORMS
+#define SME_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SME_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-C-LABEL: @test_svaddha_za64_u64(
+// CHECK-CXX-LABEL: @_Z21test_svaddha_za64_u64u10__SVBool_tu10__SVBool_tu12__SVUint64_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PN:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.addha.nxv2i64(i32 0,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]])
+// CHECK-NEXT:ret void
+//
+void test_svaddha_za64_u64(svbool_t pn, svbool_t pm, svuint64_t zn) {
+  SME_ACLE_FUNC(svaddha_za64, _u64, _m)(0, pn, pm, zn);
+}
+
+// CHECK-C-LABEL: @test_svaddha_za64_u64_1(
+// CHECK-CXX-LABEL: @_Z23test_svaddha_za64_u64_1u10__SVBool_tu10__SVBool_tu12__SVUint64_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PN:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.addha.nxv2i64(i32 7,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]])
+// CHECK-NEXT:ret void
+//
+void test_svaddha_za64_u64_1(svbool_t pn, svbool_t pm, svuint64_t zn) {
+  SME_ACLE_FUNC(svaddha_za64, _u64, _m)(7, pn, pm, zn);
+}
+
+// CHECK-C-LABEL: @test_svaddha_za64_s64(
+// CHECK-CXX-LABEL: @_Z21test_svaddha_za64_s64u10__SVBool_tu10__SVBool_tu11__SVInt64_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PN:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool

[PATCH] D134681: [Clang][AArch64][SME] Add outer product intrinsics

2023-07-16 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc updated this revision to Diff 540841.
bryanpkc added a comment.

Removed the attribute macro from tests, as @sdesmalen suggested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134681/new/

https://reviews.llvm.org/D134681

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za32.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za32.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -123,6 +123,19 @@
   SVE_ACLE_FUNC(svaddha_za32, _s32, _m,)(4, pg, pg, svundef_s32());
   // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
   SVE_ACLE_FUNC(svaddva_za32, _s32, _m,)(-1, pg, pg, svundef_s32());
+
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svmopa_za32, _s8, _m,)(4, pg, pg, svundef_s8(), svundef_s8());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svmops_za32, _s8, _m,)(-1, pg, pg, svundef_s8(), svundef_s8());
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svsumopa_za32, _s8, _m,)(4, pg, pg, svundef_s8(), svundef_u8());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svsumops_za32, _s8, _m,)(-1, pg, pg, svundef_s8(), svundef_u8());
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svusmopa_za32, _u8, _m,)(4, pg, pg, svundef_u8(), svundef_s8());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svusmops_za32, _u8, _m,)(-1, pg, pg, svundef_u8(), svundef_s8());
 }
 
 void test_range_0_7(svbool_t pg, void *ptr) {
@@ -164,6 +177,19 @@
   SVE_ACLE_FUNC(svaddha_za64, _s64, _m,)(8, pg, pg, svundef_s64());
   // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
   SVE_ACLE_FUNC(svaddva_za64, _s64, _m,)(-1, pg, pg, svundef_s64());
+
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svmopa_za64, _s16, _m,)(8, pg, pg, svundef_s16(), svundef_s16());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svmops_za64, _s16, _m,)(-1, pg, pg, svundef_s16(), svundef_s16());
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svsumopa_za64, _s16, _m,)(8, pg, pg, svundef_s16(), svundef_u16());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svsumops_za64, _s16, _m,)(-1, pg, pg, svundef_s16(), svundef_u16());
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svusmopa_za64, _u16, _m,)(8, pg, pg, svundef_u16(), svundef_s16());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svusmops_za64, _u16, _m,)(-1, pg, pg, svundef_u16(), svundef_s16());
 }
 
 void test_range_0_15(svbool_t pg, void *ptr) {
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
@@ -0,0 +1,74 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -W

[PATCH] D142702: [Clang][AArch64][SME] Generate target features from +(no)sme.* options

2023-07-16 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc updated this revision to Diff 540842.
bryanpkc marked an inline comment as done.
bryanpkc added a comment.

Removed dependency on SVE and SVE2 as per @sdesmalen's suggestion. Also made 
`nobf16` imply `nosme` to be consistent with the handling of other feature 
dependencies.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142702/new/

https://reviews.llvm.org/D142702

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-implied-sme-features.c


Index: clang/test/Driver/aarch64-implied-sme-features.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-implied-sme-features.c
@@ -0,0 +1,49 @@
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme %s -### 2>&1 | 
FileCheck %s --check-prefix=SME-IMPLY
+// SME-IMPLY: "-target-feature" "+sme" "-target-feature" "+bf16"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme %s -### 2>&1 | 
FileCheck %s --check-prefix=NOSME
+// NOSME: "-target-feature" "-sme"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme+nosme %s -### 2>&1 
| FileCheck %s --check-prefix=SME-REVERT
+// SME-REVERT-NOT: "-target-feature" "+sme"
+// SME-REVERT: "-target-feature" "+bf16" "-target-feature" "-sme" 
"-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme+nobf16 %s -### 
2>&1 | FileCheck %s --check-prefix=SME-CONFLICT
+// SME-CONFLICT-NOT: "-target-feature" "+sme"
+// SME-CONFLICT-NOT: "-target-feature" "+bf16"
+// SME-CONFLICT: "-target-feature" "-bf16" "-target-feature" "-sme" 
"-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-i16i64 %s -### 
2>&1 | FileCheck %s --check-prefix=SME-I16I64
+// SME-I16I64: "-target-feature" "+sme-i16i64" "-target-feature" "+sme" 
"-target-feature" "+bf16"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme-i16i64 %s -### 
2>&1 | FileCheck %s --check-prefix=NOSME-I16I64
+// NOSME-I16I64-NOT: "-target-feature" "+sme-i16i64"
+// NOSME-I16I64-NOT: "-target-feature" "+sme"
+// NOSME-I16I64-NOT: "-target-feature" "+bf16"
+// NOSME-I16I64: "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-i16i64+nosme-i16i64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-I16I64-REVERT
+// SME-I16I64-REVERT: "-target-feature" "+sme" "-target-feature" "+bf16" 
"-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme-f64f64 %s -### 
2>&1 | FileCheck %s --check-prefix=NOSME-F64F64
+// NOSME-F64F64-NOT: "-target-feature" "+sme-f64f64"
+// NOSME-F64F64-NOT: "-target-feature" "+sme"
+// NOSME-F64F64-NOT: "-target-feature" "+bf16"
+// NOSME-F64F64: "-target-feature" "-sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-f64f64+nosme-f64f64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-F64F64-REVERT
+// SME-F64F64-REVERT: "-target-feature" "+sme" "-target-feature" "+bf16" 
"-target-feature" "-sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-f64f64+nosme-i16i64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-SUBFEATURE-MIX
+// SME-SUBFEATURE-MIX: "-target-feature" "+sme-f64f64" "-target-feature" 
"+sme" "-target-feature" "+bf16" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-i16i64+nosme %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT1
+// SME-SUBFEATURE-CONFLICT1: "-target-feature" "+bf16" "-target-feature" 
"-sme" "-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-f64f64+nobf16 %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT2
+// SME-SUBFEATURE-CONFLICT2-NOT: "-target-feature" "+bf16"
+// SME-SUBFEATURE-CONFLICT2-NOT: "-target-feature" "+sme"
+// SME-SUBFEATURE-CONFLICT2-NOT: "-target-feature" "+sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme+sme-i16i64 %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT-REV
+// SME-SUBFEATURE-CONFLICT-REV: "-target-feature" "-sme-f64f64" 
"-target-feature" "+sme-i16i64" "-target-feature" "+sme" "-target-feature" 
"+bf16"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -82,6 +82,25 @@
 else
   return false;
 
+// +sme implies +bf16.
+// +sme-f64f64 and +sme-i16i64 both imply +sme.
+if (Feature == "sme") {
+  Features.push_back("+bf16");
+} else if (Feature == "nosme") {
+  Features.push_back("-sme-f64f64");
+  Features.push_back("-sme-i16i64");
+} else if (Feature == "sme-f64f64") {
+  Features.push_back("+sme");
+  Features.push_back("+bf16");
+} else if

[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 540845.
xgupta marked an inline comment as done.
xgupta added a comment.

Updated testcase [WIP]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
@@ -0,0 +1,80 @@
+// RUN: %check_clang_tidy %s bugprone-switch-missing-default-case %t -- -- -fno-delayed-template-parsing
+
+typedef int MyInt;
+enum EnumType { eE2 };
+typedef EnumType MyEnum;
+
+void positive() {
+  int I1 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I1) {
+  case 0:
+break;
+  }
+
+  MyInt I2 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I2) {
+  case 0:
+break;
+  }
+
+  int getValue(void);
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (getValue()) {
+  case 0:
+break;
+  }
+}
+
+void negative() {
+  enum E { eE1 };
+  E E1 = eE1;
+  switch (E1) { // no-warning
+  case eE1:
+break;
+  }
+
+  MyEnum E2 = eE2;
+  switch (E2) { // no-warning
+  case eE2:
+break;
+  }
+
+  int I1 = 0;
+  switch (I1) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  MyInt I2 = 0;
+  switch (I2) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  int getValue(void);
+  switch (getValue()) { // no-warning
+  case 0:
+break;
+default:
+break;
+  }
+}
+
+template
+void testTemplate(T Value) {
+  switch (Value) {
+case 0:
+  break;
+  }
+}
+
+void exampleUsage() {
+  testTemplate(5);
+  testTemplate(EnumType::eE2);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -92,6 +92,7 @@
`bugprone-forwarding-reference-overload `_,
`bugprone-implicit-widening-of-multiplication-result `_, "Yes"
`bugprone-inaccurate-erase `_, "Yes"
+   `bugprone-switch-missing-default-case `_,
`bugprone-incorrect-roundings `_,
`bugprone-infinite-loop `_,
`bugprone-integer-division `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
@@ -0,0 +1,56 @@
+.. title:: clang-tidy - bugprone-switch-missing-default-case
+
+bugprone-switch-missing-default-case
+
+
+Ensures that switch statements without default cases are flagged, focuses only
+on covering cases with non-enums where the compiler may not issue warnings.
+
+Switch statements without a default case can lead to unexpected
+behavior and incomplete handling of all possible cases. When a switch statement
+lacks a default case, if a value is encountered that does not match any of the
+specified cases, the program will continue execution without any defined
+behavior or handling.
+
+This check helps identify switch statements that are missing a default case,
+allowing developers to ensure that all possible cases are handled properly.
+Adding a default case allows for graceful handling of unexpected or unmatched
+values, reducing the risk of program errors and unexpected behavior.
+
+Example:
+
+.. code-block:: c++
+
+  // Example 1:
+  // warning: switching on non-enum value without default case may not cover all cases
+  switch (i) {
+  case 0:
+break;
+  }
+
+  // Example 2:
+  enum E { eE1 };
+  E e = eE1;
+  switch (e) { // no-warning
+  case eE1:
+break;
+  }
+
+  // Example 3:
+  int i = 0;
+  switch (i) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+.. note::
+   Enum types are already covered by compiler warnings (comes under -Wswitch)
+   when a switch statement does not handle all enum values. Thi

[PATCH] D155414: [Clang][RISCV] Guard RVV intrinsics types that is not available when ELEN < 64

2023-07-16 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: aaron.ballman, craig.topper.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, MaskRay.
Herald added a project: clang.

(ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1)
requires at least `zve64x`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155414

Files:
  clang/include/clang/AST/Type.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulh-overloaded.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulh.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulhsu-overloaded.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulhsu.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulhu-overloaded.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulhu.c
  clang/test/Sema/riscv-vector-zve64x-check.c

Index: clang/test/Sema/riscv-vector-zve64x-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-zve64x-check.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple riscv64 \
+// RUN:   -target-feature +zve32x -disable-O0-optnone -o - \
+// RUN:   -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+  // (ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1) is not in zve32*
+  // available when ELEN is smaller than 64.
+
+__rvv_int8mf8_t foo8() { /* expected-error {{RISC-V type '__rvv_int8mf8_t' requires the 'zve64x' extension}} */
+  __rvv_int8mf8_t i8mf8; /* expected-error {{RISC-V type '__rvv_int8mf8_t' requires the 'zve64x' extension}} */
+
+  (void)i8mf8; /* expected-error {{RISC-V type '__rvv_int8mf8_t' requires the 'zve64x' extension}} */
+
+  return i8mf8; /* expected-error {{RISC-V type '__rvv_int8mf8_t' requires the 'zve64x' extension}} */
+}
+
+__rvv_int16mf4_t foo16() { /* expected-error {{RISC-V type '__rvv_int16mf4_t' requires the 'zve64x' extension}} */
+  __rvv_int16mf4_t i16mf4; /* expected-error {{RISC-V type '__rvv_int16mf4_t' requires the 'zve64x' extension}} */
+
+  (void)i16mf4; /* expected-error {{RISC-V type '__rvv_int16mf4_t' requires the 'zve64x' extension}} */
+
+  return i16mf4; /* expected-error {{RISC-V type '__rvv_int16mf4_t' requires the 'zve64x' extension}} */
+}
+
+__rvv_int32mf2_t foo32() { /* expected-error {{RISC-V type '__rvv_int32mf2_t' requires the 'zve64x' extension}} */
+  __rvv_int32mf2_t i32mf2; /* expected-error {{RISC-V type '__rvv_int32mf2_t' requires the 'zve64x' extension}} */
+
+  (void)i32mf2; /* expected-error {{RISC-V type '__rvv_int32mf2_t' requires the 'zve64x' extension}} */
+
+  return i32mf2; /* expected-error {{RISC-V type '__rvv_int32mf2_t' requires the 'zve64x' extension}} */
+}
+
+__rvv_int64m1_t foo64() { /* expected-error {{RISC-V type '__rvv_int64m1_t' requires the 'zve64x' extension}} */
+  __rvv_int64m1_t i64m1; /* expected-error {{RISC-V type '__rvv_int64m1_t' requires the 'zve64x' extension}} */
+
+  (void)i64m1; /* expected-error {{RISC-V type '__rvv_int64m1_t' requires the 'zve64x' extension}} */
+
+  return i64m1; /* expected-error {{RISC-V type '__rvv_int64m1_t' requires the 'zve64x' extension}} */
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulhu.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulhu.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulhu.c
@@ -6,24 +6,6 @@
 
 #include 
 
-// CHECK-RV64-LABEL: @test_vmulhu_vv_u8mf8(
-// CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmulhu.nxv1i8.nxv1i8.i64( poison,  [[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])
-// CHECK-RV64-NEXT:ret  [[TMP0]]
-//
-vuint8mf8_t test_vmulhu_vv_u8mf8(vuint8mf8_t op1, vuint8mf8_t op2, size_t vl) {
-  return __riscv_vmulhu_vv_u8mf8(op1, op2, vl);
-}
-
-// CHECK-RV64-LABEL: @test_vmulhu_vx_u8mf8(
-// CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmulhu.nxv1i8.i8.i64( poison,  [[OP1:%.*]], i8 [[OP2:%.*]], i64 [[VL:%.*]])
-// CHECK-RV64-NEXT:ret  [[TMP0]]
-//
-vuint8mf8_t test_vmulhu_vx_u8mf8(vuint8mf8_t op1, uint8_t op2, size_t vl) {
-  return __riscv_vmulhu_vx_u8mf8(op1, op2, vl);
-}
-
 // CHECK-RV64-LABEL: @test_vmulhu_vv_u8mf4(
 // CHECK-RV64-NEXT:  entry:
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vmulhu.nxv2i8.nxv2i8.i64( poison,  [[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])
@@ -132,24 +114,6 @@
   return __riscv_vmulhu_vx_u8m8(op1, op2, vl);
 }
 
-// CHECK-RV64-LABEL: @test_vmulhu_vv_u16mf4(
-// CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:  

[PATCH] D155413: [NFC] Add `push_back` to `llvm::Function`

2023-07-16 Thread Evan Wilde via Phabricator via cfe-commits
etcwilde updated this revision to Diff 540850.
etcwilde added a comment.

Fixing `push_back` formatting.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155413/new/

https://reviews.llvm.org/D155413

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl05.rst
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
  llvm/examples/Kaleidoscope/Chapter5/toy.cpp
  llvm/examples/Kaleidoscope/Chapter6/toy.cpp
  llvm/examples/Kaleidoscope/Chapter7/toy.cpp
  llvm/examples/Kaleidoscope/Chapter8/toy.cpp
  llvm/examples/Kaleidoscope/Chapter9/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp
  llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
  llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
  llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
  llvm/include/llvm/IR/Function.h

Index: llvm/include/llvm/IR/Function.h
===
--- llvm/include/llvm/IR/Function.h
+++ llvm/include/llvm/IR/Function.h
@@ -693,6 +693,9 @@
 return BasicBlocks.insert(Position, BB);
   }
 
+  /// append \p BB to the end of the function
+  void push_back(BasicBlock *BB) { return BasicBlocks.push_back(BB); }
+
   /// Transfer all blocks from \p FromF to this function at \p ToIt.
   void splice(Function::iterator ToIt, Function *FromF) {
 splice(ToIt, FromF, FromF->begin(), FromF->end());
Index: llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
+++ llvm/examples/Kaleidoscope/MCJIT/lazy/toy.cpp
@@ -1025,7 +1025,7 @@
   ThenBB = Builder.GetInsertBlock();
 
   // Emit else block.
-  TheFunction->insert(TheFunction->end(), ElseBB);
+  TheFunction->push_back(ElseBB);
   Builder.SetInsertPoint(ElseBB);
 
   Value *ElseV = Else->Codegen();
@@ -1036,7 +1036,7 @@
   ElseBB = Builder.GetInsertBlock();
 
   // Emit merge block.
-  TheFunction->insert(TheFunction->end(), MergeBB);
+  TheFunction->push_back(MergeBB);
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
 
Index: llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
+++ llvm/examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp
@@ -745,7 +745,7 @@
   ThenBB = Builder.GetInsertBlock();
   
   // Emit else block.
-  TheFunction->insert(TheFunction->end(), ElseBB);
+  TheFunction->push_back(ElseBB);
   Builder.SetInsertPoint(ElseBB);
   
   Value *ElseV = Else->Codegen();
@@ -756,7 +756,7 @@
   ElseBB = Builder.GetInsertBlock();
   
   // Emit merge block.
-  TheFunction->insert(TheFunction->end(), MergeBB);
+  TheFunction->push_back(MergeBB);
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
 
Index: llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
+++ llvm/examples/Kaleidoscope/MCJIT/initial/toy.cpp
@@ -985,7 +985,7 @@
   ThenBB = Builder.GetInsertBlock();
 
   // Emit else block.
-  TheFunction->insert(TheFunction->end(), ElseBB);
+  TheFunction->push_back(ElseBB);
   Builder.SetInsertPoint(ElseBB);
 
   Value *ElseV = Else->Codegen();
@@ -996,7 +996,7 @@
   ElseBB = Builder.GetInsertBlock();
 
   // Emit merge block.
-  TheFunction->insert(TheFunction->end(), MergeBB);
+  TheFunction->push_back(MergeBB);
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
 
Index: llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
+++ llvm/examples/Kaleidoscope/MCJIT/complete/toy.cpp
@@ -1205,7 +1205,7 @@
   ThenBB = Builder.GetInsertBlock();
 
   // Emit else block.
-  TheFunction->insert(TheFunction->end(), ElseBB);
+  TheFunction->push_back(ElseBB);
   Builder.SetInsertPoint(ElseBB);
 
   Value *ElseV = Else->Codegen();
@@ -1216,7 +1216,7 @@
   ElseBB = Builder.GetInsertBlock();
 
   // Emit merge block.
-  TheFunction->insert(TheFunction->end(), MergeBB);
+  TheFunction->push_back(MergeBB);
   Builder.SetInsertPoint(MergeBB);
   PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, "iftmp");
 
Index: llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
===
--- llvm/examples/Kaleidoscope/MCJIT/cached/toy.cpp
+++ llvm/examp

[PATCH] D155416: [Clang][RISCV] Improve diagnostic message for full multiply intrinsics

2023-07-16 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: aaron.ballman, craig.topper.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, MaskRay.
Herald added a project: clang.

The full multiply intrinsics are not included for EEW=64 in Zve64*.
They require the V extension to be enabled.

This commit improves diagnostic message from

  :4:10: error: call to undeclared function '__riscv_vsmul_vv_i64m1';
  4 |   return __riscv_vsmul_vv_i64m1(op1, op2, __RISCV_VXRM_RNU, vl);

to

  test.c:5:10: error: builtin requires: v
  5 |   return __riscv_vsmul_vv_i64m1(op1, op2, __RISCV_VXRM_RNU, vl);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155416

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/Sema/riscv-vector-v-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -655,7 +655,6 @@
 for (auto RequiredFeature : RequiredFeatures) {
   RVVRequire RequireExt = StringSwitch(RequiredFeature)
   .Case("RV64", RVV_REQ_RV64)
-  .Case("FullMultiply", RVV_REQ_FullMultiply)
   .Case("Xsfvcp", RVV_REQ_Xsfvcp)
   .Default(RVV_REQ_None);
   assert(RequireExt != RVV_REQ_None && "Unrecognized required feature?");
Index: clang/test/Sema/riscv-vector-v-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-v-check.c
@@ -0,0 +1,197 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve64x \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+#include 
+
+vint64m1_t test_vsmul_vv_i64m1(vint64m1_t op1, vint64m1_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m1(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m1_t test_vsmul_vx_i64m1(vint64m1_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m1(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m2_t test_vsmul_vv_i64m2(vint64m2_t op1, vint64m2_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m2(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m2_t test_vsmul_vx_i64m2(vint64m2_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m2(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m4_t test_vsmul_vv_i64m4(vint64m4_t op1, vint64m4_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m4(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m4_t test_vsmul_vx_i64m4(vint64m4_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m4(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m8_t test_vsmul_vv_i64m8(vint64m8_t op1, vint64m8_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m8(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m8_t test_vsmul_vx_i64m8(vint64m8_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m8(op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m1_t test_vsmul_vv_i64m1_m(vbool64_t mask, vint64m1_t op1, vint64m1_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m1_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m1_t test_vsmul_vx_i64m1_m(vbool64_t mask, vint64m1_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m1_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m2_t test_vsmul_vv_i64m2_m(vbool32_t mask, vint64m2_t op1, vint64m2_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m2_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m2_t test_vsmul_vx_i64m2_m(vbool32_t mask, vint64m2_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m2_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m4_t test_vsmul_vv_i64m4_m(vbool16_t mask, vint64m4_t op1, vint64m4_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m4_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m4_t test_vsmul_vx_i64m4_m

[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

Just few nits (column numbers in test, missing doxygen comment, ...).
Please fix those before committing.

Except that, looking good to me.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:16-25
+AST_MATCHER(SwitchStmt, hasDefaultCase) {
+  const SwitchCase *Case = Node.getSwitchCaseList();
+  while (Case) {
+if (DefaultStmt::classof(Case))
+  return true;
+
+Case = Case->getNextSwitchCase();

Put this into anonymous namespace to avoid ODR issues



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp:40-41
+  const auto *Switch = Result.Nodes.getNodeAs("switch");
+  if (!Switch)
+return;
+

should never happend



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h:18
+
+class SwitchMissingDefaultCaseCheck : public ClangTidyCheck {
+public:

Missing class doxygen comment.
Check other classes, should be something like:

```
/// Ensures that switch statements without default cases are flagged, focuses 
only
/// on covering cases with non-enums where the compiler may not issue warnings.
///
/// For the user-facing documentation see:
/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/switch-missing-default-case.html

```



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp:9
+  int I1 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value 
without default case may not cover all cases 
[bugprone-switch-missing-default-case]
+  switch (I1) {





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp:16
+  MyInt I2 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value 
without default case may not cover all cases 
[bugprone-switch-missing-default-case]
+  switch (I2) {





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp:23
+  int getValue(void);
+  // CHECK-MESSAGES: [[@LINE+1]]:11: warning: switching on non-enum value 
without default case may not cover all cases 
[bugprone-switch-missing-default-case]
+  switch (getValue()) {




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

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


[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 540857.
xgupta marked 6 inline comments as done.
xgupta added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
@@ -0,0 +1,80 @@
+// RUN: %check_clang_tidy %s bugprone-switch-missing-default-case %t -- -- -fno-delayed-template-parsing
+
+typedef int MyInt;
+enum EnumType { eE2 };
+typedef EnumType MyEnum;
+
+void positive() {
+  int I1 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I1) {
+  case 0:
+break;
+  }
+
+  MyInt I2 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I2) {
+  case 0:
+break;
+  }
+
+  int getValue(void);
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (getValue()) {
+  case 0:
+break;
+  }
+}
+
+void negative() {
+  enum E { eE1 };
+  E E1 = eE1;
+  switch (E1) { // no-warning
+  case eE1:
+break;
+  }
+
+  MyEnum E2 = eE2;
+  switch (E2) { // no-warning
+  case eE2:
+break;
+  }
+
+  int I1 = 0;
+  switch (I1) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  MyInt I2 = 0;
+  switch (I2) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  int getValue(void);
+  switch (getValue()) { // no-warning
+  case 0:
+break;
+default:
+break;
+  }
+}
+
+template
+void testTemplate(T Value) {
+  switch (Value) {
+case 0:
+  break;
+  }
+}
+
+void exampleUsage() {
+  testTemplate(5);
+  testTemplate(EnumType::eE2);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -92,6 +92,7 @@
`bugprone-forwarding-reference-overload `_,
`bugprone-implicit-widening-of-multiplication-result `_, "Yes"
`bugprone-inaccurate-erase `_, "Yes"
+   `bugprone-switch-missing-default-case `_,
`bugprone-incorrect-roundings `_,
`bugprone-infinite-loop `_,
`bugprone-integer-division `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
@@ -0,0 +1,56 @@
+.. title:: clang-tidy - bugprone-switch-missing-default-case
+
+bugprone-switch-missing-default-case
+
+
+Ensures that switch statements without default cases are flagged, focuses only
+on covering cases with non-enums where the compiler may not issue warnings.
+
+Switch statements without a default case can lead to unexpected
+behavior and incomplete handling of all possible cases. When a switch statement
+lacks a default case, if a value is encountered that does not match any of the
+specified cases, the program will continue execution without any defined
+behavior or handling.
+
+This check helps identify switch statements that are missing a default case,
+allowing developers to ensure that all possible cases are handled properly.
+Adding a default case allows for graceful handling of unexpected or unmatched
+values, reducing the risk of program errors and unexpected behavior.
+
+Example:
+
+.. code-block:: c++
+
+  // Example 1:
+  // warning: switching on non-enum value without default case may not cover all cases
+  switch (i) {
+  case 0:
+break;
+  }
+
+  // Example 2:
+  enum E { eE1 };
+  E e = eE1;
+  switch (e) { // no-warning
+  case eE1:
+break;
+  }
+
+  // Example 3:
+  int i = 0;
+  switch (i) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+.. note::
+   Enum types are already covered by compiler warnings (comes under -Wswitch)
+   when a switch statement does not handle all enum values. This check f

[clang-tools-extra] 42179bb - [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2023-07-17T10:40:11+05:30
New Revision: 42179bbf6bcc9f90256b443c30f5e99f862bc2f6

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

LOG: [clang-tidy] Add check for possibly incomplete switch statements

While clang warns about a possibly incomplete switch statement when switching 
over an enum variable and failing to cover all enum values (either explicitly 
or with a default case), no such warning is emitted if a plain integer variable 
is used as switch variable.

Add a clang-tidy check to diagnose these scenarios.

No fixit hint is provided since there are multiple possible solutions.

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

Added: 
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h

clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index e62e536555c29c..7509e94950e10e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -65,6 +65,7 @@
 #include "SuspiciousSemicolonCheck.h"
 #include "SuspiciousStringCompareCheck.h"
 #include "SwappedArgumentsCheck.h"
+#include "SwitchMissingDefaultCaseCheck.h"
 #include "TerminatingContinueCheck.h"
 #include "ThrowKeywordMissingCheck.h"
 #include "TooSmallLoopVariableCheck.h"
@@ -116,6 +117,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-implicit-widening-of-multiplication-result");
 CheckFactories.registerCheck(
 "bugprone-inaccurate-erase");
+CheckFactories.registerCheck(
+"bugprone-switch-missing-default-case");
 CheckFactories.registerCheck(
 "bugprone-incorrect-roundings");
 CheckFactories.registerCheck("bugprone-infinite-loop");

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 363d1a85b0ae51..8bd892eeb41ecd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_library(clangTidyBugproneModule
   ForwardingReferenceOverloadCheck.cpp
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
+  SwitchMissingDefaultCaseCheck.cpp
   IncorrectRoundingsCheck.cpp
   InfiniteLoopCheck.cpp
   IntegerDivisionCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
new file mode 100644
index 00..d1d50fe26b29e1
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
@@ -0,0 +1,47 @@
+//===--- SwitchMissingDefaultCaseCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "SwitchMissingDefaultCaseCheck.h"
+#include "clang/AST/ASTContext.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER(SwitchStmt, hasDefaultCase) {
+  const SwitchCase *Case = Node.getSwitchCaseList();
+  while (Case) {
+if (DefaultStmt::classof(Case))
+  return true;
+
+Case = Case->getNextSwitchCase();
+  }
+  return false;
+}
+} // namespace
+
+void SwitchMissingDefaultCaseCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  switchStmt(hasCondition(expr(unless(isInstantiationDependent()),
+   hasType(qualType(hasCanonicalType(
+   unless(hasDeclaration(enumDecl(,
+ unless(hasDefaultCase()))
+  .bind("switch"),
+  this);
+}
+
+void SwitchMissingDefaultCaseCheck::check(
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  const auto *Switch = Result.Nodes.getNodeAs("switch");
+
+  diag(Switch->getSwitchLoc(), "switching on non-enum value without "
+   "default case may not cover all cases");
+}
+} // namespace cla

[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG42179bbf6bcc: [clang-tidy] Add check for possibly incomplete 
switch statements (authored by shivam-amd).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp
@@ -0,0 +1,80 @@
+// RUN: %check_clang_tidy %s bugprone-switch-missing-default-case %t -- -- -fno-delayed-template-parsing
+
+typedef int MyInt;
+enum EnumType { eE2 };
+typedef EnumType MyEnum;
+
+void positive() {
+  int I1 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I1) {
+  case 0:
+break;
+  }
+
+  MyInt I2 = 0;
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (I2) {
+  case 0:
+break;
+  }
+
+  int getValue(void);
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
+  switch (getValue()) {
+  case 0:
+break;
+  }
+}
+
+void negative() {
+  enum E { eE1 };
+  E E1 = eE1;
+  switch (E1) { // no-warning
+  case eE1:
+break;
+  }
+
+  MyEnum E2 = eE2;
+  switch (E2) { // no-warning
+  case eE2:
+break;
+  }
+
+  int I1 = 0;
+  switch (I1) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  MyInt I2 = 0;
+  switch (I2) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+  int getValue(void);
+  switch (getValue()) { // no-warning
+  case 0:
+break;
+default:
+break;
+  }
+}
+
+template
+void testTemplate(T Value) {
+  switch (Value) {
+case 0:
+  break;
+  }
+}
+
+void exampleUsage() {
+  testTemplate(5);
+  testTemplate(EnumType::eE2);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -92,6 +92,7 @@
`bugprone-forwarding-reference-overload `_,
`bugprone-implicit-widening-of-multiplication-result `_, "Yes"
`bugprone-inaccurate-erase `_, "Yes"
+   `bugprone-switch-missing-default-case `_,
`bugprone-incorrect-roundings `_,
`bugprone-infinite-loop `_,
`bugprone-integer-division `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
@@ -0,0 +1,56 @@
+.. title:: clang-tidy - bugprone-switch-missing-default-case
+
+bugprone-switch-missing-default-case
+
+
+Ensures that switch statements without default cases are flagged, focuses only
+on covering cases with non-enums where the compiler may not issue warnings.
+
+Switch statements without a default case can lead to unexpected
+behavior and incomplete handling of all possible cases. When a switch statement
+lacks a default case, if a value is encountered that does not match any of the
+specified cases, the program will continue execution without any defined
+behavior or handling.
+
+This check helps identify switch statements that are missing a default case,
+allowing developers to ensure that all possible cases are handled properly.
+Adding a default case allows for graceful handling of unexpected or unmatched
+values, reducing the risk of program errors and unexpected behavior.
+
+Example:
+
+.. code-block:: c++
+
+  // Example 1:
+  // warning: switching on non-enum value without default case may not cover all cases
+  switch (i) {
+  case 0:
+break;
+  }
+
+  // Example 2:
+  enum E { eE1 };
+  E e = eE1;
+  switch (e) { // no-warning
+  case eE1:
+break;
+  }
+
+  // Example 3:
+  int i = 0;
+  switch (i) { // no-warning
+  case 0:
+break;
+  default:
+break;
+  }
+
+.. note::
+   Enum types are already

[PATCH] D4784: [clang-tidy] Add check for possibly incomplete switch statements

2023-07-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D4784#4504690 , @PiotrZSL wrote:

> Just few nits (column numbers in test, missing doxygen comment, ...).
> Please fix those before committing.
>
> Except that, looking good to me.

Thanks for this nice code review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4784/new/

https://reviews.llvm.org/D4784

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


[PATCH] D155380: [clang] Fix delayed template parsing

2023-07-16 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 540861.
sepavloff added a comment.

Fix clang-format errors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155380/new/

https://reviews.llvm.org/D155380

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/PCH/late-parsed-instantiations.cpp


Index: clang/test/PCH/late-parsed-instantiations.cpp
===
--- clang/test/PCH/late-parsed-instantiations.cpp
+++ clang/test/PCH/late-parsed-instantiations.cpp
@@ -4,7 +4,9 @@
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch 
-fpch-instantiate-templates %s -o %t.pch -verify
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -include-pch %t.pch 
%s -verify
 
-// XFAIL: target={{.*}}-aix{{.*}}
+// Run this test for i686 as this is the target that modifies default FP 
options.
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing 
-std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing 
-std=c++14 -include-pch %t.pch %s -verify
 
 #ifndef HEADER_INCLUDED
 
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -1744,6 +1744,7 @@
 
   // Parsing should occur with empty FP pragma stack and FP options used in the
   // point of the template definition.
+  Sema::FpPragmaStackSaveRAII SavedStack(Actions);
   Actions.resetFPOptions(LPT.FPO);
 
   assert(!LPT.Toks.empty() && "Empty body!");
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -710,6 +710,16 @@
 return result;
   }
 
+  class FpPragmaStackSaveRAII {
+  public:
+FpPragmaStackSaveRAII(Sema &S) : S(S), SavedStack(S.FpPragmaStack) {}
+~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); }
+
+  private:
+Sema &S;
+PragmaStack SavedStack;
+  };
+
   void resetFPOptions(FPOptions FPO) {
 CurFPFeatures = FPO;
 FpPragmaStack.Stack.clear();


Index: clang/test/PCH/late-parsed-instantiations.cpp
===
--- clang/test/PCH/late-parsed-instantiations.cpp
+++ clang/test/PCH/late-parsed-instantiations.cpp
@@ -4,7 +4,9 @@
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify
 // RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -include-pch %t.pch %s -verify
 
-// XFAIL: target={{.*}}-aix{{.*}}
+// Run this test for i686 as this is the target that modifies default FP options.
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing -std=c++14 -emit-pch -fpch-instantiate-templates %s -o %t.pch -verify
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fdelayed-template-parsing -std=c++14 -include-pch %t.pch %s -verify
 
 #ifndef HEADER_INCLUDED
 
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -1744,6 +1744,7 @@
 
   // Parsing should occur with empty FP pragma stack and FP options used in the
   // point of the template definition.
+  Sema::FpPragmaStackSaveRAII SavedStack(Actions);
   Actions.resetFPOptions(LPT.FPO);
 
   assert(!LPT.Toks.empty() && "Empty body!");
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -710,6 +710,16 @@
 return result;
   }
 
+  class FpPragmaStackSaveRAII {
+  public:
+FpPragmaStackSaveRAII(Sema &S) : S(S), SavedStack(S.FpPragmaStack) {}
+~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); }
+
+  private:
+Sema &S;
+PragmaStack SavedStack;
+  };
+
   void resetFPOptions(FPOptions FPO) {
 CurFPFeatures = FPO;
 FpPragmaStack.Stack.clear();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d7b4594 - [NFC][clang] Fix format in UnsafeBufferUsage.cpp

2023-07-16 Thread Evan Wilde via cfe-commits

Author: Evan Wilde
Date: 2023-07-16T22:45:29-07:00
New Revision: d7b45945fbb7c4ac27c456dd7c2ff8bb40fcf8f8

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

LOG: [NFC][clang] Fix format in UnsafeBufferUsage.cpp

There were two whitespaces on an otherwise empty that were causing the
bots to fail due to formatting issues. Deleting extra whitespace now.

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index c8c1452a8f5543..142c56beddafea 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1809,7 +1809,7 @@ createOverloadsForFixedParams(unsigned ParmIdx, StringRef 
NewTyText,
   // FIXME: need to make this conflict checking better:
   if (hasConflictingOverload(FD))
 return std::nullopt;
-  
+
   const SourceManager &SM = Ctx.getSourceManager();
   const LangOptions &LangOpts = Ctx.getLangOpts();
   // FIXME Respect indentation of the original code.



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


[PATCH] D155413: [NFC] Add `push_back` to `llvm::Function`

2023-07-16 Thread Evan Wilde via Phabricator via cfe-commits
etcwilde added a comment.

Failure was a formatting issue in `clang/lib/Analysis/UnsafeBufferUsage.cpp`.
I just fixed that in d7b45945fbb7c4ac27c456dd7c2ff8bb40fcf8f8 
.
I don't know how to re-trigger the tests though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155413/new/

https://reviews.llvm.org/D155413

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


[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-07-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14930
   LookupQualifiedName(R, Record->getDecl());
-  R.suppressDiagnostics();
+  R.suppressAccessDiagnostics();
 

shafik wrote:
> rsmith wrote:
> > shafik wrote:
> > > I was a bit conservative where I changed this but maybe we should do this 
> > > everywhere.
> > Most of the other calls in this file all look wrong. 
> > `DiagnoseTwoPhaseLookup` and `BuildRecoveryCallExpr` are doing error 
> > recovery and I think it's appropriate for them to suppress all diagnostics, 
> > but the rest are doing standard-mandated searches, and so should diagnose 
> > lookup ambiguity.
> So it looks like `BuildOverloadedArrowExpr` catches the ambiguous lookup when 
> calling `CandidateSet.BestViableFunction(...)` while 
> `BuildCallToObjectOfClassType(...)` does not. So if I change the 
> `suppressDiagnostics()` call in `BuildOverloadedArrowExpr` we get double 
> diagnostic. I am not seeing why we have the inconsistency here.  
Correction, there are not duplicate diagnostics, one is for ambiguous overload 
and the other is for ambiguous name lookup. Maybe we should suppress the 
ambiguous overload if we have an ambiguous name lookup though.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155387/new/

https://reviews.llvm.org/D155387

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


[PATCH] D155419: [Clang][CMake][WIP] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED

2023-07-16 Thread Amir Ayupov via Phabricator via cfe-commits
Amir created this revision.
Herald added subscribers: wlei, ekilmer, wenlei.
Herald added a project: All.
Amir requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155419

Files:
  clang/CMakeLists.txt
  clang/utils/perf-training/CMakeLists.txt
  clang/utils/perf-training/lit.cfg
  clang/utils/perf-training/lit.site.cfg.in
  clang/utils/perf-training/perf-helper.py
  llvm/CMakeLists.txt
  llvm/cmake/modules/HandleLLVMOptions.cmake

Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1071,7 +1071,7 @@
 option(LLVM_ENABLE_IR_PGO "Build LLVM and tools with IR PGO instrumentation (deprecated)" Off)
 mark_as_advanced(LLVM_ENABLE_IR_PGO)
 
-set(LLVM_BUILD_INSTRUMENTED OFF CACHE STRING "Build LLVM and tools with PGO instrumentation. May be specified as IR or Frontend")
+set(LLVM_BUILD_INSTRUMENTED OFF CACHE STRING "Build LLVM and tools with PGO instrumentation. May be specified as IR, Frontend, CSIR, CSSPGO")
 set(LLVM_VP_COUNTERS_PER_SITE "1.5" CACHE STRING "Value profile counters to use per site for IR PGO with Clang")
 mark_as_advanced(LLVM_BUILD_INSTRUMENTED LLVM_VP_COUNTERS_PER_SITE)
 string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" uppercase_LLVM_BUILD_INSTRUMENTED)
@@ -1104,6 +1104,15 @@
 CMAKE_EXE_LINKER_FLAGS
 CMAKE_SHARED_LINKER_FLAGS)
 endif()
+  elseif(uppercase_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+append("-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-optimize-sibling-calls -fpseudo-probe-for-profiling"
+  CMAKE_CXX_FLAGS
+  CMAKE_C_FLAGS)
+if(NOT LINKER_IS_LLD_LINK)
+  append("-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-optimize-sibling-calls -fpseudo-probe-for-profiling"
+CMAKE_EXE_LINKER_FLAGS
+CMAKE_SHARED_LINKER_FLAGS)
+endif()
   else()
 append("-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\""
   CMAKE_CXX_FLAGS
@@ -1154,6 +1163,21 @@
   endif()
 endif()
 
+if(LLVM_SPROFDATA_FILE AND EXISTS ${LLVM_SPROFDATA_FILE})
+  if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
+append("-fpseudo-probe-for-profiling -fprofile-sample-use=\"${LLVM_SPROFDATA_FILE}\""
+  CMAKE_CXX_FLAGS
+  CMAKE_C_FLAGS)
+if(NOT LINKER_IS_LLD_LINK)
+  append("-fpseudo-probe-for-profiling -fprofile-sample-use=\"${LLVM_SPROFDATA_FILE}\""
+CMAKE_EXE_LINKER_FLAGS
+CMAKE_SHARED_LINKER_FLAGS)
+endif()
+  else()
+message(FATAL_ERROR "LLVM_SPROFDATA_FILE can only be specified when compiling with clang")
+  endif()
+endif()
+
 option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation" Off)
 mark_as_advanced(LLVM_BUILD_INSTRUMENTED_COVERAGE)
 append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate=\"${LLVM_PROFILE_FILE_PATTERN}\" -fcoverage-mapping"
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -849,6 +849,9 @@
 set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
   "Profiling data file to use when compiling in order to improve runtime performance.")
 
+set(LLVM_SPROFDATA_FILE "" CACHE FILEPATH
+  "Sampling profiling data file to use when compiling in order to improve runtime performance.")
+
 if(LLVM_INCLUDE_TESTS)
   # Lit test suite requires at least python 3.6
   set(LLVM_MINIMUM_PYTHON_VERSION 3.6)
Index: clang/utils/perf-training/perf-helper.py
===
--- clang/utils/perf-training/perf-helper.py
+++ clang/utils/perf-training/perf-helper.py
@@ -69,10 +69,16 @@
 
 def perf(args):
 parser = argparse.ArgumentParser(
-prog="perf-helper perf", description="perf wrapper for BOLT profile collection"
+prog="perf-helper perf",
+description="perf wrapper for BOLT/CSSPGO profile collection"
 )
 parser.add_argument(
-"--lbr", required=False, action="store_true", help="Use perf with branch stacks"
+"--lbr", required=False, action="store_true",
+help="Use perf with branch stacks"
+)
+parser.add_argument(
+"--call-graph", required=False, action="store_true",
+help="Collect call graph"
 )
 parser.add_argument("cmd", nargs="*", help="")
 
@@ -97,6 +103,8 @@
 )
 if opts.lbr:
 perf_args += ["--branch-filter=any,u"]
+if opts.call_graph:
+perf_args += ["--call-graph=fp"]
 perf_args.extend(cmd)
 
 start_time = time.time()
@@ -132,6 +140,26 @@
 return 0
 
 
+def perf2prof(args):
+parser = argparse.ArgumentParser(
+prog="perf-helper perf2prof",
+description="perf to CSSPGO prof conversion wrapper",
+)
+parser.add_argument("profgen", help="Path t

[PATCH] D155387: [Clang] Fix member lookup so that we don't ignore ambiguous lookups in some cases

2023-07-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 540866.
shafik added a comment.

- Adjusted more place to use `suppressAccessDiagnostics`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155387/new/

https://reviews.llvm.org/D155387

Files:
  clang/include/clang/Sema/Lookup.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/class.derived/class.member.lookup/gh22413.cpp
  clang/test/CXX/class.derived/class.member.lookup/p11.cpp
  clang/test/SemaCXX/arrow-operator.cpp

Index: clang/test/SemaCXX/arrow-operator.cpp
===
--- clang/test/SemaCXX/arrow-operator.cpp
+++ clang/test/SemaCXX/arrow-operator.cpp
@@ -5,10 +5,12 @@
 
 struct A {
   T* operator->(); // expected-note{{candidate function}}
+   // expected-note@-1 {{member found by ambiguous name lookup}}
 };
 
 struct B {
   T* operator->(); // expected-note{{candidate function}}
+   // expected-note@-1 {{member found by ambiguous name lookup}}
 };
 
 struct C : A, B {
@@ -20,6 +22,7 @@
 
 void f(C &c, D& d, E& e) {
   c->f(); // expected-error{{use of overloaded operator '->' is ambiguous}}
+  // expected-error@-1 {{member 'operator->' found in multiple base classes of different types}}
   d->f();
   e->f(); // expected-error{{incomplete definition of type}}
 }
Index: clang/test/CXX/class.derived/class.member.lookup/p11.cpp
===
--- /dev/null
+++ clang/test/CXX/class.derived/class.member.lookup/p11.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct B1 {
+  void f();
+  static void f(int);
+  int i; // expected-note 2{{member found by ambiguous name lookup}}
+};
+struct B2 {
+  void f(double);
+};
+struct I1: B1 { };
+struct I2: B1 { };
+
+struct D: I1, I2, B2 {
+  using B1::f;
+  using B2::f;
+  void g() {
+f(); // expected-error {{ambiguous conversion from derived class 'D' to base class 'B1'}}
+f(0); // ok
+f(0.0); // ok
+// FIXME next line should be well-formed
+int B1::* mpB1 = &D::i; // expected-error {{non-static member 'i' found in multiple base-class subobjects of type 'B1'}}
+int D::* mpD = &D::i; // expected-error {{non-static member 'i' found in multiple base-class subobjects of type 'B1'}}
+  }
+};
Index: clang/test/CXX/class.derived/class.member.lookup/gh22413.cpp
===
--- /dev/null
+++ clang/test/CXX/class.derived/class.member.lookup/gh22413.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct A {
+  void operator()(int); // expected-note {{member found by ambiguous name lookup}}
+  void f(int); // expected-note {{member found by ambiguous name lookup}}
+};
+struct B {
+  void operator()(); // expected-note {{member found by ambiguous name lookup}}
+  void f() {} // expected-note {{member found by ambiguous name lookup}}
+};
+
+struct C : A, B {};
+
+int f() {
+C c;
+c(); // expected-error {{member 'operator()' found in multiple base classes of different types}}
+c.f(10); //expected-error {{member 'f' found in multiple base classes of different types}}
+return 0;
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -593,7 +593,7 @@
   // postfix-expression and does not name a class template, the name
   // found in the class of the object expression is used, otherwise
   FoundOuter.clear();
-} else if (!Found.isSuppressingDiagnostics()) {
+} else if (!Found.isSuppressingAmbiguousDiagnostics()) {
   //   - if the name found is a class template, it must refer to the same
   // entity as the one found in the class of the object expression,
   // otherwise the program is ill-formed.
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -949,7 +949,7 @@
 LookupResult Members(S, NotEqOp, OpLoc,
  Sema::LookupNameKind::LookupMemberName);
 S.LookupQualifiedName(Members, RHSRec->getDecl());
-Members.suppressDiagnostics();
+Members.suppressAccessDiagnostics();
 for (NamedDecl *Op : Members)
   if (FunctionsCorrespond(S.Context, EqFD, Op->getAsFunction()))
 return false;
@@ -960,7 +960,7 @@
   Sema::LookupNameKind::LookupOperatorName);
   S.LookupName(NonMembers,
S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressDiagnostics();
+  NonMembers.suppressAccessDiagnostics();
   for (NamedDecl *Op : NonMembers) {
 auto *FD = Op->getAsFunction();
 if(auto* UD = dyn_cast(Op))
@@ -7941,7 +7941,7 @@
 
 LookupResult Operators(*this, OpName, OpLoc, LookupOrdinaryName);
 LookupQual

[PATCH] D155421: [clangd] Add BlockEnd comments for control flow statements

2023-07-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

These mark the end of CompoundStmts bodies of if/while/for/switch.
To identify which statement is being ended, we include abbreviated
text of the condition/loop variable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155421

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1757,6 +1759,218 @@
   ExpectedHint{" // enum class E2", "E2"});
 }
 
+TEST(BlockEndHints, If) {
+  assertBlockEndHints(
+  R"cpp(
+void foo(bool cond) {
+   if (cond)
+  ;
+
+   if (cond) {
+   $simple[[}]]
+
+   if (cond) {
+   } else {
+   $ifelse[[}]]
+
+   if (cond) {
+   } else if (!cond) {
+   $elseif[[}]]
+
+   if (cond) {
+   } else {
+ if (!cond) {
+ $inner[[}]]
+   $outer[[}]]
+
+   if (auto X = cond) {
+   $init[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // if cond", "simple"},
+  ExpectedHint{" // if cond", "ifelse"}, ExpectedHint{" // if", "elseif"},
+  ExpectedHint{" // if !cond", "inner"},
+  ExpectedHint{" // if cond", "outer"}, ExpectedHint{" // if X", "init"});
+}
+
+TEST(BlockEndHints, Loops) {
+  assertBlockEndHints(
+  R"cpp(
+void foo() {
+   while (true)
+  ;
+
+   while (true) {
+   $while[[}]]
+
+   do {
+   } while (true);
+
+   for (;true;) {
+   $forcond[[}]]
+
+   for (int I = 0; I < 10; ++I) {
+   $forvar[[}]]
+
+   int Vs[] = {1,2,3};
+   for (auto V : Vs) {
+   $foreach[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // while true", "while"},
+  ExpectedHint{" // for true", "forcond"},
+  ExpectedHint{" // for I", "forvar"},
+  ExpectedHint{" // for V", "foreach"});
+}
+
+TEST(BlockEndHints, Switch) {
+  assertBlockEndHints(
+  R"cpp(
+void foo(int I) {
+  switch (I) {
+case 0: break;
+  $switch[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // switch I", "switch"});
+}
+
+TEST(BlockEndHints, PrintLiterals) {
+  assertBlockEndHints(
+  R"cpp(
+void foo() {
+  while ("foo") {
+  $string[[}]]
+
+  while ("foo but this time it is very long") {
+  $string_long[[}]]
+
+  while (true) {
+  $boolean[[}]]
+
+  while (1) {
+  $integer[[}]]
+
+  while (1.5) {
+  $float[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // while \"foo\"", "string"},
+  ExpectedHint{" // while \"...\"", "string_long"},
+  ExpectedHint{" // while true", "boolean"},
+  ExpectedHint{" // while 1", "integer"},
+  ExpectedHint{" // while 1.5", "float"});
+}
+
+TEST(BlockEndHints, PrintRefs) {
+  assertBlockEndHints(
+  R"cpp(
+namespace ns {
+  int Var;
+  int func();
+  struct S {
+int Field;
+int method() const;
+  }; // suppress
+} // suppress
+void foo() {
+  while (ns::Var) {
+  $var[[}]]
+
+  while (ns::func()) {
+  $func[[}]]
+
+  while (ns::S{}.Field) {
+  $field[[}]]
+
+  while (ns::S{}.method()) {
+  $method[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // while Var", "var"},
+  ExpectedHint{" // while func", "func"},
+  ExpectedHint{" // while Field", "field"},
+  ExpectedHint{" // while method", "method"});
+}
+
+TEST(BlockEndHints, PrintConversions) {
+  assertBlockEndHints(
+  R"cpp(
+struct S {
+  S(int);
+  S(int, int);
+  explicit operator bool();
+}; // suppress
+void foo(int I) {
+  while (float(I)) {
+  $convert_primitive[[}]]
+
+  while (S(I)) {
+  $convert_class[[}]]
+
+  while (S(I, I)) {
+  $construct_class[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // while float", "convert_primitive"},
+  ExpectedHint{" // while S", "convert_class"},
+  ExpectedHint{" // while S", "construct_class"});
+}
+
+TEST(BlockEndHints, PrintOperators) {
+  std::string AnnotatedCode = R"cpp(
+void foo(Integer I) {
+  while(++I){
+  $preinc[[}]]
+
+  while(I++){
+  $postinc[[}]]
+
+  while(+(I + I)){
+  $unary_complex[[}]]
+
+  while(I < 0){
+  $compare[[}]]
+
+  while((I + I) < I){
+  $lhs_complex[[}]]
+
+  while(I < (I + I)){
+  $rhs_com

[PATCH] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Wait, the whole point of this algorithm is that we have to do this whole 
complicated linear check against every label whose address is taken because we 
don't know where it's going.  If we have a list of all the possible labels that 
the `asm goto` might jump to, why are we building a map of all the labels and 
then filtering out the ones that aren't listed?  We should just be checking the 
listed destinations with the stricter triviality rule that indirect-goto uses.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155342/new/

https://reviews.llvm.org/D155342

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


[clang-tools-extra] feaf70b - [clang-tidy][NFC] Fix syntax in release notes

2023-07-16 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-07-17T06:20:17Z
New Revision: feaf70b3cd64d09566ec667ce95340056c358ca2

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

LOG: [clang-tidy][NFC] Fix syntax in release notes

Add missing : character to links in release notes
so they could shown properly.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3b3bf0ca55508e..820a76c66d9862 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -238,17 +238,17 @@ New check aliases
 
 - New alias :doc:`cppcoreguidelines-noexcept-destructor
   ` to
-  :doc`performance-noexcept-destructor
+  :doc:`performance-noexcept-destructor
   ` was added.
 
 - New alias :doc:`cppcoreguidelines-noexcept-move-operations
   ` to
-  :doc`performance-noexcept-move-constructor
+  :doc:`performance-noexcept-move-constructor
   ` was added.
 
 - New alias :doc:`cppcoreguidelines-noexcept-swap
   ` to
-  :doc`performance-noexcept-swap
+  :doc:`performance-noexcept-swap
   ` was added.
 
 - New alias :doc:`cppcoreguidelines-use-default-member-init



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


[PATCH] D155367: [clang][Interp] Implement __builtin_inf() etc.

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:119
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {

tbaeder wrote:
> cor3ntin wrote:
> > why does that return a bool? you could make it void, and get rid of the if 
> > statement
> No reason other than that all the evaluation functions (also in `Interp.h`) 
> return `bool`, even if they always succeed.
Yeah, I'm not a fan of returning something for no reason but i buy the 
consistency argument


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155367/new/

https://reviews.llvm.org/D155367

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


[PATCH] D155401: [clang][Interp] Implement __builtin_fmax

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155401/new/

https://reviews.llvm.org/D155401

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


[PATCH] D155400: [clang][Interp] Implement __builtin_fabs()

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155400/new/

https://reviews.llvm.org/D155400

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


[PATCH] D155371: [clang][Interp] Implement __builtin_isinf

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155371/new/

https://reviews.llvm.org/D155371

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


[PATCH] D155369: [clang][Interp] Implement __builtin_isnan()

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:166-168
+  // FIXME: We are not going through getParam() here, because the function
+  // doesn't have any parameters. Wait for a pattern to emerge and maybe
+  // refactor this into a different function that checks things are valid.

I would remove the fixme, given you already implemented all the floating point 
builtins


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155369/new/

https://reviews.llvm.org/D155369

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


[PATCH] D155374: [clang][Interp] Implement __builtin_isnormal

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155374/new/

https://reviews.llvm.org/D155374

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


[PATCH] D155075: [clang][dataflow] Add `DataflowEnvironment::createObject()`.

2023-07-16 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 540871.
mboehme added a comment.

Add comment for `createObjectInternal()`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155075/new/

https://reviews.llvm.org/D155075

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp

Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -208,62 +208,15 @@
 if (D.hasGlobalStorage())
   return;
 
-if (D.getType()->isReferenceType()) {
-  // If this is the holding variable for a `BindingDecl`, we may already
-  // have a storage location set up -- so check. (See also explanation below
-  // where we process the `BindingDecl`.)
-  if (Env.getStorageLocation(D) == nullptr) {
-const Expr *InitExpr = D.getInit();
-assert(InitExpr != nullptr);
-if (auto *InitExprLoc =
-Env.getStorageLocation(*InitExpr, SkipPast::Reference)) {
-  Env.setStorageLocation(D, *InitExprLoc);
-} else {
-  // Even though we have an initializer, we might not get an
-  // InitExprLoc, for example if the InitExpr is a CallExpr for which we
-  // don't have a function body. In this case, we just invent a storage
-  // location and value -- it's the best we can do.
-  StorageLocation &Loc =
-  Env.createStorageLocation(D.getType().getNonReferenceType());
-  Env.setStorageLocation(D, Loc);
-  if (Value *Val = Env.createValue(D.getType().getNonReferenceType()))
-Env.setValue(Loc, *Val);
-}
-  }
-} else {
-  // Not a reference type.
+// If this is the holding variable for a `BindingDecl`, we may already
+// have a storage location set up -- so check. (See also explanation below
+// where we process the `BindingDecl`.)
+if (D.getType()->isReferenceType() && Env.getStorageLocation(D) != nullptr)
+  return;
 
-  assert(Env.getStorageLocation(D) == nullptr);
-  StorageLocation &Loc = Env.createStorageLocation(D);
-  Env.setStorageLocation(D, Loc);
+assert(Env.getStorageLocation(D) == nullptr);
 
-  const Expr *InitExpr = D.getInit();
-  if (InitExpr == nullptr) {
-// No initializer expression - associate `Loc` with a new value.
-if (Value *Val = Env.createValue(D.getType()))
-  Env.setValue(Loc, *Val);
-return;
-  }
-
-  if (auto *InitExprVal = Env.getValueStrict(*InitExpr))
-Env.setValue(Loc, *InitExprVal);
-
-  if (Env.getValue(Loc) == nullptr) {
-// We arrive here in (the few) cases where an expression is
-// intentionally "uninterpreted". There are two ways to handle this
-// situation: propagate the status, so that uninterpreted initializers
-// result in uninterpreted variables, or provide a default value. We
-// choose the latter so that later refinements of the variable can be
-// used for reasoning about the surrounding code.
-//
-// FIXME. If and when we interpret all language cases, change this to
-// assert that `InitExpr` is interpreted, rather than supplying a
-// default value (assuming we don't update the environment API to return
-// references).
-if (Value *Val = Env.createValue(D.getType()))
-  Env.setValue(Loc, *Val);
-  }
-}
+Env.setStorageLocation(D, Env.createObject(D));
 
 // `DecompositionDecl` must be handled after we've interpreted the loc
 // itself, because the binding expression refers back to the
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -260,10 +260,8 @@
   for (const VarDecl *D : Vars) {
 if (getStorageLocation(*D) != nullptr)
   continue;
-auto &Loc = createStorageLocation(D->getType().getNonReferenceType());
-setStorageLocation(*D, Loc);
-if (auto *Val = createValue(D->getType().getNonReferenceType()))
-  setValue(Loc, *Val);
+
+setStorageLocation(*D, createObject(*D));
   }
 
   for (const FunctionDecl *FD : Funcs) {
@@ -296,16 +294,7 @@
 
 for (const auto *ParamDecl : FuncDecl->parameters()) {
   assert(ParamDecl != nullptr);
-  // References aren't objects, so the reference itself doesn't have a
-  // storage location. Instead, the storage location for a reference refers
-  // directly to an object of the referenced type -- so strip off any
-  // reference from the type.
- 

[PATCH] D155410: [clang][Interp] Fix comparing nan/inf floating point values

2023-07-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155410/new/

https://reviews.llvm.org/D155410

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