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

2023-07-18 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

This looks good can you wait for one of the others to accept too


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] D155539: [CUDA][HIP] Use the same default language std as C++

2023-07-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 541836.
yaxunl added a comment.

update release note


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

https://reviews.llvm.org/D155539

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/LangStandards.def
  clang/lib/Basic/LangStandards.cpp
  clang/test/CodeGenCUDA/long-double.cu
  clang/test/Driver/unknown-std.cpp
  clang/test/Preprocessor/lang-std.cpp

Index: clang/test/Preprocessor/lang-std.cpp
===
--- clang/test/Preprocessor/lang-std.cpp
+++ clang/test/Preprocessor/lang-std.cpp
@@ -1,12 +1,14 @@
-// UNSUPPORTED: target={{.*-(ps4|ps5)}}
 /// Test default standards.
-/// PS4/PS5 default to gnu++14.
+/// CUDA/HIP uses the same default standards as C++.
 
-// RUN: %clang_cc1 -dM -E %s | FileCheck --check-prefix=CXX17 %s
-// RUN: %clang_cc1 -dM -E -x cuda %s | FileCheck --check-prefix=CXX14 %s
-// RUN: %clang_cc1 -dM -E -x hip %s | FileCheck --check-prefix=CXX14 %s
+// RUN: %clang_cc1 -dM -E %s | grep __cplusplus >%T-cpp-std.txt
+// RUN: %clang_cc1 -dM -E -x cuda %s | grep __cplusplus >%T-cuda-cuda.txt
+// RUN: %clang_cc1 -dM -E -x hip %s | grep __cplusplus >%T-hip-std.txt
+// RUN: diff %T-cpp-std.txt %T-cuda-cuda.txt
+// RUN: diff %T-cpp-std.txt %T-hip-std.txt
 
 // RUN: %clang_cc1 -dM -E -x cuda -std=c++14 %s | FileCheck --check-prefix=CXX14 %s
+// RUN: %clang_cc1 -dM -E -x cuda -std=c++17 %s | FileCheck --check-prefix=CXX17 %s
 // RUN: %clang_cc1 -dM -E -x hip -std=c++98 %s | FileCheck --check-prefix=CXX98 %s
 
 // CXX98: #define __cplusplus 199711L
Index: clang/test/Driver/unknown-std.cpp
===
--- clang/test/Driver/unknown-std.cpp
+++ clang/test/Driver/unknown-std.cpp
@@ -4,7 +4,10 @@
 
 // RUN: not %clang %s -std=foobar -c 2>&1 | FileCheck --match-full-lines %s
 // RUN: not %clang -x objective-c++ %s -std=foobar -c 2>&1 | FileCheck --match-full-lines %s
-// RUN: not %clang -x cuda -nocudainc -nocudalib --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s -std=foobar -c 2>&1 | FileCheck --match-full-lines --check-prefix=CHECK --check-prefix=CUDA %s
+// RUN: not %clang -x cuda -nocudainc -nocudalib --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
+// RUN:   %s -std=foobar -c 2>&1 | FileCheck --match-full-lines %s
+// RUN: not %clang -x hip -nocudainc -nocudalib %s -std=foobar -c 2>&1 \
+// RUN:   | FileCheck --match-full-lines %s
 
 // CHECK: error: invalid value 'foobar' in '-std=foobar'
 // CHECK-NEXT: note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
Index: clang/test/CodeGenCUDA/long-double.cu
===
--- clang/test/CodeGenCUDA/long-double.cu
+++ clang/test/CodeGenCUDA/long-double.cu
@@ -6,7 +6,7 @@
 // RUN:   -aux-triple x86_64-unknown-gnu-linux -fcuda-is-device \
 // RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
 
-// CHECK: @_ZN15infinity_helperIeE5valueE = {{.*}} double 0x47EFD586B834, align 8
+// CHECK: @_ZN15infinity_helperIeE5valueE = {{.*}} double 0x47EFD586B834,{{.*}} align 8
 // CHECK: @size = {{.*}} i32 8
 
 #include "Inputs/cuda.h"
Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -54,8 +54,6 @@
 return LangStandard::lang_opencl12;
   case Language::OpenCLCXX:
 return LangStandard::lang_openclcpp10;
-  case Language::CUDA:
-return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
 // The PS4 uses C99 as the default C standard.
@@ -66,13 +64,13 @@
 return LangStandard::lang_gnu11;
   case Language::CXX:
   case Language::ObjCXX:
+  case Language::CUDA:
+  case Language::HIP:
 if (T.isPS())
   return LangStandard::lang_gnucxx14;
 return LangStandard::lang_gnucxx17;
   case Language::RenderScript:
 return LangStandard::lang_c99;
-  case Language::HIP:
-return LangStandard::lang_hip;
   case Language::HLSL:
 return LangStandard::lang_hlsl2021;
   }
Index: clang/include/clang/Basic/LangStandards.def
===
--- clang/include/clang/Basic/LangStandards.def
+++ clang/include/clang/Basic/LangStandards.def
@@ -214,14 +214,6 @@
 LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++1.0")
 LANGSTANDARD_ALIAS_DEPR(openclcpp2021, "CLC++2021")
 
-// CUDA
-LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)",
- LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
-
-// HIP
-LANGSTANDARD(hip, "hip", HIP, "HIP",
- LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
-
 // HLSL
 LANGSTANDARD(hlsl, "hlsl",
  HLSL, "High Level Shader Language",
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -805,6 +805,9 @@
 
 

[PATCH] D155670: [c-index-test] Suppress -Wcast-qual after D153911

2023-07-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay abandoned this revision.
MaskRay added a comment.

commit 0f0c3d45d7d75ba82a955246da654146a7d57a0d 
 did this 
first


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155670

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


[PATCH] D155545: [clang][Interp] Pass CallExpr to builtin functions

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

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

https://reviews.llvm.org/D155545

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/Opcodes.td

Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -52,6 +52,7 @@
 def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
 def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
 def ArgCastKind : ArgType { let Name = "CastKind"; }
+def ArgCallExpr : ArgType { let Name = "const CallExpr *"; }
 
 //===--===//
 // Classes of types instructions operate on.
@@ -188,7 +189,7 @@
 }
 
 def CallBI : Opcode {
-  let Args = [ArgFunction];
+  let Args = [ArgFunction, ArgCallExpr];
   let Types = [];
 }
 
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -237,10 +237,9 @@
 /// second one is an integral value.
 static bool interp__builtin_isfpclass(InterpState , CodePtr OpPC,
   const InterpFrame *Frame,
-  const Function *Func) {
-  const Expr *E = S.Current->getExpr(OpPC);
-  const CallExpr *CE = cast(E);
-  PrimType FPClassArgT = *S.getContext().classify(CE->getArgs()[1]->getType());
+  const Function *Func,
+  const CallExpr *Call) {
+  PrimType FPClassArgT = *S.getContext().classify(Call->getArg(1)->getType());
   APSInt FPClassArg = peekToAPSInt(S.Stk, FPClassArgT);
   const Floating  =
   S.Stk.peek(align(primSize(FPClassArgT) + primSize(PT_Float)));
@@ -301,10 +300,9 @@
 /// The return type must be the same.
 static bool interp__builtin_arithmetic_fence(InterpState , CodePtr OpPC,
  const InterpFrame *Frame,
- const Function *Func) {
-  const Expr *E = S.Current->getExpr(OpPC);
-  const CallExpr *CE = cast(E);
-  QualType ReturnType = CE->getType();
+ const Function *Func,
+ const CallExpr *Call) {
+  QualType ReturnType = Call->getType();
 
   // TODO: Support vector and complex types.
   if (!ReturnType->isFloatingType())
@@ -316,7 +314,8 @@
   return true;
 }
 
-bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F) {
+bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F,
+  const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
 
@@ -410,7 +409,7 @@
   return Ret(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_isfpclass:
-if (interp__builtin_isfpclass(S, OpPC, Frame, F))
+if (interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
   return Ret(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_fpclassify:
@@ -427,7 +426,7 @@
 break;
 
   case Builtin::BI__arithmetic_fence:
-if (interp__builtin_arithmetic_fence(S, OpPC, Frame, F))
+if (interp__builtin_arithmetic_fence(S, OpPC, Frame, F, Call))
   return Ret(S, OpPC, Dummy);
 break;
 
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -180,7 +180,8 @@
 bool Interpret(InterpState , APValue );
 
 /// Interpret a builtin function.
-bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F);
+bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F,
+  const CallExpr *Call);
 
 /// Perform a bitcast of all fields of P into Buff. This performs the
 /// actions of a __builtin_bit_cast expression when the target type
@@ -1843,13 +1844,14 @@
   return Call(S, OpPC, Func);
 }
 
-inline bool CallBI(InterpState , CodePtr , const Function *Func) {
+inline bool CallBI(InterpState , CodePtr , const Function *Func,
+   const CallExpr *CE) {
   auto NewFrame = std::make_unique(S, Func, PC);
 
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
-  if (InterpretBuiltin(S, PC, Func)) {
+  if (InterpretBuiltin(S, PC, Func, CE)) {
 NewFrame.release();
 return true;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1906,7 +1906,7 @@
   return false;
   }
 
-  if (!this->emitCallBI(Func, E))
+  if (!this->emitCallBI(Func, E, E))
 return false;
 
   QualType ReturnType = 

[PATCH] D155356: [clang][Interp] Implement __builtin_nan family of functions

2023-07-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

One thing I'm wondering though is:

  constexpr char A[] = {'1', '2', '3'};
  constexpr double d = __builtin_nans(A);

what's expected here? The given char array is not null-terminated. 
Should the interpreter ignore the null byte at the end if it's there? 
`StringRef::getAsInteger()` always returns an error if it encounters one, so 
the currentcode in `InterpBuiltin.cpp` ignores the last byte and will pass `12` 
along for the example above.


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

https://reviews.llvm.org/D155356

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


[clang] 12f35b3 - [tools] Use "#pragma GCC" instead of "#pragma clang" to ignore -Wcast-qual in c-index-test.c (NFC)

2023-07-18 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2023-07-19T12:05:05+08:00
New Revision: 12f35b39ee63e932d4bdf6b28cce2e3d07713c4d

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

LOG: [tools] Use "#pragma GCC" instead of "#pragma clang" to ignore -Wcast-qual 
in c-index-test.c (NFC)

Added: 


Modified: 
clang/tools/c-index-test/c-index-test.c

Removed: 




diff  --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 9c60e83f0bcf93..9d66a22f3b43b5 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -231,14 +231,14 @@ void free_remapped_files(struct CXUnsavedFile 
*unsaved_files,
  int num_unsaved_files) {
   int i;
   for (i = 0; i != num_unsaved_files; ++i) {
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
 #endif
 free((char *)unsaved_files[i].Filename);
 free((char *)unsaved_files[i].Contents);
-#if defined(__clang__)
-#pragma clang diagnostic pop
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
 #endif
   }
   free(unsaved_files);
@@ -3766,13 +3766,13 @@ index_startedTranslationUnit(CXClientData client_data, 
void *reserved) {
   printCheck(index_data);
 
   printf("[startedTranslationUnit]\n");
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
 #endif
   return (CXIdxClientContainer)"TU";
-#if defined(__clang__)
-#pragma clang diagnostic pop
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
 #endif
 }
 



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


[PATCH] D155356: [clang][Interp] Implement __builtin_nan family of functions

2023-07-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 541833.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D155356

Files:
  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
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -34,3 +37,15 @@
 // ref-error {{not an integral constant}} \
 // ref-note {{dereferenced one-past-the-end}}
 }
+
+namespace nan {
+  constexpr double NaN1 = __builtin_nan("");
+
+  /// The current interpreter does not accept this, but it should.
+  constexpr float NaN2 = __builtin_nans([](){return "0xAE98";}()); // ref-error {{must be initialized by a constant expression}}
+
+  constexpr double NaN3 = __builtin_nan("foo"); // expected-error {{must be initialized by a constant expression}} \
+// ref-error {{must be initialized by a constant expression}}
+  constexpr float NaN4 = __builtin_nanf("");
+  constexpr long double NaN5 = __builtin_nanf128("");
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -9,6 +9,7 @@
 #include "Interp.h"
 #include "PrimType.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
 
 namespace clang {
 namespace interp {
@@ -57,6 +58,64 @@
   return true;
 }
 
+static bool interp__builtin_nan(InterpState , CodePtr OpPC,
+const InterpFrame *Frame, const Function *F,
+bool Signaling) {
+  const Pointer  = getParam(Frame, 0);
+
+  if (!CheckLoad(S, OpPC, Arg))
+return false;
+
+  assert(Arg.getFieldDesc()->isPrimitiveArray());
+
+  // Convert the given string to an integer using StringRef's API.
+  llvm::APInt Fill;
+  std::string Str;
+  assert(Arg.getNumElems() >= 1);
+  for (unsigned I = 0, E = Arg.getNumElems() - 1; I != E; ++I) {
+const Pointer  = Arg.atIndex(I);
+
+if (!CheckLoad(S, OpPC, Elem))
+  return false;
+
+Str += Elem.deref();
+  }
+
+  // Treat empty strings as if they were zero.
+  if (Str.empty())
+Fill = llvm::APInt(32, 0);
+  else if (StringRef(Str).getAsInteger(0, Fill))
+return false;
+
+  const llvm::fltSemantics  =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  Floating Result;
+  if (S.getCtx().getTargetInfo().isNan2008()) {
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, ));
+else
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, ));
+  } else {
+// Prior to IEEE 754-2008, architectures were allowed to choose whether
+// the first bit of their significand was set for qNaN or sNaN. MIPS chose
+// a different encoding to what became a standard in 2008, and for pre-
+// 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as
+// sNaN. This is now known as "legacy NaN" encoding.
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, ));
+else
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, ));
+  }
+
+  S.Stk.push(Result);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -70,7 +129,24 @@
   case Builtin::BI__builtin_strcmp:
 if (interp__builtin_strcmp(S, OpPC, Frame))
   return Ret(S, OpPC, Dummy);
-return false;
+break;
+  case Builtin::BI__builtin_nan:
+  case Builtin::BI__builtin_nanf:
+  case Builtin::BI__builtin_nanl:
+  case Builtin::BI__builtin_nanf16:
+  case Builtin::BI__builtin_nanf128:
+if (interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/false))
+  return Ret(S, OpPC, Dummy);
+break;
+  case Builtin::BI__builtin_nans:
+  case Builtin::BI__builtin_nansf:
+  case Builtin::BI__builtin_nansl:
+  case Builtin::BI__builtin_nansf16:
+  case Builtin::BI__builtin_nansf128:
+if (interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/true))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }

[PATCH] D155356: [clang][Interp] Implement __builtin_nan family of functions

2023-07-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 2 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:106
+// 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as
+// sNaN. This is now known as "legacy NaN" encoding.
+if (Signaling)

aaron.ballman wrote:
> LOL, thank you for this comment and wow. :-D
That's just copy/paste from `ExprConst.cpp` :)



Comment at: clang/test/AST/Interp/builtin-functions.cpp:44
+
+  constexpr float Nan2 = __builtin_nans([](){return "0xAE98";}()); // 
ref-error {{must be initialized by a constant expression}}
+}

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Probably worth a comment here mentioning that the ref-error is a 
> > > rejects-valid issue that the experimental compiler accepts correctly.
> > I thought you said on Discord that the current interpreter is correct? I 
> > made the new one reject anything but string literals in 
> > https://reviews.llvm.org/D155545.
> Oops, crossing streams as I just mentioned this in another review of yours in 
> the same area.
> 
> I think I misunderstood the question on Discord when we were chatting. I was 
> thinking the situation was more that Sema was allowing through something like 
> `__builtin_nan(12);` and diagnosing it later during CodeGen. I think 
> constexpr builtins should generally behave the same as regular constexpr 
> functions the user could write.
> 
> I'm really sorry if I made extra work for you with this confusion!
No problem, passing the `CallExpr` along still makes sense.


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

https://reviews.llvm.org/D155356

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


[PATCH] D155356: [clang][Interp] Implement __builtin_nan family of functions

2023-07-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 541832.
tbaeder marked 3 inline comments as done.

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

https://reviews.llvm.org/D155356

Files:
  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
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -34,3 +37,14 @@
 // ref-error {{not an integral constant}} \
 // ref-note {{dereferenced one-past-the-end}}
 }
+
+namespace nan {
+  constexpr double NaN1 = __builtin_nan("");
+
+  constexpr float NaN2 = __builtin_nans([](){return "0xAE98";}()); // ref-error {{must be initialized by a constant expression}}
+
+  constexpr double NaN3 = __builtin_nan("foo"); // expected-error {{must be initialized by a constant expression}} \
+// ref-error {{must be initialized by a constant expression}}
+  constexpr float NaN4 = __builtin_nanf("");
+  constexpr long double NaN5 = __builtin_nanf128("");
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -9,6 +9,7 @@
 #include "Interp.h"
 #include "PrimType.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
 
 namespace clang {
 namespace interp {
@@ -57,6 +58,64 @@
   return true;
 }
 
+static bool interp__builtin_nan(InterpState , CodePtr OpPC,
+const InterpFrame *Frame, const Function *F,
+bool Signaling) {
+  const Pointer  = getParam(Frame, 0);
+
+  if (!CheckLoad(S, OpPC, Arg))
+return false;
+
+  assert(Arg.getFieldDesc()->isPrimitiveArray());
+
+  // Convert the given string to an integer using StringRef's API.
+  llvm::APInt Fill;
+  std::string Str;
+  assert(Arg.getNumElems() >= 1);
+  for (unsigned I = 0, E = Arg.getNumElems() - 1; I != E; ++I) {
+const Pointer  = Arg.atIndex(I);
+
+if (!CheckLoad(S, OpPC, Elem))
+  return false;
+
+Str += Elem.deref();
+  }
+
+  // Treat empty strings as if they were zero.
+  if (Str.empty())
+Fill = llvm::APInt(32, 0);
+  else if (StringRef(Str).getAsInteger(0, Fill))
+return false;
+
+  const llvm::fltSemantics  =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  Floating Result;
+  if (S.getCtx().getTargetInfo().isNan2008()) {
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, ));
+else
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, ));
+  } else {
+// Prior to IEEE 754-2008, architectures were allowed to choose whether
+// the first bit of their significand was set for qNaN or sNaN. MIPS chose
+// a different encoding to what became a standard in 2008, and for pre-
+// 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as
+// sNaN. This is now known as "legacy NaN" encoding.
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, ));
+else
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, ));
+  }
+
+  S.Stk.push(Result);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState , CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -70,7 +129,24 @@
   case Builtin::BI__builtin_strcmp:
 if (interp__builtin_strcmp(S, OpPC, Frame))
   return Ret(S, OpPC, Dummy);
-return false;
+break;
+  case Builtin::BI__builtin_nan:
+  case Builtin::BI__builtin_nanf:
+  case Builtin::BI__builtin_nanl:
+  case Builtin::BI__builtin_nanf16:
+  case Builtin::BI__builtin_nanf128:
+if (interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/false))
+  return Ret(S, OpPC, Dummy);
+break;
+  case Builtin::BI__builtin_nans:
+  case Builtin::BI__builtin_nansf:
+  case Builtin::BI__builtin_nansl:
+  case Builtin::BI__builtin_nansf16:
+  case Builtin::BI__builtin_nansf128:
+if (interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/true))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
___
cfe-commits mailing 

[PATCH] D155647: [RISCV] Add C intrinsics for scalar crypto

2023-07-18 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc added a comment.

Can we run mem2reg pass in RUNs just like RVV tests (maybe another cleanup 
patch)? I think there are a lot of noises in CHECKS.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155647

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


[clang] 16d5078 - [tools] Fix buildbot build failure

2023-07-18 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2023-07-19T11:39:00+08:00
New Revision: 16d50781e16374f5bf930ba0b9aa8cbbb034ee6c

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

LOG: [tools] Fix buildbot build failure

/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:234:
 warning: ignoring '#pragma clang diagnostic' [-Wunknown-pragmas]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:235:
 warning: ignoring '#pragma clang diagnostic' [-Wunknown-pragmas]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:236:10:
 warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:237:10:
 warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:238:
 warning: ignoring '#pragma clang diagnostic' [-Wunknown-pragmas]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:3765:
 warning: ignoring '#pragma clang diagnostic' [-Wunknown-pragmas]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:3766:
 warning: ignoring '#pragma clang diagnostic' [-Wunknown-pragmas]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:3767:10:
 warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
/buildbot/worker/arc-folder/llvm-project/clang/tools/c-index-test/c-index-test.c:3768:
 warning: ignoring '#pragma clang diagnostic' [-Wunknown-pragmas]

Added: 


Modified: 
clang/tools/c-index-test/c-index-test.c

Removed: 




diff  --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 22cea032036977..9c60e83f0bcf93 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -231,11 +231,15 @@ void free_remapped_files(struct CXUnsavedFile 
*unsaved_files,
  int num_unsaved_files) {
   int i;
   for (i = 0; i != num_unsaved_files; ++i) {
+#if defined(__clang__)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wcast-qual"
+#endif
 free((char *)unsaved_files[i].Filename);
 free((char *)unsaved_files[i].Contents);
+#if defined(__clang__)
 #pragma clang diagnostic pop
+#endif
   }
   free(unsaved_files);
 }
@@ -3762,10 +3766,14 @@ index_startedTranslationUnit(CXClientData client_data, 
void *reserved) {
   printCheck(index_data);
 
   printf("[startedTranslationUnit]\n");
+#if defined(__clang__)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wcast-qual"
+#endif
   return (CXIdxClientContainer)"TU";
+#if defined(__clang__)
 #pragma clang diagnostic pop
+#endif
 }
 
 static void index_indexDeclaration(CXClientData client_data,



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


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541824.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm3intrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/X86/sm3-builtins.c
  clang/test/CodeGen/X86/sm3-error.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm3-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm3-32.txt
  llvm/test/MC/Disassembler/X86/sm3-64.txt
  llvm/test/MC/X86/sm3-att-32.s
  llvm/test/MC/X86/sm3-att-64.s
  llvm/test/MC/X86/sm3-intel-32.s
  llvm/test/MC/X86/sm3-intel-64.s

Index: llvm/test/MC/X86/sm3-intel-64.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm3-intel-64.s
@@ -0,0 +1,86 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xe4]
+  vsm3msg1 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x10,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x10,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xe4]
+  vsm3msg2 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x11,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x11,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmm4, 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0xe4,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmm4, 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+// CHECK: encoding: [0xc4,0x23,0x11,0xde,0xa4,0xf5,0x00,0x00,0x00,0x10,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+// CHECK: encoding: [0xc4,0x43,0x11,0xde,0xa4,0x80,0x23,0x01,0x00,0x00,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rip], 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0x25,0x00,0x00,0x00,0x00,0x7b]
+  

[clang] 0f0c3d4 - [tools] Ignore -Wcast-qual in c-index-test.c after D153911 (NFC)

2023-07-18 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2023-07-19T10:55:12+08:00
New Revision: 0f0c3d45d7d75ba82a955246da654146a7d57a0d

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

LOG: [tools] Ignore -Wcast-qual in c-index-test.c after D153911 (NFC)

/Users/jiefu/llvm-project/clang/tools/c-index-test/c-index-test.c:234:18: 
error: cast from 'const char *' to 'char *' drops const qualifier 
[-Werror,-Wcast-qual]
free((char *)unsaved_files[i].Filename);
 ^
/Users/jiefu/llvm-project/clang/tools/c-index-test/c-index-test.c:235:18: 
error: cast from 'const char *' to 'char *' drops const qualifier 
[-Werror,-Wcast-qual]
free((char *)unsaved_files[i].Contents);
 ^
/Users/jiefu/llvm-project/clang/tools/c-index-test/c-index-test.c:3762:32: 
error: cast from 'const char *' to 'void *' drops const qualifier 
[-Werror,-Wcast-qual]
  return (CXIdxClientContainer)"TU";
   ^
3 errors generated.

Added: 


Modified: 
clang/tools/c-index-test/c-index-test.c

Removed: 




diff  --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 68a560ca15cf43..22cea032036977 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -231,8 +231,11 @@ void free_remapped_files(struct CXUnsavedFile 
*unsaved_files,
  int num_unsaved_files) {
   int i;
   for (i = 0; i != num_unsaved_files; ++i) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcast-qual"
 free((char *)unsaved_files[i].Filename);
 free((char *)unsaved_files[i].Contents);
+#pragma clang diagnostic pop
   }
   free(unsaved_files);
 }
@@ -3759,7 +3762,10 @@ index_startedTranslationUnit(CXClientData client_data, 
void *reserved) {
   printCheck(index_data);
 
   printf("[startedTranslationUnit]\n");
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcast-qual"
   return (CXIdxClientContainer)"TU";
+#pragma clang diagnostic pop
 }
 
 static void index_indexDeclaration(CXClientData client_data,



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


[PATCH] D155671: [include-cleaner] allow spelling strategies to customize verbatim/system headers

2023-07-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Our use case is wanting to apply a spelling strategy to rewrite the spellings
written in IWYU pragma private directives.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155671

Files:
  clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -11,6 +11,7 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Testing/TestAST.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Path.h"
@@ -42,6 +43,10 @@
 class DummyIncludeSpeller : public IncludeSpeller {
 public:
   std::string operator()(const IncludeSpeller::Input ) const override {
+if (Input.H.kind() == Header::Standard)
+  return "";
+if (Input.H.kind() != Header::Physical)
+  return "";
 llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
 std::string RootWithSeparator{testRoot()};
 RootWithSeparator += llvm::sys::path::get_separator();
@@ -71,6 +76,16 @@
 spellHeader({Header{*FM.getFile("dir/header.h")}, HS, MainFile}));
 }
 
+TEST(IncludeSpeller, CanOverrideSystemHeaders) {
+  TestAST AST("");
+  auto  = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+  EXPECT_EQ("",
+spellHeader({Header{*tooling::stdlib::Header::named("")},
+ HS, MainFile}));
+}
+
 IncludeSpellingStrategy::Add
 Speller("dummy", "Dummy Include Speller");
 
Index: clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
===
--- clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
+++ clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
@@ -23,44 +23,40 @@
 class DefaultIncludeSpeller : public IncludeSpeller {
 public:
   std::string operator()(const Input ) const override {
-bool IsSystem = false;
-std::string FinalSpelling = Input.HS.suggestPathToFileForDiagnostics(
-Input.H.physical(), Input.Main->tryGetRealPathName(), );
-return IsSystem ? "<" + FinalSpelling + ">" : "\"" + FinalSpelling + "\"";
+switch (Input.H.kind()) {
+case Header::Standard:
+  return Input.H.standard().name().str();
+case Header::Verbatim:
+  return Input.H.verbatim().str();
+case Header::Physical:
+  bool IsSystem = false;
+  std::string FinalSpelling = Input.HS.suggestPathToFileForDiagnostics(
+  Input.H.physical(), Input.Main->tryGetRealPathName(), );
+  return IsSystem ? "<" + FinalSpelling + ">" : "\"" + FinalSpelling + "\"";
+}
   }
 };
 
-std::string spellPhysicalHeader(const IncludeSpeller::Input ) {
-  static auto Spellers = [] {
-llvm::SmallVector> Result;
+} // namespace
+
+std::string spellHeader(const IncludeSpeller::Input ) {
+  static auto *Spellers = [] {
+auto *Result =
+new llvm::SmallVector>;
 for (const auto  :
  include_cleaner::IncludeSpellingStrategy::entries())
-  Result.push_back(Strategy.instantiate());
-Result.push_back(std::make_unique());
+  Result->push_back(Strategy.instantiate());
+Result->push_back(std::make_unique());
 return Result;
   }();
 
   std::string Spelling;
-  for (const auto  : Spellers) {
+  for (const auto  : *Spellers) {
 Spelling = (*Speller)(Input);
 if (!Spelling.empty())
   break;
   }
   return Spelling;
 }
-} // namespace
 
-std::string spellHeader(const IncludeSpeller::Input ) {
-  const Header  = Input.H;
-  switch (H.kind()) {
-  case Header::Standard:
-return H.standard().name().str();
-  case Header::Verbatim:
-return H.verbatim().str();
-  case Header::Physical:
-// Spelling physical headers allows for various plug-in strategies.
-return spellPhysicalHeader(Input);
-  }
-  llvm_unreachable("Unknown Header kind");
-}
 } // namespace clang::include_cleaner
\ No newline at end of file
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Headers/sm3intrin.h:162
+/// \param imm8
+///A 128-bit vector of [4 x int].
+/// \returns

This is `int`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

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


[PATCH] D155670: [c-index-test] Suppress -Wcast-qual after D153911

2023-07-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: AlexM, dblaikie.
Herald added a subscriber: arphaman.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

free_remapped_files needs to discard the casts qualifier.
index_startedTranslationUnit casts a string literal to void *.

Since we probably cannot change the public API, suppress the warnings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155670

Files:
  clang/tools/c-index-test/c-index-test.c


Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -230,10 +230,17 @@
 void free_remapped_files(struct CXUnsavedFile *unsaved_files,
  int num_unsaved_files) {
   int i;
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
   for (i = 0; i != num_unsaved_files; ++i) {
 free((char *)unsaved_files[i].Filename);
 free((char *)unsaved_files[i].Contents);
   }
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
   free(unsaved_files);
 }
 
@@ -3759,7 +3766,14 @@
   printCheck(index_data);
 
   printf("[startedTranslationUnit]\n");
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
   return (CXIdxClientContainer)"TU";
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
 }
 
 static void index_indexDeclaration(CXClientData client_data,


Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -230,10 +230,17 @@
 void free_remapped_files(struct CXUnsavedFile *unsaved_files,
  int num_unsaved_files) {
   int i;
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
   for (i = 0; i != num_unsaved_files; ++i) {
 free((char *)unsaved_files[i].Filename);
 free((char *)unsaved_files[i].Contents);
   }
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
   free(unsaved_files);
 }
 
@@ -3759,7 +3766,14 @@
   printCheck(index_data);
 
   printf("[startedTranslationUnit]\n");
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-qual"
+#endif
   return (CXIdxClientContainer)"TU";
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
 }
 
 static void index_indexDeclaration(CXClientData client_data,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-07-18 Thread Yueh-Ting (eop) Chen 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 rG28c3a74a5c6c: [Clang][RISCV] Improve diagnostic message for 
full multiply intrinsics (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

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

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(vbool16_t mask, vint64m4_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m4_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m8_t test_vsmul_vv_i64m8_m(vbool8_t mask, vint64m8_t op1, vint64m8_t op2, size_t vl) {
+  return __riscv_vsmul_vv_i64m8_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m8_t test_vsmul_vx_i64m8_m(vbool8_t mask, vint64m8_t op1, int64_t op2, size_t vl) {
+  return __riscv_vsmul_vx_i64m8_m(mask, op1, op2, __RISCV_VXRM_RNU, vl); /* expected-error {{builtin requires: v}} */
+}
+vint64m1_t test_vmulh_vv_i64m1(vint64m1_t op1, 

[clang] 28c3a74 - [Clang][RISCV] Improve diagnostic message for full multiply intrinsics

2023-07-18 Thread via cfe-commits

Author: eopXD
Date: 2023-07-18T19:39:46-07:00
New Revision: 28c3a74a5c6c7ed1ac97a010ca080eaacfd7f324

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

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

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);
```

Reviewed By: craig.topper

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

Added: 
clang/test/Sema/riscv-vector-v-check.c

Modified: 
clang/include/clang/Basic/riscv_vector.td
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaRISCVVectorLookup.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 49011d61af1a2a..7e5889812aecc8 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -1713,13 +1713,11 @@ defm vmax : RVVSignedBinBuiltinSet;
 
 // 12.10. Vector Single-Width Integer Multiply Instructions
 defm vmul : RVVIntBinBuiltinSet;
-let RequiredFeatures = ["FullMultiply"] in {
 defm vmulh : RVVSignedBinBuiltinSet;
 defm vmulhu : RVVUnsignedBinBuiltinSet;
 defm vmulhsu : RVVOutOp1BuiltinSet<"vmulhsu", "csil",
[["vv", "v", "vvUv"],
 ["vx", "v", "vvUe"]]>;
-}
 
 // 12.11. Vector Integer Divide Instructions
 defm vdivu : RVVUnsignedBinBuiltinSet;
@@ -1859,9 +1857,7 @@ let ManualCodegen = [{
   defm vasub : RVVSignedBinBuiltinSetRoundingMode;
 
   // 13.3. Vector Single-Width Fractional Multiply with Rounding and Saturation
-  let RequiredFeatures = ["FullMultiply"] in {
   defm vsmul : RVVSignedBinBuiltinSetRoundingMode;
-  }
 
   // 13.4. Vector Single-Width Scaling Shift Instructions
   defm vssrl : RVVUnsignedShiftBuiltinSetRoundingMode;

diff  --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index e985a9bef888c4..804b1518c06b51 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -475,8 +475,7 @@ class RVVIntrinsic {
 enum RVVRequire : uint8_t {
   RVV_REQ_None = 0,
   RVV_REQ_RV64 = 1 << 0,
-  RVV_REQ_FullMultiply = 1 << 1,
-  RVV_REQ_Xsfvcp = 1 << 2,
+  RVV_REQ_Xsfvcp = 1 << 1,
 
   LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Xsfvcp)
 };

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a8bcf498d18da4..de0977e9bb3a20 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4527,6 +4527,73 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const 
TargetInfo ,
   if (FeatureMissing)
 return true;
 
+  // vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx,
+  // vsmul.vv, vsmul.vx are not included for EEW=64 in Zve64*.
+  switch (BuiltinID) {
+  default:
+break;
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vv:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vx:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vv_tu:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vx_tu:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vv_m:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vx_m:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vv_mu:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vx_mu:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vv_tum:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vx_tum:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vv_tumu:
+  case RISCVVector::BI__builtin_rvv_vmulhsu_vx_tumu:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vv:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vx:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vv_tu:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vx_tu:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vv_m:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vx_m:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vv_mu:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vx_mu:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vv_tum:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vx_tum:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vv_tumu:
+  case RISCVVector::BI__builtin_rvv_vmulhu_vx_tumu:
+  case RISCVVector::BI__builtin_rvv_vmulh_vv:
+  case RISCVVector::BI__builtin_rvv_vmulh_vx:
+  case RISCVVector::BI__builtin_rvv_vmulh_vv_tu:
+  case RISCVVector::BI__builtin_rvv_vmulh_vx_tu:
+  case RISCVVector::BI__builtin_rvv_vmulh_vv_m:
+  case 

[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541815.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

Address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm3intrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/X86/sm3-builtins.c
  clang/test/CodeGen/X86/sm3-error.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm3-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm3-32.txt
  llvm/test/MC/Disassembler/X86/sm3-64.txt
  llvm/test/MC/X86/sm3-att-32.s
  llvm/test/MC/X86/sm3-att-64.s
  llvm/test/MC/X86/sm3-intel-32.s
  llvm/test/MC/X86/sm3-intel-64.s

Index: llvm/test/MC/X86/sm3-intel-64.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm3-intel-64.s
@@ -0,0 +1,86 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xe4]
+  vsm3msg1 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x10,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x10,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xe4]
+  vsm3msg2 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x11,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x11,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmm4, 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0xe4,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmm4, 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+// CHECK: encoding: [0xc4,0x23,0x11,0xde,0xa4,0xf5,0x00,0x00,0x00,0x10,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+// CHECK: encoding: [0xc4,0x43,0x11,0xde,0xa4,0x80,0x23,0x01,0x00,0x00,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rip], 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0x25,0x00,0x00,0x00,0x00,0x7b]
+  

[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Headers/sm3intrin.h:161-164
+/// \param imm8
+///A 128-bit vector of [4 x int].
+/// \returns
+///A 32-bit int.

The description should invert


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

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


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei 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/D155147/new/

https://reviews.llvm.org/D155147

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


[PATCH] D154755: [clang-format] Fix formatting of if statements with BlockIndent

2023-07-18 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:25486
"comment\n"
-   "  return;\n"
"}",

MyDeveloperDay wrote:
> Why remove?
oops. that's a spurious change. I have reverted it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154755

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


[PATCH] D154755: [clang-format] Fix formatting of if statements with BlockIndent

2023-07-18 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 541813.
gedare marked an inline comment as done.
gedare added a comment.

Revert deleted line in test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154755

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25494,12 +25494,56 @@
"}",
Style);
 
+  // Treating if clauses as block indents causes a known bug (#54808, #63383)
+  // breaking the following test. It gets formatted instead as:
+  // "if (quitelongarg != (alsolongarg - 1)\n"
+  // ") { // ABC is a very long comment"
+  // "return;"
+  // "}"
+
+#if 0
   verifyFormat("if (quitelongarg !=\n"
"(alsolongarg - 1)) { // ABC is a very long "
"comment\n"
"  return;\n"
"}",
Style);
+#endif
+
+  verifyFormat("void foo() {\n"
+   "  if (quitelongname < alsolongname ||\n"
+   "  anotherevenlongername <=\n"
+   "  thisreallyreallyreallyreallyreallyreallylongername 
||"
+   "\n"
+   "  othername < thislastname) {\n"
+   "return;\n"
+   "  } else if (\n"
+   "  quitelongname < alsolongname ||\n"
+   "  anotherevenlongername <=\n"
+   "  thisreallyreallyreallyreallyreallyreallylongername 
||"
+   "\n"
+   "  othername < thislastname\n"
+   "  ) {\n"
+   "return;\n"
+   "  }\n"
+   "}",
+   Style);
+
+  Style.ContinuationIndentWidth = 2;
+  verifyFormat("void foo() {\n"
+   "  if (\n"
+   "ThisIsRatherALongIfClause && thatIExpectToBeBroken ||\n"
+   "ontoMultipleLines && whenFormattedCorrectly\n"
+   "  ) {\n"
+   "if (false) {\n"
+   "} else if (\n"
+   "  thisIsRatherALongIfClause && thatIExpectToBeBroken ||\n"
+   "  ontoMultipleLines && whenFormattedCorrectly\n"
+   ") {\n"
+   "}\n"
+   "  }\n"
+   "}",
+   Style);
 }
 
 TEST_F(FormatTest, AlignAfterOpenBracketBlockIndentForStatement) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -5499,7 +5499,7 @@
 if (Next && Next->is(tok::l_paren))
   return false;
 const FormatToken *Previous = Right.MatchingParen->Previous;
-return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
+return !(Previous && Previous->is(tok::kw_for));
   }
 
   // Allow breaking after a trailing annotation, e.g. after a method


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25494,12 +25494,56 @@
"}",
Style);
 
+  // Treating if clauses as block indents causes a known bug (#54808, #63383)
+  // breaking the following test. It gets formatted instead as:
+  // "if (quitelongarg != (alsolongarg - 1)\n"
+  // ") { // ABC is a very long comment"
+  // "return;"
+  // "}"
+
+#if 0
   verifyFormat("if (quitelongarg !=\n"
"(alsolongarg - 1)) { // ABC is a very long "
"comment\n"
"  return;\n"
"}",
Style);
+#endif
+
+  verifyFormat("void foo() {\n"
+   "  if (quitelongname < alsolongname ||\n"
+   "  anotherevenlongername <=\n"
+   "  thisreallyreallyreallyreallyreallyreallylongername ||"
+   "\n"
+   "  othername < thislastname) {\n"
+   "return;\n"
+   "  } else if (\n"
+   "  quitelongname < alsolongname ||\n"
+   "  anotherevenlongername <=\n"
+   "  thisreallyreallyreallyreallyreallyreallylongername ||"
+   "\n"
+   "  othername < thislastname\n"
+   "  ) {\n"
+   "return;\n"
+   "  }\n"
+   "}",
+   Style);
+
+  Style.ContinuationIndentWidth = 2;
+  verifyFormat("void foo() {\n"
+   "  if (\n"
+   "ThisIsRatherALongIfClause && thatIExpectToBeBroken ||\n"
+   "ontoMultipleLines && whenFormattedCorrectly\n"
+   "  ) {\n"
+   "if (false) {\n"
+   

[PATCH] D155148: [X86] Add SM4 instructions.

2023-07-18 Thread Kan Shengchen via Phabricator via cfe-commits
skan accepted this revision.
skan added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155148

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


[PATCH] D154366: [clang][ExprConstant] Print template arguments when describing stack frame

2023-07-18 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I think this looks fine, I just wonder if we should be adding more tests to 
make sure we cover the a fuller set of types and non-type template parameters. 
I feel like this is always what bites us when bugs come up, if we had just test 
more carefully we would have caught the problem earlier.


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

https://reviews.llvm.org/D154366

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


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

2023-07-18 Thread Yueh-Ting (eop) Chen 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 rGc4a5b5849767: [Clang][RISCV] Guard RVV intrinsics types that 
is not available when ELEN  64 (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

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

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:[[TMP0:%.*]] = call  @llvm.riscv.vmulhu.nxv1i16.nxv1i16.i64( poison,  [[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])
-// CHECK-RV64-NEXT:ret  [[TMP0]]
-//
-vuint16mf4_t test_vmulhu_vv_u16mf4(vuint16mf4_t op1, vuint16mf4_t op2, size_t vl) {
-  return __riscv_vmulhu_vv_u16mf4(op1, op2, vl);
-}
-
-// CHECK-RV64-LABEL: 

[clang] c4a5b58 - [Clang][RISCV] Guard RVV intrinsics types that is not available when ELEN < 64

2023-07-18 Thread via cfe-commits

Author: eopXD
Date: 2023-07-18T18:57:33-07:00
New Revision: c4a5b58497677f6be2618765f89b08462e820337

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

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

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

Reviewed By: craig.topper

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

Added: 
clang/test/Sema/riscv-vector-zve64x-check.c

Modified: 
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

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index eea60d7c9831e1..8d20d088bb63c4 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2306,6 +2306,8 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// Check if the type is the CUDA device builtin texture type.
   bool isCUDADeviceBuiltinTextureType() const;
 
+  bool isRVVType(unsigned ElementCount) const;
+
   bool isRVVType() const;
 
   bool isRVVType(unsigned Bitwidth, bool IsFloat) const;
@@ -7193,6 +7195,16 @@ inline bool Type::isRVVType() const {
 false; // end of boolean or operation.
 }
 
+inline bool Type::isRVVType(unsigned ElementCount) const {
+  bool Ret = false;
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
+IsFP)  
\
+  if (NumEls == ElementCount)  
\
+Ret |= isSpecificBuiltinType(BuiltinType::Id);
+#include "clang/Basic/RISCVVTypes.def"
+  return Ret;
+}
+
 inline bool Type::isRVVType(unsigned Bitwidth, bool IsFloat) const {
   bool Ret = false;
 #define RVV_TYPE(Name, Id, SingletonId)

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 339f15ba1217fb..a8bcf498d18da4 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5331,7 +5331,10 @@ bool Sema::CheckWebAssemblyBuiltinFunctionCall(const 
TargetInfo ,
 
 void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
   const TargetInfo  = Context.getTargetInfo();
-  if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&
+  // (ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1) requires at
+  // least zve64x
+  if ((Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) ||
+   Ty->isRVVType(/* ElementCount */ 1)) &&
   !TI.hasFeature("zve64x"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
   if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) &&

diff  --git 
a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulh-overloaded.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulh-overloaded.c
index b07825a831f2da..6eaa175351e3b5 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulh-overloaded.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vmulh-overloaded.c
@@ -6,24 +6,6 @@
 
 #include 
 
-// CHECK-RV64-LABEL: @test_vmulh_vv_i8mf8(
-// CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vmulh.nxv1i8.nxv1i8.i64( poison,  
[[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])
-// CHECK-RV64-NEXT:ret  [[TMP0]]
-//
-vint8mf8_t test_vmulh_vv_i8mf8(vint8mf8_t op1, vint8mf8_t op2, size_t vl) {
-  return __riscv_vmulh(op1, op2, vl);
-}
-
-// CHECK-RV64-LABEL: @test_vmulh_vx_i8mf8(
-// CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vmulh.nxv1i8.i8.i64( poison,  
[[OP1:%.*]], i8 [[OP2:%.*]], i64 [[VL:%.*]])
-// CHECK-RV64-NEXT:ret  [[TMP0]]
-//
-vint8mf8_t test_vmulh_vx_i8mf8(vint8mf8_t op1, int8_t op2, size_t vl) {
-  return __riscv_vmulh(op1, op2, vl);
-}
-
 // CHECK-RV64-LABEL: @test_vmulh_vv_i8mf4(
 // CHECK-RV64-NEXT:  entry:
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vmulh.nxv2i8.nxv2i8.i64( poison,  
[[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])
@@ -132,24 +114,6 @@ vint8m8_t test_vmulh_vx_i8m8(vint8m8_t op1, int8_t op2, 
size_t vl) {
   return __riscv_vmulh(op1, op2, vl);
 }
 
-// CHECK-RV64-LABEL: @test_vmulh_vv_i16mf4(
-// CHECK-RV64-NEXT:  entry:
-// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vmulh.nxv1i16.nxv1i16.i64( poison,  [[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])
-// 

[PATCH] D155668: [RISCV] Upgrade Zvfh version to 1.0 and move out of experimental state.

2023-07-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: asb, reames, kito-cheng.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, arphaman, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, 
hiraditya, arichardson, qcolombet, MatzeB.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: wangpc, eopXD, MaskRay.
Herald added projects: clang, LLVM.

This has been ratified according to 
https://wiki.riscv.org/display/HOME/Recently+Ratified+Extensions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155668

Files:
  clang/lib/Sema/SemaChecking.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcompress.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcpop.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfabs.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfclass.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfcvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfcvt_rtz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt_rod.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfncvt_rtz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfneg.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsac.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfnmsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrdiv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrec7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmax.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredmin.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredosum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfredusum.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsqrt7.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfrsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnj.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjn.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsgnjx.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1down.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfslide1up.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsqrt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfsub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwcvt.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwcvt_rtz.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwmacc.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfwmsac.c
  

[PATCH] D155667: [-Wunsafe-buffer-usage] Check source location validity before using `TypeLoc`s

2023-07-18 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: NoQ, jkorous, t-rasmud, malavikasamak.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The safe-buffer analysis analyzes `TypeLoc`s of types of variable declarations 
in order to get source locations of them.

However, in some cases, the source locations of a `TypeLoc` are not valid.  
Using invalid source locations results in assertion violation or incorrect 
analysis or fix-its.

It is still not clear to me in what circumstances a `TypeLoc`  does not have 
valid source locations (it looks like a bug in Clang to me, but it is not our 
responsibility to fix it).  So we will conservatively give up the analysis when 
required source locations are not valid.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155667

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp


Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp
@@ -33,6 +33,26 @@
   }
 }
 
+// The analysis requires accurate source location informations from
+// `TypeLoc`s of types of variable (parameter) declarations in order
+// to generate fix-its for them. But those information is not always
+// available (probably due to some bugs in clang but it is irrelevant
+// to the safe-buffer project).  The following is an example.  When
+// `_Atomic` is used, we cannot get valid source locations of the
+// pointee type of `unsigned *`.  The analysis gives up in such a
+// case.
+// CHECK-NOT: fix-it:
+void typeLocSourceLocationInvalid(_Atomic unsigned *map) { // 
expected-warning{{'map' is an unsafe pointer used for buffer access}}
+  map[5] = 5; // expected-note{{used in buffer access here}}
+}
+
+// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:33-[[@LINE+1]]:46}:"std::span 
map"
+void typeLocSourceLocationValid(unsigned *map) { // expected-warning{{'map' is 
an unsafe pointer used for buffer access}} \
+   expected-note{{change type 
of 'map' to 'std::span' to preserve bounds information}}
+  map[5] = 5; // expected-note{{used in buffer access here}}
+}
+// CHECK: 
fix-it:"{{.*}}":{[[@LINE-1]]:2-[[@LINE-1]]:2}:"\n{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}}
 void typeLocSourceLocationValid(unsigned *map) {return 
typeLocSourceLocationValid(std::span(map, <# size #>));}\n"
+
 // We do not fix parameters participating unsafe operations for the
 // following functions/methods or function-like expressions:
 
@@ -128,4 +148,3 @@
   int tmp;
   tmp = x[5]; // expected-note{{used in buffer access here}}
 }
-
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1385,8 +1385,18 @@
   TypeLoc PteTyLoc = TyLoc.getUnqualifiedLoc().getNextTypeLoc();
   SourceLocation VDNameStartLoc = VD->getLocation();
 
-  if (!SM.isBeforeInTranslationUnit(PteTyLoc.getSourceRange().getEnd(),
-VDNameStartLoc)) {
+  if (!(VDNameStartLoc.isValid() && PteTyLoc.getSourceRange().isValid())) {
+// We are expecting these locations to be valid. But in some cases, they 
are
+// not all valid. It is a Clang bug to me and we are not responsible for
+// fixing it.  So we will just give up for now when it happens.
+return std::nullopt;
+  }
+
+  // Note that TypeLoc.getEndLoc() returns the begin location of the last 
token:
+  SourceLocation PteEndOfTokenLoc =
+  Lexer::getLocForEndOfToken(PteTyLoc.getEndLoc(), 0, SM, LangOpts);
+
+  if (!SM.isBeforeInTranslationUnit(PteEndOfTokenLoc, VDNameStartLoc)) {
 // We only deal with the cases where the source text of the pointee type
 // appears on the left-hand side of the variable identifier completely,
 // including the following forms:
@@ -1401,13 +1411,8 @@
 // `PteTy` via source ranges.
 *QualifiersToAppend = PteTy.getQualifiers();
   }
-
-  // Note that TypeLoc.getEndLoc() returns the begin location of the last 
token:
-  SourceRange CSR{
-  PteTyLoc.getBeginLoc(),
-  Lexer::getLocForEndOfToken(PteTyLoc.getEndLoc(), 0, SM, LangOpts)};
-
-  return getRangeText(CSR, SM, LangOpts)->str();
+  return getRangeText({PteTyLoc.getBeginLoc(), PteEndOfTokenLoc}, SM, LangOpts)
+  ->str();
 }
 
 // Returns the text of the name (with qualifiers) of a `FunctionDecl`.


Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp
===
--- 

[clang] 8f54b83 - [clang-format][doc] Replace single back quotes with double ones

2023-07-18 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-07-18T18:27:15-07:00
New Revision: 8f54b8331f9f083220eab06fe903b47115441dbe

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

LOG: [clang-format][doc] Replace single back quotes with double ones

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 8ef58faa76837b..7547aa2a55a71c 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1687,7 +1687,7 @@ the configuration (without a prefix: ``Auto``).
 .. note::
 
  @autoreleasepool and @synchronized blocks are wrapped
- according to `AfterControlStatement` flag.
+ according to ``AfterControlStatement`` flag.
 
   * ``bool AfterStruct`` Wrap struct definitions.
 
@@ -1803,9 +1803,10 @@ the configuration (without a prefix: ``Auto``).
 
   * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put 
on a single line.
 This option is used only if the opening brace of the function has
-already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
+already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
 set, and the function could/should not be put on a single line (as per
-`AllowShortFunctionsOnASingleLine` and constructor formatting options).
+``AllowShortFunctionsOnASingleLine`` and constructor formatting
+options).
 
 .. code-block:: c++
 
@@ -1816,7 +1817,7 @@ the configuration (without a prefix: ``Auto``).
 
   * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct 
or union) body
 can be put on a single line. This option is used only if the opening
-brace of the record has already been wrapped, i.e. the `AfterClass`
+brace of the record has already been wrapped, i.e. the ``AfterClass``
 (for classes) brace wrapping mode is set.
 
 .. code-block:: c++
@@ -1828,7 +1829,7 @@ the configuration (without a prefix: ``Auto``).
 
   * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put 
on a single line.
 This option is used only if the opening brace of the namespace has
-already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
+already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is
 set.
 
 .. code-block:: c++
@@ -1926,9 +1927,9 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakArrays:
 
 **BreakArrays** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ 
`
-  If ``true``, clang-format will always break after a Json array `[`
-  otherwise it will scan until the closing `]` to determine if it should add
-  newlines between elements (prettier compatible).
+  If ``true``, clang-format will always break after a Json array ``[``
+  otherwise it will scan until the closing ``]`` to determine if it should
+  add newlines between elements (prettier compatible).
 
 
   .. note::
@@ -2445,7 +2446,7 @@ the configuration (without a prefix: ``Auto``).
   } // namespace N
 
   * ``BS_Custom`` (in configuration: ``Custom``)
-Configure each individual brace in `BraceWrapping`.
+Configure each individual brace in ``BraceWrapping``.
 
 
 
@@ -3336,9 +3337,9 @@ the configuration (without a prefix: ``Auto``).
 
   .. warning::
 
-   Setting this option to `true` could lead to incorrect code formatting due
-   to clang-format's lack of complete semantic information. As such, extra
-   care should be taken to review code changes made by this option.
+   Setting this option to ``true`` could lead to incorrect code formatting
+   due to clang-format's lack of complete semantic information. As such,
+   extra care should be taken to review code changes made by this option.
 
   .. code-block:: c++
 
@@ -3746,7 +3747,7 @@ the configuration (without a prefix: ``Auto``).
 A(a*b);
 
   will usually be interpreted as a call to a function A, and the
-  multiplication expression will be formatted as `a * b`.
+  multiplication expression will be formatted as ``a * b``.
 
   If we specify the macro definition:
 
@@ -3756,7 +3757,7 @@ the configuration (without a prefix: ``Auto``).
 - A(x)=x
 
   the code will now be parsed as a declaration of the variable b of type a*,
-  and formatted as `a* b` (depending on pointer-binding rules).
+  and formatted as ``a* b`` (depending on pointer-binding rules).
 
   Features and restrictions:
* Both function-like macros and object-like macros are supported.
@@ -4127,7 +4128,7 @@ the configuration (without a prefix: ``Auto``).
 
   .. warning::
 
-   Setting ``QualifierAlignment``  to something other than `Leave`, COULD
+   Setting ``QualifierAlignment``  to 

[PATCH] D155012: Fix types of arm64 MSVC __readx18/__writex18 intrinsics

2023-07-18 Thread Akira Hatanaka 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 rG4ae87b3f8adc: Fix types of arm64 MSVC __readx18/__writex18 
intrinsics (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155012

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/test/CodeGen/arm64-microsoft-intrinsics.c

Index: clang/test/CodeGen/arm64-microsoft-intrinsics.c
===
--- clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -1,9 +1,12 @@
 // RUN: %clang_cc1 -triple arm64-windows -Wno-implicit-function-declaration -fms-compatibility -emit-llvm -o - %s \
-// RUN:| FileCheck %s -check-prefix CHECK-MSVC
+// RUN:| FileCheck %s --check-prefix=CHECK-MSVC --check-prefix=CHECK-MSCOMPAT
 
 // RUN: not %clang_cc1 -triple arm64-linux -Werror -S -o /dev/null %s 2>&1 \
 // RUN:| FileCheck %s -check-prefix CHECK-LINUX
 
+// RUN: %clang_cc1 -triple arm64-darwin -Wno-implicit-function-declaration -fms-compatibility -emit-llvm -o - %s \
+// RUN:| FileCheck %s -check-prefix CHECK-MSCOMPAT
+
 long test_InterlockedAdd(long volatile *Addend, long Value) {
   return _InterlockedAdd(Addend, Value);
 }
@@ -117,128 +120,150 @@
   return reg;
 }
 
-// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata ![[MD2:.*]])
-// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata ![[MD3:.*]])
+// CHECK-MSCOMPAT: call i64 @llvm.read_register.i64(metadata ![[MD2:.*]])
+// CHECK-MSCOMPAT: call i64 @llvm.read_register.i64(metadata ![[MD3:.*]])
+
+#ifdef __LP64__
+#define LONG __int32
+#else
+#define LONG long
+#endif
 
-void check__writex18byte(unsigned long offset, unsigned char data) {
+#ifdef __LP64__
+void check__writex18byte(unsigned char data, unsigned LONG offset) {
+#else
+void check__writex18byte(unsigned LONG offset, unsigned char data) {
+#endif
   __writex18byte(offset, data);
 }
 
-// CHECK-MSVC: %[[DATA_ADDR:.*]] = alloca i8, align 1
-// CHECK-MSVC: %[[OFFSET_ADDR:.*]] = alloca i32, align 4
-// CHECK-MSVC: store i8 %data, ptr %[[DATA_ADDR]], align 1
-// CHECK-MSVC: store i32 %offset, ptr %[[OFFSET_ADDR]], align 4
-// CHECK-MSVC: %[[X18:.*]] = call i64 @llvm.read_register.i64(metadata ![[MD2]])
-// CHECK-MSVC: %[[X18_AS_PTR:.*]] = inttoptr i64 %[[X18]] to ptr
-// CHECK-MSVC: %[[OFFSET:.*]] = load i32, ptr %[[OFFSET_ADDR]], align 4
-// CHECK-MSVC: %[[ZEXT_OFFSET:.*]] = zext i32 %[[OFFSET]] to i64
-// CHECK-MSVC: %[[PTR:.*]] = getelementptr i8, ptr %[[X18_AS_PTR]], i64 %[[ZEXT_OFFSET]]
-// CHECK-MSVC: %[[DATA:.*]] = load i8, ptr %[[DATA_ADDR]], align 1
-// CHECK-MSVC: store i8 %[[DATA]], ptr %[[PTR]], align 1
-
-void check__writex18word(unsigned long offset, unsigned short data) {
+// CHECK-MSCOMPAT: %[[DATA_ADDR:.*]] = alloca i8, align 1
+// CHECK-MSCOMPAT: %[[OFFSET_ADDR:.*]] = alloca i32, align 4
+// CHECK-MSCOMPAT: store i8 %data, ptr %[[DATA_ADDR]], align 1
+// CHECK-MSCOMPAT: store i32 %offset, ptr %[[OFFSET_ADDR]], align 4
+// CHECK-MSCOMPAT: %[[X18:.*]] = call i64 @llvm.read_register.i64(metadata ![[MD2]])
+// CHECK-MSCOMPAT: %[[X18_AS_PTR:.*]] = inttoptr i64 %[[X18]] to ptr
+// CHECK-MSCOMPAT: %[[OFFSET:.*]] = load i32, ptr %[[OFFSET_ADDR]], align 4
+// CHECK-MSCOMPAT: %[[ZEXT_OFFSET:.*]] = zext i32 %[[OFFSET]] to i64
+// CHECK-MSCOMPAT: %[[PTR:.*]] = getelementptr i8, ptr %[[X18_AS_PTR]], i64 %[[ZEXT_OFFSET]]
+// CHECK-MSCOMPAT: %[[DATA:.*]] = load i8, ptr %[[DATA_ADDR]], align 1
+// CHECK-MSCOMPAT: store i8 %[[DATA]], ptr %[[PTR]], align 1
+
+#ifdef __LP64__
+void check__writex18word(unsigned short data, unsigned LONG offset) {
+#else
+void check__writex18word(unsigned LONG offset, unsigned short data) {
+#endif
   __writex18word(offset, data);
 }
 
-// CHECK-MSVC: %[[DATA_ADDR:.*]] = alloca i16, align 2
-// CHECK-MSVC: %[[OFFSET_ADDR:.*]] = alloca i32, align 4
-// CHECK-MSVC: store i16 %data, ptr %[[DATA_ADDR]], align 2
-// CHECK-MSVC: store i32 %offset, ptr %[[OFFSET_ADDR]], align 4
-// CHECK-MSVC: %[[X18:.*]] = call i64 @llvm.read_register.i64(metadata ![[MD2]])
-// CHECK-MSVC: %[[X18_AS_PTR:.*]] = inttoptr i64 %[[X18]] to ptr
-// CHECK-MSVC: %[[OFFSET:.*]] = load i32, ptr %[[OFFSET_ADDR]], align 4
-// CHECK-MSVC: %[[ZEXT_OFFSET:.*]] = zext i32 %[[OFFSET]] to i64
-// CHECK-MSVC: %[[PTR:.*]] = getelementptr i8, ptr %[[X18_AS_PTR]], i64 %[[ZEXT_OFFSET]]
-// CHECK-MSVC: %[[DATA:.*]] = load i16, ptr %[[DATA_ADDR]], align 2
-// CHECK-MSVC: store i16 %[[DATA]], ptr %[[PTR]], align 1
-
-void check__writex18dword(unsigned long offset, unsigned long data) {
+// CHECK-MSCOMPAT: %[[DATA_ADDR:.*]] = alloca i16, align 2
+// CHECK-MSCOMPAT: %[[OFFSET_ADDR:.*]] = alloca i32, align 4
+// CHECK-MSCOMPAT: store i16 %data, ptr %[[DATA_ADDR]], align 2
+// CHECK-MSCOMPAT: store i32 %offset, ptr %[[OFFSET_ADDR]], align 4
+// 

[clang] 4ae87b3 - Fix types of arm64 MSVC __readx18/__writex18 intrinsics

2023-07-18 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2023-07-18T18:16:20-07:00
New Revision: 4ae87b3f8adc35faa3769f2929e51940dd397803

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

LOG: Fix types of arm64 MSVC __readx18/__writex18 intrinsics

Using `L` for type `long` results in clang passing 64-bit integers to
these intrinsics on LP64 operating systems. This isn't correct as the
intrinsics accept 32-bit integers.

Use `N` instead of `L` so that 32-bit integers are passed to the
intrinsics on LP64 operating systems too. This is the same fix as the
following two commits:

33703fb9f908113f93bd9af83a79eb56f5131735
afa47c91ce5085d446ebb5ac1312dc98b6a68a6c

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/test/CodeGen/arm64-microsoft-intrinsics.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index ec635d4dd507b7..eaae6c9ad84686 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -259,15 +259,16 @@ TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 
 TARGET_HEADER_BUILTIN(__break, "vi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
 
-TARGET_HEADER_BUILTIN(__writex18byte,  "vULiUc", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__writex18word,  "vULiUs", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__writex18dword, "vULiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__writex18qword, "vULiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
-
-TARGET_HEADER_BUILTIN(__readx18byte,  "UcULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readx18word,  "UsULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readx18dword, "ULiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readx18qword, "ULLiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
+TARGET_HEADER_BUILTIN(__writex18byte,  "vUNiUc", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__writex18word,  "vUNiUs", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__writex18dword, "vUNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__writex18qword, "vUNiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
+TARGET_HEADER_BUILTIN(__readx18byte,  "UcUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__readx18word,  "UsUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__readx18dword, "UNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__readx18qword, "ULLiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
 #undef BUILTIN
 #undef LANGBUILTIN

diff  --git a/clang/test/CodeGen/arm64-microsoft-intrinsics.c 
b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
index ec5909c77b9624..bd8e4cb27e5268 100644
--- a/clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -1,9 +1,12 @@
 // RUN: %clang_cc1 -triple arm64-windows -Wno-implicit-function-declaration 
-fms-compatibility -emit-llvm -o - %s \
-// RUN:| FileCheck %s -check-prefix CHECK-MSVC
+// RUN:| FileCheck %s --check-prefix=CHECK-MSVC 
--check-prefix=CHECK-MSCOMPAT
 
 // RUN: not %clang_cc1 -triple arm64-linux -Werror -S -o /dev/null %s 2>&1 \
 // RUN:| FileCheck %s -check-prefix CHECK-LINUX
 
+// RUN: %clang_cc1 -triple arm64-darwin -Wno-implicit-function-declaration 
-fms-compatibility -emit-llvm -o - %s \
+// RUN:| FileCheck %s -check-prefix CHECK-MSCOMPAT
+
 long test_InterlockedAdd(long volatile *Addend, long Value) {
   return _InterlockedAdd(Addend, Value);
 }
@@ -117,128 +120,150 @@ unsigned __int64 check__getReg(void) {
   return reg;
 }
 
-// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata ![[MD2:.*]])
-// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata ![[MD3:.*]])
+// CHECK-MSCOMPAT: call i64 @llvm.read_register.i64(metadata ![[MD2:.*]])
+// CHECK-MSCOMPAT: call i64 @llvm.read_register.i64(metadata ![[MD3:.*]])
+
+#ifdef __LP64__
+#define LONG __int32
+#else
+#define LONG long
+#endif
 
-void check__writex18byte(unsigned long offset, unsigned char data) {
+#ifdef __LP64__
+void check__writex18byte(unsigned char data, unsigned LONG offset) {
+#else
+void check__writex18byte(unsigned LONG offset, unsigned char data) {
+#endif
   __writex18byte(offset, data);
 }
 
-// CHECK-MSVC: %[[DATA_ADDR:.*]] = alloca i8, align 1
-// CHECK-MSVC: %[[OFFSET_ADDR:.*]] = alloca i32, align 4
-// CHECK-MSVC: store i8 %data, ptr %[[DATA_ADDR]], align 1
-// CHECK-MSVC: store i32 %offset, ptr %[[OFFSET_ADDR]], align 4
-// CHECK-MSVC: %[[X18:.*]] = call i64 @llvm.read_register.i64(metadata 
![[MD2]])
-// CHECK-MSVC: 

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-07-18 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:8360
+  // Do not constant fold an R-value.
+  if (Info.EvalMode == EvalInfo::EM_ConstantFold && !E->isLValue())
+return false;

nickdesaulniers wrote:
> efriedma wrote:
> > Checking isLValue() doesn't make sense; consider:
> > 
> > ```
> > struct R { mutable long x; };
> > struct Z { const R , y; };
> > Z z = { R{1}, z.x.x=10 };
> > ```
> > 
> > Maybe also want to check for EM_IgnoreSideEffects?  Not sure what cases, if 
> > any, that would affect.
> > 
> > We should probably check `E->getStorageDuration() == SD_Static`.  The cases 
> > where it's a local temporary don't hit the getOrCreateValue() codepath, so 
> > the evaluated value should be handled correctly.
> > 
> > Checking EvalMode feels a little weird, but I guess it should do the right 
> > thing in the cases I can think of?  I'd like a second opinion on this.
> Changing this condition to:
> ```
> if (E->getStorageDuration() == SD_Static &&   
> Info.EvalMode == EvalInfo::EM_ConstantFold && 
> E->isXValue())
>   return false;
> ```
> allows all tests in tree to pass, but messes up the test case you posted 
> above. I'm trying to sus out what else might be different about that test 
> case...we should return `false` for that, but I'm not sure what's different 
> about that case.
> 
> In particular, I was playing with `E->isUsableInConstantExpressions` and 
> `E->getLifetimeExtendedTemporaryDecl()`, but getting your case to work, I end 
> up regressing 
> clang/test/SemaCXX/attr-require-constant-initialization.cpp...argh!!
Shouldn't that just be the following?

```
if (E->getStorageDuration() == SD_Static &&   
Info.EvalMode == EvalInfo::EM_ConstantFold) 
   
  return false;
```

A materialized temporary is always going to be either an LValue or an XValue, 
and the difference between the two isn't relevant here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D155146: [X86] Add SHA512 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked 3 inline comments as done.
FreddyYe added a comment.

I think we can discuss this issue first in https://reviews.llvm.org/D155662


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155146

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


[PATCH] D138810: [RISCV] Support vector crypto extension C intrinsics

2023-07-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4576
+  case RISCVVector::BI__builtin_rvv_vaeskf1_vi_ta:
+  case RISCVVector::BI__builtin_rvv_vsm4k_vi_ta:
+return SemaBuiltinConstantArgRange(TheCall, 1, 0, 31);

craig.topper wrote:
> craig.topper wrote:
> > eopXD wrote:
> > > Valid range of `vaeskf1`, `vaeskf2` seems to be 0 to 15. [0]
> > > Valid range of `vsm4k` seems to be 0 to 7 [1].
> > > 
> > > 
> > > 
> > > [0] 
> > > https://github.com/riscv/riscv-crypto/blob/master/doc/vector/insns/vaeskf1.adoc
> > >  
> > > [1] 
> > > https://github.com/riscv/riscv-crypto/blob/master/doc/vector/insns/vsm4k.adoc
> > I think the field in the instruction is 5 bits, but vaeskf1 and vaeskf2 
> > ignore bit 4. The true valid range is 1-10. The other values are aliased to 
> > one of the valid values. Should the intrinsic interface expose all 32 
> > possible values or just 1-10?
> 1-10 is the valid range for vaeskf1. vaeskf2 is 2-14.
Let's leave it 0-31 for now and maybe start a conversation on crypto or 
intrinsic github.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138810

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


[PATCH] D155146: [X86] Add SHA512 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541793.
FreddyYe added a comment.

Add missing doxygen


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155146

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sha512intrin.h
  clang/test/CodeGen/X86/sha512-builtins.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sha512-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sha512-32.txt
  llvm/test/MC/Disassembler/X86/sha512-64.txt
  llvm/test/MC/X86/sha512-32-att.s
  llvm/test/MC/X86/sha512-32-intel.s
  llvm/test/MC/X86/sha512-64-att.s
  llvm/test/MC/X86/sha512-64-intel.s

Index: llvm/test/MC/X86/sha512-64-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-64-intel.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsha512msg1 ymm12, xmm3
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcc,0xe3]
+  vsha512msg1 ymm12, xmm3
+
+// CHECK: vsha512msg2 ymm12, ymm3
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcd,0xe3]
+  vsha512msg2 ymm12, ymm3
+
+// CHECK: vsha512rnds2 ymm12, ymm3, xmm4
+// CHECK: encoding: [0xc4,0x62,0x67,0xcb,0xe4]
+  vsha512rnds2 ymm12, ymm3, xmm4
+
Index: llvm/test/MC/X86/sha512-64-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-64-att.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
+
+// CHECK: vsha512msg1 %xmm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcc,0xe3]
+  vsha512msg1 %xmm3, %ymm12
+
+// CHECK: vsha512msg2 %ymm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x7f,0xcd,0xe3]
+  vsha512msg2 %ymm3, %ymm12
+
+// CHECK: vsha512rnds2 %xmm4, %ymm3, %ymm12
+// CHECK: encoding: [0xc4,0x62,0x67,0xcb,0xe4]
+  vsha512rnds2 %xmm4, %ymm3, %ymm12
+
Index: llvm/test/MC/X86/sha512-32-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-32-intel.s
@@ -0,0 +1,13 @@
+// RUN: llvm-mc -triple i686 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 ymm2, xmm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 ymm2, xmm3
+
+// CHECK:  vsha512msg2 ymm2, ymm3
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 ymm2, ymm3
+
+// CHECK:  vsha512rnds2 ymm2, ymm3, xmm4
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 ymm2, ymm3, xmm4
Index: llvm/test/MC/X86/sha512-32-att.s
===
--- /dev/null
+++ llvm/test/MC/X86/sha512-32-att.s
@@ -0,0 +1,13 @@
+// RUN: llvm-mc -triple i686 --show-encoding %s | FileCheck %s
+
+// CHECK:  vsha512msg1 %xmm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcc,0xd3]
+   vsha512msg1 %xmm3, %ymm2
+
+// CHECK:  vsha512msg2 %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x7f,0xcd,0xd3]
+   vsha512msg2 %ymm3, %ymm2
+
+// CHECK:  vsha512rnds2 %xmm4, %ymm3, %ymm2
+// CHECK: encoding: [0xc4,0xe2,0x67,0xcb,0xd4]
+   vsha512rnds2 %xmm4, %ymm3, %ymm2
Index: llvm/test/MC/Disassembler/X86/sha512-64.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/sha512-64.txt
@@ -0,0 +1,15 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL
+
+# ATT:   vsha512msg1 %xmm3, %ymm12
+# INTEL: vsha512msg1 ymm12, xmm3
+0xc4,0x62,0x7f,0xcc,0xe3
+
+# ATT:   vsha512msg2 %ymm3, %ymm12
+# INTEL: vsha512msg2 ymm12, ymm3
+0xc4,0x62,0x7f,0xcd,0xe3
+
+# ATT:   vsha512rnds2 %xmm4, %ymm3, %ymm12
+# INTEL: vsha512rnds2 ymm12, ymm3, xmm4
+0xc4,0x62,0x67,0xcb,0xe4
+
Index: llvm/test/MC/Disassembler/X86/sha512-32.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/X86/sha512-32.txt
@@ -0,0 +1,15 @@
+# RUN: llvm-mc --disassemble %s -triple=i386 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=i386 --output-asm-variant=1 | FileCheck %s 

[PATCH] D153059: [-Wunsafe-buffer-usage] Group parameter fix-its

2023-07-18 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud added inline comments.



Comment at: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-multi-parm-span.cpp:306
+  b[5] = 5; // expected-note{{used in buffer access here}}
+}

Can we have a test case with qualifiers on parameters and maybe another with a 
qualifier on the function itself?


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

https://reviews.llvm.org/D153059

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


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: clang/lib/Headers/sm3intrin.h:230
+/// \endcode
+#define _mm_sm3rnds2_epi32(A, B, C, D) 
\
+  (__m128i) __builtin_ia32_vsm3rnds2((__v4su)A, (__v4su)B, (__v4su)C, (int)D)

pengfei wrote:
> Missing `__` for variables.
MACROs prefer no __ for prefix and the operation defines A, B, C, ... So I used 
another naming convention in doxygen for parameters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

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


[PATCH] D155147: [X86] Add SM3 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541792.
FreddyYe marked 5 inline comments as done.
FreddyYe added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155147

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm3intrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/X86/sm3-builtins.c
  clang/test/CodeGen/X86/sm3-error.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm3-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm3-32.txt
  llvm/test/MC/Disassembler/X86/sm3-64.txt
  llvm/test/MC/X86/sm3-att-32.s
  llvm/test/MC/X86/sm3-att-64.s
  llvm/test/MC/X86/sm3-intel-32.s
  llvm/test/MC/X86/sm3-intel-64.s

Index: llvm/test/MC/X86/sm3-intel-64.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm3-intel-64.s
@@ -0,0 +1,86 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xe4]
+  vsm3msg1 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x10,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x10,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x10,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg1 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xe4]
+  vsm3msg2 xmm12, xmm13, xmm4
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x11,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x11,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x11,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm3msg2 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmm4, 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0xe4,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmm4, 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+// CHECK: encoding: [0xc4,0x23,0x11,0xde,0xa4,0xf5,0x00,0x00,0x00,0x10,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+// CHECK: encoding: [0xc4,0x43,0x11,0xde,0xa4,0x80,0x23,0x01,0x00,0x00,0x7b]
+  vsm3rnds2 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291], 123
+
+// CHECK: vsm3rnds2 xmm12, xmm13, xmmword ptr [rip], 123
+// CHECK: encoding: [0xc4,0x63,0x11,0xde,0x25,0x00,0x00,0x00,0x00,0x7b]
+  

[PATCH] D155661: [ASTImporter] Fix recursive friend class template with non-type parm

2023-07-18 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
Herald added subscribers: martong, kristof.beyls.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For friend class template within dependent context:

1. Should not do structure matching checking
2. Should not be added into redecls chain

See `Sema::CheckClassTemplate`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155661

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3969,7 +3969,32 @@
 }
 
 
-struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {};
+struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {
+  void testRecursiveFriendClassTemplate(Decl *FromTu) {
+auto *FromD =
+FirstDeclMatcher().match(FromTu,
+classTemplateDecl());
+auto *ToD = Import(FromD, Lang_CXX03);
+
+auto Pattern = classTemplateDecl(
+has(cxxRecordDecl(has(friendDecl(has(classTemplateDecl()));
+ASSERT_TRUE(MatchVerifier{}.match(FromD, Pattern));
+EXPECT_TRUE(MatchVerifier{}.match(ToD, Pattern));
+
+auto *FromFriend =
+FirstDeclMatcher().match(FromD, friendDecl());
+auto *FromClass =
+FirstDeclMatcher().match(FromD, classTemplateDecl());
+EXPECT_NE(FromFriend->getFriendDecl(), FromClass);
+EXPECT_TRUE(FromFriend->getFriendDecl()->getPreviousDecl() == nullptr);
+
+auto *Class =
+FirstDeclMatcher().match(ToD, classTemplateDecl());
+auto *Friend = FirstDeclMatcher().match(ToD, friendDecl());
+EXPECT_NE(Friend->getFriendDecl(), Class);
+EXPECT_TRUE(Friend->getFriendDecl()->getPreviousDecl() == nullptr);
+  }
+};
 
 TEST_P(ImportFriendClasses, ImportOfFriendRecordDoesNotMergeDefinition) {
   Decl *FromTU = getTuDecl(
@@ -4074,20 +4099,19 @@
   )",
   Lang_CXX03, "input.cc");
 
-  auto *FromD =
-  FirstDeclMatcher().match(FromTu, classTemplateDecl());
-  auto *ToD = Import(FromD, Lang_CXX03);
-
-  auto Pattern = classTemplateDecl(
-  has(cxxRecordDecl(has(friendDecl(has(classTemplateDecl()));
-  ASSERT_TRUE(MatchVerifier{}.match(FromD, Pattern));
-  EXPECT_TRUE(MatchVerifier{}.match(ToD, Pattern));
+  testRecursiveFriendClassTemplate(FromTu);
+}
 
-  auto *Class =
-  FirstDeclMatcher().match(ToD, classTemplateDecl());
-  auto *Friend = FirstDeclMatcher().match(ToD, friendDecl());
-  EXPECT_NE(Friend->getFriendDecl(), Class);
-  EXPECT_EQ(Friend->getFriendDecl()->getPreviousDecl(), Class);
+TEST_P(ImportFriendClasses,
+   ImportOfRecursiveFriendClassTemplateWithNonTypeParm) {
+  Decl *FromTu = getTuDecl(
+  R"(
+  template class declToImport {
+template friend class declToImport;
+  };
+  )",
+  Lang_CXX03, "input.cc");
+  testRecursiveFriendClassTemplate(FromTu);
 }
 
 TEST_P(ImportFriendClasses, ProperPrevDeclForClassTemplateDecls) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2857,6 +2857,10 @@
   } else if (Importer.getToContext().getLangOpts().CPlusPlus)
 IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend;
 
+  bool IsDependentContext = DC != LexicalDC ?
+  LexicalDC->isDependentContext() : DC->isDependentContext();
+  bool ShouldAddRedecl = !(IsFriendTemplate && IsDependentContext);
+
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *PrevDecl = nullptr;
   if (!DC->isFunctionOrMethod() && !D->isLambda()) {
@@ -2897,7 +2901,7 @@
 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
   continue;
 
-if (IsStructuralMatch(D, FoundRecord)) {
+if (!ShouldAddRedecl || IsStructuralMatch(D, FoundRecord)) {
   RecordDecl *FoundDef = FoundRecord->getDefinition();
   if (D->isThisDeclarationADefinition() && FoundDef) {
 // FIXME: Structural equivalence check should check for same
@@ -2955,7 +2959,7 @@
 return CDeclOrErr.takeError();
   Numbering.ContextDecl = *CDeclOrErr;
   D2CXX->setLambdaNumbering(Numbering);
-   } else if (DCXX->isInjectedClassName()) {
+} else if (DCXX->isInjectedClassName()) {
   // We have to be careful to do a similar dance to the one in
   // Sema::ActOnStartCXXMemberDeclarations
   const bool DelayTypeCreation = true;
@@ -2970,7 +2974,9 @@
   if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
   D->getTagKind(), DC, *BeginLocOrErr, Loc,
   Name.getAsIdentifierInfo(),
-  cast_or_null(PrevDecl)))
+ 

[PATCH] D155148: [X86] Add SM4 instructions.

2023-07-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 541787.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

Address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155148

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsX86.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/sm4intrin.h
  clang/test/CodeGen/X86/sm4-builtins.c
  clang/test/CodeGen/attr-target-x86.c
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrSSE.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/sm4-intrinsics.ll
  llvm/test/MC/Disassembler/X86/sm4-32.txt
  llvm/test/MC/Disassembler/X86/sm4-64.txt
  llvm/test/MC/X86/sm4-32-att.s
  llvm/test/MC/X86/sm4-32-intel.s
  llvm/test/MC/X86/sm4-64-att.s
  llvm/test/MC/X86/sm4-64-intel.s

Index: llvm/test/MC/X86/sm4-64-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/sm4-64-intel.s
@@ -0,0 +1,114 @@
+// RUN: llvm-mc -triple x86_64 -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK: vsm4key4 ymm12, ymm13, ymm4
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xe4]
+  vsm4key4 ymm12, ymm13, ymm4
+
+// CHECK: vsm4key4 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xe4]
+  vsm4key4 xmm12, xmm13, xmm4
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x16,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x16,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rip]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [2*rbp - 1024]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0x24,0x6d,0x00,0xfc,0xff,0xff]
+  vsm4key4 ymm12, ymm13, ymmword ptr [2*rbp - 1024]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rcx + 4064]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xa1,0xe0,0x0f,0x00,0x00]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rcx + 4064]
+
+// CHECK: vsm4key4 ymm12, ymm13, ymmword ptr [rdx - 4096]
+// CHECK: encoding: [0xc4,0x62,0x16,0xda,0xa2,0x00,0xf0,0xff,0xff]
+  vsm4key4 ymm12, ymm13, ymmword ptr [rdx - 4096]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x12,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x12,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0x25,0x00,0x00,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rip]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0x24,0x6d,0x00,0xfe,0xff,0xff]
+  vsm4key4 xmm12, xmm13, xmmword ptr [2*rbp - 512]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rcx + 2032]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xa1,0xf0,0x07,0x00,0x00]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rcx + 2032]
+
+// CHECK: vsm4key4 xmm12, xmm13, xmmword ptr [rdx - 2048]
+// CHECK: encoding: [0xc4,0x62,0x12,0xda,0xa2,0x00,0xf8,0xff,0xff]
+  vsm4key4 xmm12, xmm13, xmmword ptr [rdx - 2048]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymm4
+// CHECK: encoding: [0xc4,0x62,0x17,0xda,0xe4]
+  vsm4rnds4 ymm12, ymm13, ymm4
+
+// CHECK: vsm4rnds4 xmm12, xmm13, xmm4
+// CHECK: encoding: [0xc4,0x62,0x13,0xda,0xe4]
+  vsm4rnds4 xmm12, xmm13, xmm4
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+// CHECK: encoding: [0xc4,0x22,0x17,0xda,0xa4,0xf5,0x00,0x00,0x00,0x10]
+  vsm4rnds4 ymm12, ymm13, ymmword ptr [rbp + 8*r14 + 268435456]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+// CHECK: encoding: [0xc4,0x42,0x17,0xda,0xa4,0x80,0x23,0x01,0x00,0x00]
+  vsm4rnds4 ymm12, ymm13, ymmword ptr [r8 + 4*rax + 291]
+
+// CHECK: vsm4rnds4 ymm12, ymm13, ymmword ptr [rip]
+// CHECK: encoding: [0xc4,0x62,0x17,0xda,0x25,0x00,0x00,0x00,0x00]
+  

[clang] b43df5b - PseudoObjectExpr: Prefer ArrayRef over iterator_range when iterating with pointers

2023-07-18 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2023-07-18T23:43:41Z
New Revision: b43df5bfe7e7ef358e135b515b0651ec51f635d8

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

LOG: PseudoObjectExpr: Prefer ArrayRef over iterator_range when iterating with 
pointers

Simpler to use ArrayRef directly here rather than a more
generic/customizable range helper like iterator_range

Added: 


Modified: 
clang/include/clang/AST/Expr.h

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 661a8a7175ca88..7a886f546ed937 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -6356,11 +6356,11 @@ class PseudoObjectExpr final
 return getSubExprsBuffer() + getNumSubExprs();
   }
 
-  llvm::iterator_range semantics() {
-return llvm::make_range(semantics_begin(), semantics_end());
+  ArrayRef semantics() {
+return ArrayRef(semantics_begin(), semantics_end());
   }
-  llvm::iterator_range semantics() const {
-return llvm::make_range(semantics_begin(), semantics_end());
+  ArrayRef semantics() const {
+return ArrayRef(semantics_begin(), semantics_end());
   }
 
   Expr *getSemanticExpr(unsigned index) {



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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D153536#4490918 , @cor3ntin wrote:

> @dblaikie Would you be willing to look at the debugger side of things in a 
> subsequent patch? I'm not familiar with debug symbol code gen so I'm not sure 
> I'd be able to improve thing the right way.

Not sure I've got the time to do the fix myself, but might be able to provide 
pointers.

but at least at a first blush I can't reproduce the failures shown...

  struct t1 {
int _;
int _;
  };
  t1 v1;
  int main() {
int _;
int _;
  }

  0x002e:   DW_TAG_structure_type
  DW_AT_calling_convention(DW_CC_pass_by_value)
  DW_AT_name  ("t1")
  DW_AT_byte_size (0x08)
  DW_AT_decl_file 
("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
  DW_AT_decl_line (1)
  
  0x0034: DW_TAG_member
DW_AT_name("_")
DW_AT_type(0x0047 "int")
DW_AT_decl_file   
("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
DW_AT_decl_line   (2)
DW_AT_data_member_location(0x00)
  
  0x003d: DW_TAG_member
DW_AT_name("_")
DW_AT_type(0x0047 "int")
DW_AT_decl_file   
("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
DW_AT_decl_line   (2)
DW_AT_data_member_location(0x00)
  
  0x0046: NULL
  
  0x0047:   DW_TAG_base_type
  DW_AT_name  ("int")
  DW_AT_encoding  (DW_ATE_signed)
  DW_AT_byte_size (0x04)
  
  0x004b:   DW_TAG_subprogram
  DW_AT_low_pc(0x)
  DW_AT_high_pc   (0x0008)
  DW_AT_frame_base(DW_OP_reg6 RBP)
  DW_AT_name  ("main")
  DW_AT_decl_file 
("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
  DW_AT_decl_line (6)
  DW_AT_type  (0x0047 "int")
  DW_AT_external  (true)
  
  0x005a: DW_TAG_variable
DW_AT_location(DW_OP_fbreg -4)
DW_AT_name("_")
DW_AT_decl_file   
("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
DW_AT_decl_line   (7)
DW_AT_type(0x0047 "int")
  
  0x0065: DW_TAG_variable
DW_AT_location(DW_OP_fbreg -8)
DW_AT_name("_")
DW_AT_decl_file   
("/usr/local/google/home/blaikie/dev/scratch/unused_member.cpp")
DW_AT_decl_line   (8)
DW_AT_type(0x0047 "int")

Looks OK to me - two local variables with the same name, two member variables 
with the same name.

so probably at least one bug in lldb because it does seem to think `t1` has 
only one member. But the DWARF I see for the local variables doesn't seem to 
match the dump shown in https://reviews.llvm.org/D153536#4483191


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D155012: Fix types of arm64 MSVC __readx18/__writex18 intrinsics

2023-07-18 Thread Ravi via Phabricator via cfe-commits
ravikandhadai accepted this revision.
ravikandhadai added a comment.
This revision is now accepted and ready to land.

Thanks Akira. LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155012

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


[PATCH] D154366: [clang][ExprConstant] Print template arguments when describing stack frame

2023-07-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds good to me


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

https://reviews.llvm.org/D154366

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


[PATCH] D152632: [Clang] Add warnings for CWG2521

2023-07-18 Thread PoYao Chang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ce5e983f82c: [Clang] Add warnings for CWG2521 (authored by 
rZhBoYao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152632

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -14933,7 +14933,7 @@
 https://cplusplus.github.io/CWG/issues/2521.html;>2521
 DR
 User-defined literals and reserved identifiers
-Unknown
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/2522.html;>2522
Index: clang/test/CXX/drs/dr25xx.cpp
===
--- clang/test/CXX/drs/dr25xx.cpp
+++ clang/test/CXX/drs/dr25xx.cpp
@@ -1,4 +1,14 @@
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+
+#if __cplusplus < 201103L
+// expected-no-diagnostics
+#endif
 
 namespace dr2516 { // dr2516: yes
// NB: reusing 1482 test
@@ -13,9 +23,13 @@
 
 namespace dr2518 { // dr2518: 17
 
+#if __cplusplus >= 201103L
 template 
 void f(T t) {
   if constexpr (sizeof(T) != sizeof(int)) {
+#if __cplusplus < 201703L
+// expected-error@-2 {{constexpr if is a C++17 extension}}
+#endif
 static_assert(false, "must be int-sized"); // expected-error {{must be int-size}}
   }
 }
@@ -28,6 +42,9 @@
 template 
 struct S {
   static_assert(false); // expected-error {{static assertion failed}}
+#if __cplusplus < 201703L
+// expected-error@-2 {{'static_assert' with no message is a C++17 extension}}
+#endif
 };
 
 template <>
@@ -41,11 +58,31 @@
   S s2;
   S s3; // expected-note {{in instantiation of template class 'dr2518::S' requested here}}
 }
+#endif
 
 }
 
+namespace dr2521 { // dr2521: 17
+#if __cplusplus >= 201103L
+#pragma clang diagnostic push
+#pragma clang diagnostic warning "-Wdeprecated-literal-operator"
+long double operator""  _\u03C0___(long double);
+// expected-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
+// expected-warning@-2 {{user-defined literal suffixes containing '__' are reserved}}
+
+template  decltype(sizeof 0)
+operator""  _div();
+// expected-warning@-1 {{identifier '_div' preceded by whitespace in a literal operator declaration is deprecated}}
+
+using ::dr2521::operator"" _\u03C0___;
+using ::dr2521::operator""_div;
+// expected-warning@-2 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
+#pragma clang diagnostic pop
+#endif
+} // namespace dr2521
 
 namespace dr2565 { // dr2565: 16 open
+#if __cplusplus >= 202002L
   template
 concept C = requires (typename T::type x) {
   x + 1;
@@ -107,4 +144,5 @@
   // expected-error@-1{{static assertion failed}}
   // expected-note@-2{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
 
+#endif
 }
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -502,13 +502,16 @@
 IdentifierInfo *II = Name.Identifier;
 ReservedIdentifierStatus Status = II->isReserved(PP.getLangOpts());
 SourceLocation Loc = Name.getEndLoc();
-if (isReservedInAllContexts(Status) &&
-!PP.getSourceManager().isInSystemHeader(Loc)) {
-  Diag(Loc, diag::warn_reserved_extern_symbol)
-  << II << static_cast(Status)
-  << FixItHint::CreateReplacement(
- Name.getSourceRange(),
- (StringRef("operator\"\"") + II->getName()).str());
+if 

[clang] 5ce5e98 - [Clang] Add warnings for CWG2521

2023-07-18 Thread Po-yao Chang via cfe-commits

Author: Po-yao Chang
Date: 2023-07-19T07:23:34+08:00
New Revision: 5ce5e983f82c802e44faa8ed42d605d70c045ba9

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

LOG: [Clang] Add warnings for CWG2521

1. Teach -Wuser-defined-literals to warn on using double underscores in
   literal suffix identifiers.
2. Add -Wdeprecated-literal-operator to warn about the use of the first
   grammar production of literal-operator-id, which defaults to off for now.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/lib/Basic/IdentifierTable.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/drs/dr25xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cad10dd090263c..7d7c07f818e0fd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -142,6 +142,22 @@ Resolutions to C++ Defect Reports
 ^
 - Implemented `DR2397 `_ which allows ``auto`` 
specifier for pointers
   and reference to arrays.
+- Implemented `CWG2521 `_ which reserves using 
``__`` in user-defined
+  literal suffixes and deprecates literal operator function declarations using 
an identifier.
+  Taught ``-Wuser-defined-literals`` for the former, on by default, and added
+  ``-Wdeprecated-literal-operator`` for the latter, off by default for now.
+
+  .. code-block:: c++
+
+// What follows is warned by -Wuser-defined-literals
+// albeit "ill-formed, no diagnostic required".
+// Its behavior is undefined, [reserved.names.general]p2.
+string operator ""__i18n(const char*, std::size_t);
+
+// Assume this declaration is not in the global namespace.
+// -Wdeprecated-literal-operator diagnoses the extra space.
+string operator "" _i18n(const char*, std::size_t);
+//^ an extra space
 
 C Language Changes
 --

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index c0797166585e44..7b4d415bf06494 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -183,6 +183,7 @@ def DeprecatedCopyWithUserProvidedCopy : 
DiagGroup<"deprecated-copy-with-user-pr
 def DeprecatedCopyWithUserProvidedDtor : 
DiagGroup<"deprecated-copy-with-user-provided-dtor">;
 def DeprecatedCopy : DiagGroup<"deprecated-copy", 
[DeprecatedCopyWithUserProvidedCopy]>;
 def DeprecatedCopyWithDtor : DiagGroup<"deprecated-copy-with-dtor", 
[DeprecatedCopyWithUserProvidedDtor]>;
+def DeprecatedLiteralOperator : DiagGroup<"deprecated-literal-operator">;
 // For compatibility with GCC.
 def : DiagGroup<"deprecated-copy-dtor", [DeprecatedCopyWithDtor]>;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
@@ -220,6 +221,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedEnumFloatConversion,
   DeprecatedBuiltins,
   DeprecatedIncrementBool,
+  DeprecatedLiteralOperator,
   DeprecatedPragma,
   DeprecatedRegister,
   DeprecatedThisCapture,
@@ -865,7 +867,7 @@ def SignedEnumBitfield : DiagGroup<"signed-enum-bitfield">;
 
 def ReservedModuleIdentifier : DiagGroup<"reserved-module-identifier">;
 def ReservedIdentifier : DiagGroup<"reserved-identifier",
-[ReservedIdAsMacro, ReservedModuleIdentifier]>;
+[ReservedIdAsMacro, ReservedModuleIdentifier, UserDefinedLiterals]>;
 
 // Unreachable code warning groups.
 //

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d9932e0aa31a2a..52cca5acfd9245 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -406,6 +406,9 @@ def warn_reserved_extern_symbol: Warning<
   "it starts with '_' followed by a capital letter|"
   "it contains '__'}1">,
   InGroup, DefaultIgnore;
+def warn_deprecated_literal_operator_id: Warning<
+  "identifier %0 preceded by whitespace in a literal operator declaration "
+  "is deprecated">, InGroup, DefaultIgnore;
 def warn_reserved_module_name : Warning<
   "%0 is a reserved name for a module">, InGroup;
 
@@ -9261,8 +9264,8 @@ def 

[PATCH] D155524: [-Wunsafe-buffer-usage] Ignore the FixableGadgets that will not be fixed at an earlier stage

2023-07-18 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1095-1102
   // Gadgets "claim" variables they're responsible for. Once this loop 
finishes,
   // the tracker will only track DREs that weren't claimed by any gadgets,
   // i.e. not understood by the analysis.
   for (const auto  : CB.FixableGadgets) {
 for (const auto *DRE : G->getClaimedVarUseSites()) {
   CB.Tracker.claimUse(DRE);
 }

NoQ wrote:
> Let's also skip this part when there are no warning gadgets? Your initial 
> patch was clearing the `FixableGadgets` list so it was naturally skipped, but 
> now it's active again.
Oh, I intentionally chose not to skip it:
 - 1. To keep the `Tracker` consistent with `CB.FixableGadgets` in case in the 
future we want to use these two objects even if there is no `WarningGadget`; 
 - 2. The `findGadgets` function can stay as straightforward as its name 
suggests.  It doesn't have to know the specific optimization for empty 
`WarningGadget`s.

But the two thoughts above probably aren't important enough.  I will change it 
back to skipping the loop when there is no warnings.




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

https://reviews.llvm.org/D155524

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


[PATCH] D154880: [-Wunsafe-buffer-usage][WIP] Add a facility for debugging low fixit coverage.

2023-07-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2248-2249
+#ifndef NDEBUG
+// FIXME: F->getBaseStmt() should never be null!
+// (Or we should build a better interface for this.)
+Handler.addDebugNoteForVar(

This is my original comment right? It's actually also outdated and should be 
removed, I already erased the runtime check, and I already moved the 
architectural recommendation to implementation of `getBaseStmt()` in individual 
gadgets for which it doesn't make sense.


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

https://reviews.llvm.org/D154880

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


[PATCH] D154880: [-Wunsafe-buffer-usage][WIP] Add a facility for debugging low fixit coverage.

2023-07-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Awesome!!

Did you try running it on some real code? Does this actually cover most cases? 
(I suspect that (1.) is going to be the most popular case, but that's also the 
easiest case to diagnose visually. We might still want a note if we wanted to 
prioritize among non-variables, but that's some work, maybe we can get back to 
this later.)

I have a few minor nitpicks, but generally LGTM!




Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1745-1746
+const StringRef UserFillPlaceHolder,
+UnsafeBufferUsageHandler ) {
   const QualType  = D->getType()->getPointeeType();
   assert(!SpanEltT.isNull() && "Trying to fix a non-pointer type variable!");

We might want to silence `-Wunused-parameter` in release builds.

Maybe it's better to put the entire parameter under `#ifndef NDEBUG`, but it's 
definitely more clumsy.

There's also `__attribute__((unused))` aka `[[maybe_unused]]` but it looks like 
we're not supposed to use it in LLVM for variables:
```
  173 // Some compilers warn about unused functions. When a function is 
sometimes
  174 // used or not depending on build settings (e.g. a function only called 
from
  175 // within "assert"), this attribute can be used to suppress such warnings.
  176 //
  177 // However, it shouldn't be used for unused *variables*, as those have a 
much
  178 // more portable solution:
  179 //   (void)unused_var_name;
  180 // Prefer cast-to-void wherever it is sufficient.
  181 #if __has_attribute(unused)
  182 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
  183 #else
  184 #define LLVM_ATTRIBUTE_UNUSED
  185 #endif
```



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1760-1761
+#ifndef NDEBUG
+  // FIXME: F->getBaseStmt() should never be null!
+  // (Or we should build a better interface for this.)
+  Handler.addDebugNoteForVar(

This comment is probably duplicated everywhere by accident; it doesn't make 
much sense in most of these places.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1790
+  ("failed to produce fixit for declaration '" + D->getName()
+   + "' : fale dto get end char loc (macro)").str());
+#endif





Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2395
+  it->first, it->first->getBeginLoc(),
+  ("'" + it->first->getName() +
+   "' is neither local nor a parameter").str());

`getName()` crashes on various anonymous variables, whereas `getNameAsString()` 
always gives an answer (even if it's not always a "good" answer), which is more 
suitable for diagnostics.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:2396
+  ("'" + it->first->getName() +
+   "' is neither local nor a parameter").str());
+#endif

Do you want to include a "failde to produce fixit..." text in this message and 
the next message, for consistency?


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

https://reviews.llvm.org/D154880

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first

2023-07-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:8360
+  // Do not constant fold an R-value.
+  if (Info.EvalMode == EvalInfo::EM_ConstantFold && !E->isLValue())
+return false;

efriedma wrote:
> Checking isLValue() doesn't make sense; consider:
> 
> ```
> struct R { mutable long x; };
> struct Z { const R , y; };
> Z z = { R{1}, z.x.x=10 };
> ```
> 
> Maybe also want to check for EM_IgnoreSideEffects?  Not sure what cases, if 
> any, that would affect.
> 
> We should probably check `E->getStorageDuration() == SD_Static`.  The cases 
> where it's a local temporary don't hit the getOrCreateValue() codepath, so 
> the evaluated value should be handled correctly.
> 
> Checking EvalMode feels a little weird, but I guess it should do the right 
> thing in the cases I can think of?  I'd like a second opinion on this.
Changing this condition to:
```
if (E->getStorageDuration() == SD_Static &&   
Info.EvalMode == EvalInfo::EM_ConstantFold && 
E->isXValue())
  return false;
```
allows all tests in tree to pass, but messes up the test case you posted above. 
I'm trying to sus out what else might be different about that test case...we 
should return `false` for that, but I'm not sure what's different about that 
case.

In particular, I was playing with `E->isUsableInConstantExpressions` and 
`E->getLifetimeExtendedTemporaryDecl()`, but getting your case to work, I end 
up regressing 
clang/test/SemaCXX/attr-require-constant-initialization.cpp...argh!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword

2023-07-18 Thread Gedare Bloom via Phabricator via cfe-commits
gedare planned changes to this revision.
gedare added a comment.

I need to fix this to reflect the changes in the parent rev.




Comment at: clang/include/clang/Format/Format.h:4208-4213
+/// Put a space in parentheses inside attribute specifier lists.
+/// \code
+///true:  false:
+///__attribute__(( noreturn ))vs. __attribute__((noreturn))
+/// \endcode
+bool InAttributeSpecifierLists;

HazardyKnusperkeks wrote:
> gedare wrote:
> > owenpan wrote:
> > > This should be covered by `SpacesInParetheses`, so we really should not 
> > > have a special option for `__attribute__`.
> > Currently, the behavior of `SpacesInParentheses` does this:
> > ```
> > __attribute__( ( noreturn ) )
> > ```
> > In order to prevent this from happening, it is necessary to add an option 
> > to disable it somehow, because I don't see that this kind of spacing should 
> > ever be used by anyone, but probably someone does it, and it should be 
> > maintained for backward compatibility anyway.
> > Currently, the behavior of `SpacesInParentheses` does this:
> > ```
> > __attribute__( ( noreturn ) )
> > ```
> > In order to prevent this from happening, it is necessary to add an option 
> > to disable it somehow, because I don't see that this kind of spacing should 
> > ever be used by anyone, but probably someone does it, and it should be 
> > maintained for backward compatibility anyway.
> 
> And what does clang-format do before your `SpacesInParentheses`? You should 
> expand the tests to cover the attributes (if they aren't in there already).
`SpacesInParentheses` formats like this: `__attribute__( ( ... ) )`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155529

___
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-18 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added a comment.

In D155239#4509921 , 
@HazardyKnusperkeks wrote:

> If you limit it to `Never` I don't see any value in the differentiation. You 
> could just always use `Custom` (by dropping the custom and only having the 
> nested options).
>
> But I think having at least the `Always` option would be nice. If you want 
> **always** to have a space and you set everything by hand to true, someone 
> comes along and adds a new option (which then is defaulted to `false`) you 
> don't get what you want.

Having `Custom` simplifies detecting if the new options are being used. It is 
possible to add an `Always` option if someone wants it, but that option has not 
existed yet for `clang-format`.




Comment at: clang/lib/Format/Format.cpp:1035
 IO.mapOptional("SpaceInEmptyBlock", Style.SpaceInEmptyBlock);
-IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
 IO.mapOptional("SpacesBeforeTrailingComments",

HazardyKnusperkeks wrote:
> MyDeveloperDay wrote:
> > By removing the old options don’t you break everyone’s clang format file
> You need to parse all of the old options, and map them to the new one, if and 
> only if the old one(s) is/are set and the new is not! See below for the other 
> deprecated options.
Got it, I misunderstood how to handle deprecated options (twice). I think I 
have that sorted now.


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] D155239: [clang-format] Add SpacesInParens with SpacesInParensOptions

2023-07-18 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 541770.
gedare added a comment.

Parse deprecated options and map to new ones.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155239

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -807,7 +807,8 @@
"  if (x)\n"
"x = x;",
Style);
-  Style.SpacesInConditionalStatement = true;
+  Style.SpacesInParens = FormatStyle::SIPO_Custom;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("if ( x )\n"
"  x = x;\n"
"else if ( x )\n"
@@ -903,7 +904,8 @@
   verifyFormat("repeat (x) begin\n"
"end");
   auto Style = getDefaultStyle();
-  Style.SpacesInConditionalStatement = true;
+  Style.SpacesInParens = FormatStyle::SIPO_Custom;
+  Style.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("foreach ( x[x] )\n"
"  x = x;",
Style);
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11031,14 +11031,16 @@
   verifyFormat("template  void operator=(T) && {}", AlignMiddle);
 
   FormatStyle Spaces = getLLVMStyle();
-  Spaces.SpacesInCStyleCastParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("Deleted =(const Deleted &) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;", Spaces);
   verifyFormat("Deleted =(const Deleted &) &;", Spaces);
   verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces);
 
-  Spaces.SpacesInCStyleCastParentheses = false;
-  Spaces.SpacesInParentheses = true;
+  Spaces.SpacesInParensOptions.InCStyleCasts = false;
+  Spaces.SpacesInParensOptions.Other = true;
   verifyFormat("Deleted =( const Deleted & ) & = default;", Spaces);
   verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;",
Spaces);
@@ -13674,7 +13676,8 @@
 
   FormatStyle SpaceBetweenBraces = getLLVMStyle();
   SpaceBetweenBraces.SpacesInAngles = FormatStyle::SIAS_Always;
-  SpaceBetweenBraces.SpacesInParentheses = true;
+  SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
+  SpaceBetweenBraces.SpacesInParensOptions.Other = true;
   SpaceBetweenBraces.SpacesInSquareBrackets = true;
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
@@ -13697,7 +13700,8 @@
 "};",
 format("vectorx{1,2,3,4,};", SpaceBetweenBraces));
   verifyFormat("vector< int > x{};", SpaceBetweenBraces);
-  SpaceBetweenBraces.SpaceInEmptyParentheses = true;
+  SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
+  SpaceBetweenBraces.SpacesInParensOptions.InEmptyParentheses = true;
   verifyFormat("vector< int > x{ };", SpaceBetweenBraces);
 }
 
@@ -16707,10 +16711,13 @@
   verifyFormat("! ! x", Spaces);
 }
 
-TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
+TEST_F(FormatTest, ConfigurableSpacesInParens) {
   FormatStyle Spaces = getLLVMStyle();
 
-  Spaces.SpacesInParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.Other = true;
+  Spaces.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
@@ -16738,8 +16745,9 @@
"}",
Spaces);
 
-  Spaces.SpacesInParentheses = false;
-  Spaces.SpacesInCStyleCastParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  Spaces.SpacesInParensOptions.InCStyleCasts = true;
   verifyFormat("Type *A = ( Type * )P;", Spaces);
   verifyFormat("Type *A = ( vector )P;", Spaces);
   verifyFormat("x = ( int32 )y;", Spaces);
@@ -16750,9 +16758,10 @@
   verifyFormat("#define x (( int )-1)", Spaces);
 
   // Run the first set of tests again with:
-  Spaces.SpacesInParentheses = false;
-  Spaces.SpaceInEmptyParentheses = true;
-  Spaces.SpacesInCStyleCastParentheses = true;
+  Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+  Spaces.SpacesInParensOptions = {};
+  

[PATCH] D155134: [clang][docs] Defensively turn off exception behavior in dump_ast_matchers.py

2023-07-18 Thread Rashmi Mudduluru 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 rG1e62587a48a3: [clang][docs] Defensively turn off exception 
behavior in dump_ast_matchers.py (authored by t-rasmud).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155134

Files:
  clang/docs/tools/dump_ast_matchers.py


Index: clang/docs/tools/dump_ast_matchers.py
===
--- clang/docs/tools/dump_ast_matchers.py
+++ clang/docs/tools/dump_ast_matchers.py
@@ -15,7 +15,8 @@
 try:
 CLASS_INDEX_PAGE = urlopen(CLASS_INDEX_PAGE_URL).read().decode("utf-8")
 except Exception as e:
-raise Exception("Unable to get %s: %s" % (CLASS_INDEX_PAGE_URL, e))
+CLASS_INDEX_PAGE = None
+print("Unable to get %s: %s" % (CLASS_INDEX_PAGE_URL, e))
 
 MATCHERS_FILE = "../../include/clang/ASTMatchers/ASTMatchers.h"
 
@@ -58,7 +59,10 @@
 url = "https://clang.llvm.org/doxygen/classclang_1_1%s.html; % name
 if url not in doxygen_probes:
 search_str = 'href="classclang_1_1%s.html"' % name
-doxygen_probes[url] = search_str in CLASS_INDEX_PAGE
+if CLASS_INDEX_PAGE is not None:
+doxygen_probes[url] = search_str in CLASS_INDEX_PAGE
+else:
+doxygen_probes[url] = True
 if not doxygen_probes[url]:
 print("Did not find %s in class index page" % name)
 if doxygen_probes[url]:
@@ -186,7 +190,7 @@
 """
 if declaration.strip():
 
-if re.match(r"^\s?(#|namespace|using)", declaration):
+if re.match(r"^\s?(#|namespace|using|template  
using|})", declaration):
 return
 
 # Node matchers are defined by writing:


Index: clang/docs/tools/dump_ast_matchers.py
===
--- clang/docs/tools/dump_ast_matchers.py
+++ clang/docs/tools/dump_ast_matchers.py
@@ -15,7 +15,8 @@
 try:
 CLASS_INDEX_PAGE = urlopen(CLASS_INDEX_PAGE_URL).read().decode("utf-8")
 except Exception as e:
-raise Exception("Unable to get %s: %s" % (CLASS_INDEX_PAGE_URL, e))
+CLASS_INDEX_PAGE = None
+print("Unable to get %s: %s" % (CLASS_INDEX_PAGE_URL, e))
 
 MATCHERS_FILE = "../../include/clang/ASTMatchers/ASTMatchers.h"
 
@@ -58,7 +59,10 @@
 url = "https://clang.llvm.org/doxygen/classclang_1_1%s.html; % name
 if url not in doxygen_probes:
 search_str = 'href="classclang_1_1%s.html"' % name
-doxygen_probes[url] = search_str in CLASS_INDEX_PAGE
+if CLASS_INDEX_PAGE is not None:
+doxygen_probes[url] = search_str in CLASS_INDEX_PAGE
+else:
+doxygen_probes[url] = True
 if not doxygen_probes[url]:
 print("Did not find %s in class index page" % name)
 if doxygen_probes[url]:
@@ -186,7 +190,7 @@
 """
 if declaration.strip():
 
-if re.match(r"^\s?(#|namespace|using)", declaration):
+if re.match(r"^\s?(#|namespace|using|template  using|})", declaration):
 return
 
 # Node matchers are defined by writing:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1e62587 - [clang][docs] Defensively turn off exception behavior in dump_ast_matchers.py

2023-07-18 Thread Rashmi Mudduluru via cfe-commits

Author: Rashmi Mudduluru
Date: 2023-07-18T15:36:09-07:00
New Revision: 1e62587a48a33b3bf5939e1eef2fd4e41b7e75f6

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

LOG: [clang][docs] Defensively turn off exception behavior in 
dump_ast_matchers.py

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

Added: 


Modified: 
clang/docs/tools/dump_ast_matchers.py

Removed: 




diff  --git a/clang/docs/tools/dump_ast_matchers.py 
b/clang/docs/tools/dump_ast_matchers.py
index 8ac3c2166d4231..cc7024d1627b97 100755
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -15,7 +15,8 @@
 try:
 CLASS_INDEX_PAGE = urlopen(CLASS_INDEX_PAGE_URL).read().decode("utf-8")
 except Exception as e:
-raise Exception("Unable to get %s: %s" % (CLASS_INDEX_PAGE_URL, e))
+CLASS_INDEX_PAGE = None
+print("Unable to get %s: %s" % (CLASS_INDEX_PAGE_URL, e))
 
 MATCHERS_FILE = "../../include/clang/ASTMatchers/ASTMatchers.h"
 
@@ -58,7 +59,10 @@ def link_if_exists(m):
 url = "https://clang.llvm.org/doxygen/classclang_1_1%s.html; % name
 if url not in doxygen_probes:
 search_str = 'href="classclang_1_1%s.html"' % name
-doxygen_probes[url] = search_str in CLASS_INDEX_PAGE
+if CLASS_INDEX_PAGE is not None:
+doxygen_probes[url] = search_str in CLASS_INDEX_PAGE
+else:
+doxygen_probes[url] = True
 if not doxygen_probes[url]:
 print("Did not find %s in class index page" % name)
 if doxygen_probes[url]:
@@ -186,7 +190,7 @@ def act_on_decl(declaration, comment, allowed_types):
 """
 if declaration.strip():
 
-if re.match(r"^\s?(#|namespace|using)", declaration):
+if re.match(r"^\s?(#|namespace|using|template  
using|})", declaration):
 return
 
 # Node matchers are defined by writing:



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


[PATCH] D155647: [RISCV] Add C intrinsics for scalar crypto

2023-07-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 541759.
craig.topper added a comment.

Fix name of zip/unzip builtin


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155647

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_crypto.h
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c

Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
@@ -4,45 +4,57 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zksh -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSH
 
-#include 
+#include 
 
 // RV32ZKSH-LABEL: @sm3p0(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p0(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV64ZKSH-NEXT:ret i32 [[TMP2]]
 //
 uint32_t sm3p0(uint32_t rs1) {
-  return __builtin_riscv_sm3p0(rs1);
+  return __riscv_sm3p0(rs1);
 }
 
 
 // RV32ZKSH-LABEL: @sm3p1(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p1(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// RV64ZKSH-NEXT:ret i32 [[TMP2]]
 //
 uint32_t sm3p1(uint32_t rs1) {
-  return __builtin_riscv_sm3p1(rs1);
+  return __riscv_sm3p1(rs1);
 }
Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zksed -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSED
 
-#include 

[PATCH] D155304: [clang][docs] Update LibASTMatchersReference.html

2023-07-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a subscriber: ccotter.
NoQ added a comment.

@ccotter: now your matcher is properly documented in 
https://clang.llvm.org/docs/LibASTMatchersReference.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155304

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


[PATCH] D155273: [clang-format] Add TypeNames option to disambiguate types/objects

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

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155273

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


[PATCH] D155304: [clang][docs] Update LibASTMatchersReference.html

2023-07-18 Thread Rashmi Mudduluru 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 rG3ea673a97b05: [clang][docs] Update 
LibASTMatchersReference.html (authored by t-rasmud).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155304

Files:
  clang/docs/LibASTMatchersReference.html

Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1455,6 +1455,16 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoroutineBodyStmtMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoroutineBodyStmt.html;>CoroutineBodyStmt...
+Matches coroutine body statements.
+
+coroutineBodyStmt() matches the coroutine below
+  generatorint gen() {
+co_return;
+  }
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoyieldExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoyieldExpr.html;>CoyieldExpr...
 Matches co_yield expressions.
 
@@ -3037,10 +3047,11 @@
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html;>CXXConstructExprargumentCountAtLeastunsigned N
-Checks that a call expression or a constructor call expression has
-at least the specified number of arguments (including absent default arguments).
+Checks that a call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -3706,10 +3717,11 @@
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html;>CXXUnresolvedConstructExprargumentCountAtLeastunsigned N
-Checks that a call expression or a constructor call expression has
-at least the specified number of arguments (including absent default arguments).
+Checks that a call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -3728,10 +3740,11 @@
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CallExpr.html;>CallExprargumentCountAtLeastunsigned N
-Checks that a call expression or a constructor call expression has
-at least the specified number of arguments (including absent default arguments).
+Checks that a call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -4897,10 +4910,11 @@
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html;>ObjCMessageExprargumentCountAtLeastunsigned N
-Checks that a call expression or a constructor call expression has
-at least the specified number of arguments (including absent default arguments).
+Checks that a call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -6795,9 +6809,10 @@
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html;>CXXForRangeStmthasBodyMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>Stmt InnerMatcher
-Matches a 'for', 'while', 'do' statement or a function definition that has
-a given body. Note that in case of functions this matcher only matches the
-definition itself and not the other declarations of the same function.
+Matches a 'for', 'while', 'while' statement or a function or coroutine
+definition that has a given body. Note that in case of functions or
+coroutines this matcher only matches the definition itself and not the
+other declarations of the same function or coroutine.
 
 Given
   for (;;) {}
@@ -7682,6 +7697,30 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CoroutineBodyStmt.html;>CoroutineBodyStmthasBodyMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>Stmt InnerMatcher
+Matches a 'for', 'while', 'while' 

[clang] 3ea673a - [clang][docs] Update LibASTMatchersReference.html

2023-07-18 Thread Rashmi Mudduluru via cfe-commits

Author: Rashmi Mudduluru
Date: 2023-07-18T15:27:59-07:00
New Revision: 3ea673a97b0583affc22345b9d62e863ba36b3d8

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

LOG: [clang][docs] Update LibASTMatchersReference.html

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index e6b8c771f1a394..bde8ac7de52a73 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1455,6 +1455,16 @@ Node Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoroutineBodyStmtMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoroutineBodyStmt.html;>CoroutineBodyStmt...
+Matches coroutine 
body statements.
+
+coroutineBodyStmt() matches the coroutine below
+  generatorint gen() {
+co_return;
+  }
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoyieldExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoyieldExpr.html;>CoyieldExpr...
 Matches co_yield 
expressions.
 
@@ -3037,10 +3047,11 @@ Narrowing Matchers
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConstructExpr.html;>CXXConstructExprargumentCountAtLeastunsigned 
N
-Checks that a 
call expression or a constructor call expression has
-at least the specified number of arguments (including absent default 
arguments).
+Checks that a 
call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = 
callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -3706,10 +3717,11 @@ Narrowing Matchers
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html;>CXXUnresolvedConstructExprargumentCountAtLeastunsigned 
N
-Checks that a 
call expression or a constructor call expression has
-at least the specified number of arguments (including absent default 
arguments).
+Checks that a 
call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = 
callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -3728,10 +3740,11 @@ Narrowing Matchers
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CallExpr.html;>CallExprargumentCountAtLeastunsigned 
N
-Checks that a 
call expression or a constructor call expression has
-at least the specified number of arguments (including absent default 
arguments).
+Checks that a 
call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = 
callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -4897,10 +4910,11 @@ Narrowing Matchers
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1ObjCMessageExpr.html;>ObjCMessageExprargumentCountAtLeastunsigned 
N
-Checks that a 
call expression or a constructor call expression has
-at least the specified number of arguments (including absent default 
arguments).
+Checks that a 
call expression or a constructor call expression has at least
+the specified number of arguments (including absent default arguments).
 
-Example matches f(0, 0) and g(0, 0, 0) (matcher = 
callExpr(argumentCountAtLeast(2)))
+Example matches f(0, 0) and g(0, 0, 0)
+(matcher = callExpr(argumentCountAtLeast(2)))
   void f(int x, int y);
   void g(int x, int y, int z);
   f(0, 0);
@@ -6795,9 +6809,10 @@ AST Traversal Matchers
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html;>CXXForRangeStmthasBodyMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>Stmt 
InnerMatcher
-Matches a 'for', 'while', 
'do' statement or a function definition that has
-a given body. Note that in case of functions this matcher only matches the
-definition itself and not the other declarations of the same function.
+Matches a 'for', 'while', 
'while' statement or a function or coroutine
+definition that has a given body. Note that in case of functions or
+coroutines this matcher only matches the definition itself and not the
+other declarations of the same function or coroutine.
 
 Given
   for 

[PATCH] D155651: [SystemZ][z/OS] Add OpenFlags to CreateMissingDirectories path when creating temp files

2023-07-18 Thread Tony Tao via Phabricator via cfe-commits
tltao created this revision.
Herald added a project: All.
tltao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Additional patch to https://reviews.llvm.org/D103806 to add the same flags in 
the path where the CreateMissingDirectories booleans is set to true.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155651

Files:
  clang/lib/Frontend/CompilerInstance.cpp


Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -895,10 +895,12 @@
 TempPath += "-";
 TempPath += OutputExtension;
 TempPath += ".tmp";
+llvm::sys::fs::OpenFlags BinaryFlags =
+Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text;
 Expected ExpectedFile =
 llvm::sys::fs::TempFile::create(
 TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,
-Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text);
+BinaryFlags);
 
 llvm::Error E = handleErrors(
 ExpectedFile.takeError(), [&](const llvm::ECError ) -> llvm::Error {
@@ -908,7 +910,9 @@
 StringRef Parent = llvm::sys::path::parent_path(OutputPath);
 EC = llvm::sys::fs::create_directories(Parent);
 if (!EC) {
-  ExpectedFile = llvm::sys::fs::TempFile::create(TempPath);
+  ExpectedFile = llvm::sys::fs::TempFile::create(
+  TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,
+  BinaryFlags);
   if (!ExpectedFile)
 return llvm::errorCodeToError(
 llvm::errc::no_such_file_or_directory);


Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -895,10 +895,12 @@
 TempPath += "-";
 TempPath += OutputExtension;
 TempPath += ".tmp";
+llvm::sys::fs::OpenFlags BinaryFlags =
+Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text;
 Expected ExpectedFile =
 llvm::sys::fs::TempFile::create(
 TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,
-Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text);
+BinaryFlags);
 
 llvm::Error E = handleErrors(
 ExpectedFile.takeError(), [&](const llvm::ECError ) -> llvm::Error {
@@ -908,7 +910,9 @@
 StringRef Parent = llvm::sys::path::parent_path(OutputPath);
 EC = llvm::sys::fs::create_directories(Parent);
 if (!EC) {
-  ExpectedFile = llvm::sys::fs::TempFile::create(TempPath);
+  ExpectedFile = llvm::sys::fs::TempFile::create(
+  TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,
+  BinaryFlags);
   if (!ExpectedFile)
 return llvm::errorCodeToError(
 llvm::errc::no_such_file_or_directory);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155641: [-Wunsafe-buffer-usage] Do not assert that function parameters have names.

2023-07-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I nitpicked to comments, but other than that LGTM, thanks!




Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1890-1891
+  // A parameter of a function definition has no name.
+  // FIXME: We should create a name for the parameter as part of the 
fix-it.
+  // Go through declarations of the function and look for a name?
+  if (!Parm->getIdentifier())

There doesn't have to be a name anywhere, and if it's not there in the 
definition this usually means the parameter is unused. If it's unused, we won't 
ever fix it, and this also means that there's no need to give it a name. So I 
suspect that in the typical case the correct behavior is to just preserve the 
anonymous parameter as-is.

This is just my usual argument: I think the fixit should simply take the part 
that doesn't need fixing from the original code, and include it textually. In 
this case this would mean duplicating the text rather than simply not touching 
it, but that's probably still more precise than writing code from scratch.



Comment at: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp:160
+// CHECK-NOT: fix-it:{{.*}}:
+void parmHasNoName(int *p, int *) { // cannot fix the function because there 
is one parameter has no name.
+  p[5] = 5;

There's no fundamental reason we can't fix this, we just didn't have time yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155641

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


[PATCH] D155524: [-Wunsafe-buffer-usage] Ignore the FixableGadgets that will not be fixed at an earlier stage

2023-07-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:1095-1102
   // Gadgets "claim" variables they're responsible for. Once this loop 
finishes,
   // the tracker will only track DREs that weren't claimed by any gadgets,
   // i.e. not understood by the analysis.
   for (const auto  : CB.FixableGadgets) {
 for (const auto *DRE : G->getClaimedVarUseSites()) {
   CB.Tracker.claimUse(DRE);
 }

Let's also skip this part when there are no warning gadgets? Your initial patch 
was clearing the `FixableGadgets` list so it was naturally skipped, but now 
it's active again.


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

https://reviews.llvm.org/D155524

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


[PATCH] D154382: [ClangRepl] support code completion at a REPL

2023-07-18 Thread Fred Fu via Phabricator via cfe-commits
capfredf updated this revision to Diff 541753.
capfredf added a comment.

Remove unnecessary braces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154382

Files:
  clang/include/clang/Interpreter/CodeCompletion.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/CodeCompletion.cpp
  clang/lib/Interpreter/ExternalSource.cpp
  clang/lib/Interpreter/ExternalSource.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/CodeCompletionTest.cpp

Index: clang/unittests/Interpreter/CodeCompletionTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/CodeCompletionTest.cpp
@@ -0,0 +1,61 @@
+#include "clang/Interpreter/CodeCompletion.h"
+#include "clang/Interpreter/Interpreter.h"
+
+#include "llvm/LineEditor/LineEditor.h"
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "llvm/Support/Error.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+namespace {
+auto CB = clang::IncrementalCompilerBuilder();
+
+static std::unique_ptr createInterpreter() {
+  auto CI = cantFail(CB.CreateCpp());
+  return cantFail(clang::Interpreter::create(std::move(CI)));
+}
+
+TEST(CodeCompletionTest, Sanity) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Completer = ReplListCompleter(CB, *Interp);
+  std::vector comps =
+  Completer(std::string("f"), 1);
+  EXPECT_EQ((size_t)2, comps.size()); // foo and float
+  EXPECT_EQ(comps[0].TypedText, std::string("oo"));
+}
+
+TEST(CodeCompletionTest, SanityNoneValid) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Completer = ReplListCompleter(CB, *Interp);
+  std::vector comps =
+  Completer(std::string("babanana"), 8);
+  EXPECT_EQ((size_t)0, comps.size()); // foo and float
+}
+
+TEST(CodeCompletionTest, TwoDecls) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int application = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  if (auto R = Interp->ParseAndExecute("int apple = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Completer = ReplListCompleter(CB, *Interp);
+  std::vector comps =
+  Completer(std::string("app"), 3);
+  EXPECT_EQ((size_t)2, comps.size());
+}
+} // anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -9,6 +9,7 @@
 add_clang_unittest(ClangReplInterpreterTests
   IncrementalProcessingTest.cpp
   InterpreterTest.cpp
+  CodeCompletionTest.cpp
   )
 target_link_libraries(ClangReplInterpreterTests PUBLIC
   clangAST
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -543,6 +543,7 @@
 case CodeCompletionContext::CCC_PreprocessorExpression:
 case CodeCompletionContext::CCC_PreprocessorDirective:
 case CodeCompletionContext::CCC_Attribute:
+case CodeCompletionContext::CCC_ReplTopLevel:
 case CodeCompletionContext::CCC_TypeQualifiers: {
   //Only Clang results should be accepted, so we'll set all of the other
   //context bits to 0 (i.e. the empty set)
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -13,6 +13,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Interpreter/CodeCompletion.h"
 #include "clang/Interpreter/Interpreter.h"
 
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
@@ -155,8 +156,8 @@
 
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
-// FIXME: Add LE.setListCompleter
 std::string Input;
+LE.setListCompleter(clang::ReplListCompleter(CB, *Interp));
 while (std::optional Line = LE.readLine()) {
   llvm::StringRef L = *Line;
   L = L.trim();
@@ -168,10 +169,10 @@
   }
 
   Input += L;
-
   if 

[PATCH] D155647: [RISCV] Add C intrinsics for scalar crypto

2023-07-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 541752.
craig.topper added a comment.

Fix file description


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155647

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_crypto.h
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c

Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
@@ -4,45 +4,57 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zksh -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSH
 
-#include 
+#include 
 
 // RV32ZKSH-LABEL: @sm3p0(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p0(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV64ZKSH-NEXT:ret i32 [[TMP2]]
 //
 uint32_t sm3p0(uint32_t rs1) {
-  return __builtin_riscv_sm3p0(rs1);
+  return __riscv_sm3p0(rs1);
 }
 
 
 // RV32ZKSH-LABEL: @sm3p1(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p1(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// RV64ZKSH-NEXT:ret i32 [[TMP2]]
 //
 uint32_t sm3p1(uint32_t rs1) {
-  return __builtin_riscv_sm3p1(rs1);
+  return __riscv_sm3p1(rs1);
 }
Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zksed -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSED
 
-#include 

[PATCH] D155647: [RISCV] Add C intrinsics for scalar crypto

2023-07-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 541751.
craig.topper added a comment.

git add the header


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155647

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_crypto.h
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c

Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
@@ -4,45 +4,57 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zksh -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSH
 
-#include 
+#include 
 
 // RV32ZKSH-LABEL: @sm3p0(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p0(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV64ZKSH-NEXT:ret i32 [[TMP2]]
 //
 uint32_t sm3p0(uint32_t rs1) {
-  return __builtin_riscv_sm3p0(rs1);
+  return __riscv_sm3p0(rs1);
 }
 
 
 // RV32ZKSH-LABEL: @sm3p1(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p1(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// RV64ZKSH-NEXT:ret i32 [[TMP2]]
 //
 uint32_t sm3p1(uint32_t rs1) {
-  return __builtin_riscv_sm3p1(rs1);
+  return __riscv_sm3p1(rs1);
 }
Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zksed -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSED
 
-#include 
+#include 

[PATCH] D155647: [RISCV] Add C intrinsics for scalar crypto

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

This adds riscv_crypto.h

This is based on the proposed spec here 
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/44

Tests that previously used builtins directly now use the intrinsics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155647

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c

Index: clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
===
--- clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
+++ clang/test/CodeGen/RISCV/rvk-intrinsics/zksh.c
@@ -4,45 +4,57 @@
 // RUN: %clang_cc1 -triple riscv64 -target-feature +zksh -emit-llvm %s -o - \
 // RUN: | FileCheck %s  -check-prefix=RV64ZKSH
 
-#include 
+#include 
 
 // RV32ZKSH-LABEL: @sm3p0(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p0(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p0(i32 [[TMP1]])
+// RV64ZKSH-NEXT:ret i32 [[TMP2]]
 //
 uint32_t sm3p0(uint32_t rs1) {
-  return __builtin_riscv_sm3p0(rs1);
+  return __riscv_sm3p0(rs1);
 }
 
 
 // RV32ZKSH-LABEL: @sm3p1(
 // RV32ZKSH-NEXT:  entry:
+// RV32ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV32ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV32ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV32ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV32ZKSH-NEXT:ret i32 [[TMP1]]
+// RV32ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV32ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// RV32ZKSH-NEXT:ret i32 [[TMP2]]
 //
 // RV64ZKSH-LABEL: @sm3p1(
 // RV64ZKSH-NEXT:  entry:
+// RV64ZKSH-NEXT:[[__X_ADDR_I:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:[[RS1_ADDR:%.*]] = alloca i32, align 4
 // RV64ZKSH-NEXT:store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
 // RV64ZKSH-NEXT:[[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
-// RV64ZKSH-NEXT:[[TMP1:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP0]])
-// RV64ZKSH-NEXT:ret i32 [[TMP1]]
+// RV64ZKSH-NEXT:store i32 [[TMP0]], ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP1:%.*]] = load i32, ptr [[__X_ADDR_I]], align 4
+// RV64ZKSH-NEXT:[[TMP2:%.*]] = call i32 @llvm.riscv.sm3p1(i32 [[TMP1]])
+// 

[PATCH] D154880: [-Wunsafe-buffer-usage][WIP] Add a facility for debugging low fixit coverage.

2023-07-18 Thread Rashmi Mudduluru via Phabricator via cfe-commits
t-rasmud updated this revision to Diff 541745.
t-rasmud added a comment.

This patch addresses cases 2, 3, and 4 described in the summary (i.e) adds 
debug notes for unclaimed uses of variables and for failed fixit generation of 
variable declarations.


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

https://reviews.llvm.org/D154880

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -verify=expected %s
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -verify=expected,debug %s
+
+// A generic -debug would also enable our notes. This is probably fine.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-std=c++20 -mllvm -debug \
+// RUN:-verify=expected,debug %s
+
+// This test file checks the behavior under the assumption that no fixits
+// were emitted for the test cases. If -Wunsafe-buffer-usage is improved
+// to support these cases (thus failing the test), the test should be changed
+// to showcase a different unsupported example.
+//
+// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
+// RUN:-mllvm -debug-only=SafeBuffers \
+// RUN:-std=c++20 -fdiagnostics-parseable-fixits %s \
+// RUN:2>&1 | FileCheck %s
+// CHECK-NOT: fix-it:
+
+// This debugging facility is only available in debug builds.
+//
+// REQUIRES: asserts
+
+void foo() {
+  int *x = new int[10]; // expected-warning{{'x' is an unsafe pointer used for buffer access}}
+  x[5] = 10;// expected-note{{used in buffer access here}}
+  int z = x[-1];// expected-note{{used in buffer access here}} \
+// debug-note{{safe buffers debug: gadget 'ULCArraySubscript' refused to produce a fix}}
+}
+
+void failed_decl() {
+  int a[10];  // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : not a pointer}}
+  
+  for (int i = 0; i < 10; i++) {
+a[i] = i;  // expected-note{{used in buffer access here}}
+  }
+}
+
+void failed_multiple_decl() {
+  int *a = new int[4], b;  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : multiple VarDecls}}
+  a[4] = 3;  // expected-note{{used in buffer access here}}
+}
+
+void failed_param_var_decl(int *a =new int[3]) {  // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
+  // debug-note{{safe buffers debug: failed to produce fixit for parm var decl 'a' : has default arg}}
+  a[4] = 6;  // expected-note{{used in buffer access here}}
+}
+
+void unclaimed_use() {
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[2] = 9;  // expected-note{{used in buffer access here}}
+  int *b = a++;  // expected-note{{used in pointer arithmetic here}} \
+  // debug-note{{safe buffers debug: 'a' has an unclaimed use}}
+}
+
+void implied_unclaimed_var(int *b) {  // expected-warning{{'b' is an unsafe pointer used for buffer access}}
+  int *a = new int[3];  // expected-warning{{'a' is an unsafe pointer used for buffer access}}
+  a[4] = 7;  // expected-note{{used in buffer access here}}
+  a = b;  // debug-note{{safe buffers debug: gadget 'PointerAssignment' refused to produce a fix}}
+  b++;  // expected-note{{used in pointer arithmetic here}} \
+// debug-note{{safe buffers debug: 'b' has an unclaimed use}}
+}
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2276,6 +2276,12 @@
   for (const auto  : Fixes)
 FD << F;
 }
+
+#ifndef NDEBUG
+if (areDebugNotesRequested())
+  for (const DebugNote : DebugNotesByVar[Variable])
+S.Diag(Note.first, diag::note_safe_buffer_debug_mode) << Note.second;
+#endif
   }
 
   bool isSafeBufferOptOut(const SourceLocation ) const override {
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -319,6 +319,15 @@
 
   Kind 

[PATCH] D155636: [clang][dataflow] Add function to `WatchedLiteralsSolver` that reports whether the iteration limit has been reached.

2023-07-18 Thread Yitzhak Mandelbaum 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 rG1defa781243f: [clang][dataflow] Add function to 
`WatchedLiteralsSolver` that reports whether… (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155636

Files:
  clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -350,4 +350,23 @@
   EXPECT_EQ(solver.solve({A, B}).getStatus(), 
Solver::Result::Status::TimedOut);
 }
 
+TEST(SolverTest, ReachedLimitsReflectsTimeouts) {
+  WatchedLiteralsSolver solver(10);
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto Z = Ctx.atom();
+  auto W = Ctx.atom();
+
+  // !(X v Y) <=> !X ^ !Y
+  auto A = Ctx.iff(Ctx.neg(Ctx.disj(X, Y)), Ctx.conj(Ctx.neg(X), Ctx.neg(Y)));
+
+  // !(Z ^ W) <=> !Z v !W
+  auto B = Ctx.iff(Ctx.neg(Ctx.conj(Z, W)), Ctx.disj(Ctx.neg(Z), Ctx.neg(W)));
+
+  // A ^ B
+  ASSERT_EQ(solver.solve({A, B}).getStatus(), 
Solver::Result::Status::TimedOut);
+  EXPECT_TRUE(solver.reachedLimit());
+}
+
 } // namespace
Index: clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
===
--- clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
+++ clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
@@ -47,6 +47,9 @@
   : MaxIterations(WorkLimit) {}
 
   Result solve(llvm::ArrayRef Vals) override;
+
+  // The solver reached its maximum number of iterations.
+  bool reachedLimit() const { return MaxIterations == 0; }
 };
 
 } // namespace dataflow


Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -350,4 +350,23 @@
   EXPECT_EQ(solver.solve({A, B}).getStatus(), Solver::Result::Status::TimedOut);
 }
 
+TEST(SolverTest, ReachedLimitsReflectsTimeouts) {
+  WatchedLiteralsSolver solver(10);
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto Z = Ctx.atom();
+  auto W = Ctx.atom();
+
+  // !(X v Y) <=> !X ^ !Y
+  auto A = Ctx.iff(Ctx.neg(Ctx.disj(X, Y)), Ctx.conj(Ctx.neg(X), Ctx.neg(Y)));
+
+  // !(Z ^ W) <=> !Z v !W
+  auto B = Ctx.iff(Ctx.neg(Ctx.conj(Z, W)), Ctx.disj(Ctx.neg(Z), Ctx.neg(W)));
+
+  // A ^ B
+  ASSERT_EQ(solver.solve({A, B}).getStatus(), Solver::Result::Status::TimedOut);
+  EXPECT_TRUE(solver.reachedLimit());
+}
+
 } // namespace
Index: clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
===
--- clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
+++ clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
@@ -47,6 +47,9 @@
   : MaxIterations(WorkLimit) {}
 
   Result solve(llvm::ArrayRef Vals) override;
+
+  // The solver reached its maximum number of iterations.
+  bool reachedLimit() const { return MaxIterations == 0; }
 };
 
 } // namespace dataflow
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1defa78 - [clang][dataflow] Add function to `WatchedLiteralsSolver` that reports whether the iteration limit has been reached.

2023-07-18 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2023-07-18T21:43:55Z
New Revision: 1defa781243f9d0bc66719465e4de33e9fb7a243

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

LOG: [clang][dataflow] Add function to `WatchedLiteralsSolver` that reports 
whether the iteration limit has been reached.

This change provides a centralized record of whether the solver is
"exhausted". In general, once the solver is exhausted, further uses do not
produce meaningful conclusions. Clients can use this information, for example,
to choose to discard all results based on the solver, instead of trying to
distinguish those reached before the limit was reached. Providing it at in the
solver avoids the need to propagate it from each callsite to the client of the
solver.

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h 
b/clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
index a0cdce93c9d470..5448eecf6d41a2 100644
--- a/clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
+++ b/clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
@@ -47,6 +47,9 @@ class WatchedLiteralsSolver : public Solver {
   : MaxIterations(WorkLimit) {}
 
   Result solve(llvm::ArrayRef Vals) override;
+
+  // The solver reached its maximum number of iterations.
+  bool reachedLimit() const { return MaxIterations == 0; }
 };
 
 } // namespace dataflow

diff  --git a/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
index ba0a77a910d7c4..28f4adb2d39354 100644
--- a/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -350,4 +350,23 @@ TEST(SolverTest, LowTimeoutResultsInTimedOut) {
   EXPECT_EQ(solver.solve({A, B}).getStatus(), 
Solver::Result::Status::TimedOut);
 }
 
+TEST(SolverTest, ReachedLimitsReflectsTimeouts) {
+  WatchedLiteralsSolver solver(10);
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto Z = Ctx.atom();
+  auto W = Ctx.atom();
+
+  // !(X v Y) <=> !X ^ !Y
+  auto A = Ctx.iff(Ctx.neg(Ctx.disj(X, Y)), Ctx.conj(Ctx.neg(X), Ctx.neg(Y)));
+
+  // !(Z ^ W) <=> !Z v !W
+  auto B = Ctx.iff(Ctx.neg(Ctx.conj(Z, W)), Ctx.disj(Ctx.neg(Z), Ctx.neg(W)));
+
+  // A ^ B
+  ASSERT_EQ(solver.solve({A, B}).getStatus(), 
Solver::Result::Status::TimedOut);
+  EXPECT_TRUE(solver.reachedLimit());
+}
+
 } // namespace



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


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

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155414

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


[PATCH] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute

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



Comment at: clang/lib/AST/ExprConstant.cpp:9591-9594
+  bool IsMSConstexpr = Info.CurrentCall->CanEvalMSConstexpr &&
+   OperatorNew->hasAttr();
   if (OperatorNew->isReservedGlobalPlacementOperator() &&
+  (Info.CurrentCall->isStdFunction() || IsMSConstexpr) && !E->isArray()) {

Do we really need this change? Was our existing check of whether the caller is 
in namespace `std` not sufficient for MS' standard library? I'd strongly prefer 
not to have a documented, user-visible attribute that gives permission to use 
placement new directly.


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] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute

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



Comment at: clang/lib/AST/ExprConstant.cpp:5615-5627
+if (canEvalMSConstexpr || isMSConstexpr) {
+  // Diagnose invalid usage of [[msvc::constexpr]] function
+  bool isConstructor = isa(Definition);
+  if (canEvalMSConstexpr) { // !isMSConstexpr
+Info.FFDiag(CallLoc, diag::note_constexpr_invalid_function, 1)
+<< /*IsConstexpr*/ 0 << isConstructor << Definition;
+Info.Note(Definition->getLocation(), diag::note_declared_at);

Given that the intended use case is for usage behind the scenes in the standard 
library, I don't think we should be changing our diagnostic output at all here. 
If the library, as an implementation detail, marks a non-`constexpr` function 
as `[[msvc::constexpr]]`, we shouldn't tell the user to add 
`[[msvc::constexpr]]` to their code to allow it to be called, after all, the 
annotation is an implementation detail of the MS standard library.


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] D155642: Unconditionally include intrinsic headers in MSVC mode

2023-07-18 Thread Alexander Neumann via Phabricator via cfe-commits
Neumann-A created this revision.
Herald added a project: All.
Neumann-A requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Even though there is a significant compile time overhead for all users being a 
true drop in replacement for cl requires including the intrinsic headers 
without a guard.

Github issues (there are probably more related):
https://github.com/llvm/llvm-project/issues/53520
https://github.com/llvm/llvm-project/issues/63492


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155642

Files:
  clang/lib/Headers/bmiintrin.h
  clang/lib/Headers/immintrin.h
  clang/lib/Headers/keylockerintrin.h
  clang/lib/Headers/x86gprintrin.h
  clang/lib/Headers/x86intrin.h

Index: clang/lib/Headers/x86intrin.h
===
--- clang/lib/Headers/x86intrin.h
+++ clang/lib/Headers/x86intrin.h
@@ -14,52 +14,52 @@
 
 #include 
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__3dNOW__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__PRFCHW__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__SSE4A__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__FMA4__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__XOP__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__TBM__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__LWP__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__MWAITX__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CLZERO__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__RDPRU__)
 #include 
 #endif
Index: clang/lib/Headers/x86gprintrin.h
===
--- clang/lib/Headers/x86gprintrin.h
+++ clang/lib/Headers/x86gprintrin.h
@@ -10,32 +10,32 @@
 #ifndef __X86GPRINTRIN_H
 #define __X86GPRINTRIN_H
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__HRESET__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__UINTR__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CRC32__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__PRFCHI__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__RAOINT__)
 #include 
 #endif
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__CMPCCXADD__)
 #include 
 #endif
Index: clang/lib/Headers/keylockerintrin.h
===
--- clang/lib/Headers/keylockerintrin.h
+++ clang/lib/Headers/keylockerintrin.h
@@ -28,7 +28,7 @@
 #ifndef _KEYLOCKERINTRIN_H
 #define _KEYLOCKERINTRIN_H
 
-#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  \
+#if defined(_MSC_VER) || !defined(__SCE__) || __has_feature(modules) ||  \
 defined(__KL__)
 
 /* Define the 

[PATCH] D155273: [clang-format] Add TypeNames option to disambiguate types/objects

2023-07-18 Thread Owen Pan 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 rG5c106f7b947e: [clang-format] Add TypeNames option to 
disambiguate types/objects (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155273

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -272,6 +272,19 @@
   Tokens = annotate("template * = nullptr> void f();");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[5], tok::ampamp, TT_BinaryOperator);
+
+  FormatStyle Style = getLLVMStyle();
+  Style.TypeNames.push_back("MYI");
+  Tokens = annotate("if (MYI *p{nullptr})", Style);
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_TypeName);
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Style.TypeNames.push_back("Class");
+  Tokens = annotate("if (Class *obj {getObj()})", Style);
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_TypeName);
+  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -422,6 +422,7 @@
   FormatToken *PrevPrev = Prev->getPreviousNonComment();
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
+  PrevPrev->isNot(TT_TypeName) &&
   Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
   CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
 Prev->setType(TT_BinaryOperator);
@@ -2508,6 +2509,8 @@
 const FormatToken *PrevToken = Tok.getPreviousNonComment();
 if (!PrevToken)
   return TT_UnaryOperator;
+if (PrevToken->is(TT_TypeName))
+  return TT_PointerOrReference;
 
 const FormatToken *NextToken = Tok.getNextNonComment();
 
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Regex.h"
 
@@ -126,6 +127,8 @@
 
   llvm::SmallMapVector Macros;
 
+  llvm::SmallPtrSet TypeNames;
+
   bool FormattingDisabled;
 
   llvm::Regex MacroBlockBeginRegex;
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -71,6 +71,9 @@
 auto Identifier = (StatementAttributeLikeMacro);
 Macros.insert({Identifier, TT_StatementAttributeLikeMacro});
   }
+
+  for (const auto  : Style.TypeNames)
+TypeNames.insert((TypeName));
 }
 
 ArrayRef FormatTokenLexer::lex() {
@@ -1222,7 +1225,8 @@
   }
 
   if (Style.isCpp()) {
-auto it = Macros.find(FormatTok->Tok.getIdentifierInfo());
+auto *Identifier = FormatTok->Tok.getIdentifierInfo();
+auto it = Macros.find(Identifier);
 if (!(Tokens.size() > 0 && Tokens.back()->Tok.getIdentifierInfo() &&
   Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() ==
   tok::pp_define) &&
@@ -1240,6 +1244,8 @@
 FormatTok->setType(TT_MacroBlockBegin);
   else if (MacroBlockEndRegex.match(Text))
 FormatTok->setType(TT_MacroBlockEnd);
+  else if (TypeNames.contains(Identifier))
+FormatTok->setFinalizedType(TT_TypeName);
 }
   }
 
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -141,6 +141,7 @@
   TYPE(TrailingReturnArrow)\
   TYPE(TrailingUnaryOperator)  \
   TYPE(TypeDeclarationParen)   \
+  TYPE(TypeName)   \
   TYPE(TypenameMacro)  \
   

[clang] 5c106f7 - [clang-format] Add TypeNames option to disambiguate types/objects

2023-07-18 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-07-18T14:18:40-07:00
New Revision: 5c106f7b947e514852402ad5678c0ebf70ce91b1

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

LOG: [clang-format] Add TypeNames option to disambiguate types/objects

If a non-keyword identifier is found in TypeNames, then a *, &, or && that
follows it is annotated as TT_PointerOrReference.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 8965b20e62c641..8ef58faa76837b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5355,6 +5355,15 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TypeNames:
+
+**TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
+  A vector of non-keyword identifiers that should be interpreted as type
+  names.
+
+  A `*`, `&`, or `&&` between a type name and another non-keyword identifier
+  is annotated as a pointer or reference token instead of a binary operator.
+
 .. _TypenameMacros:
 
 **TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9` 
:ref:`¶ `

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dd316a7a82e353..cad10dd090263c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -876,6 +876,7 @@ clang-format
   the indentation level of the contents of braced init lists.
 - Add ``KeepEmptyLinesAtEOF`` to keep empty lines at end of file.
 - Add ``RemoveParentheses`` to remove redundant parentheses.
+- Add ``TypeNames`` to treat listed non-keyword identifiers as type names.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 71948027fbe3ed..874f10b0c57fc2 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4265,6 +4265,15 @@ struct FormatStyle {
   /// \version 3.7
   unsigned TabWidth;
 
+  /// A vector of non-keyword identifiers that should be interpreted as type
+  /// names.
+  ///
+  /// A `*`, `&`, or `&&` between a type name and another non-keyword 
identifier
+  /// is annotated as a pointer or reference token instead of a binary 
operator.
+  ///
+  /// \version 17
+  std::vector TypeNames;
+
   /// \brief A vector of macros that should be interpreted as type declarations
   /// instead of as function calls.
   ///
@@ -4492,7 +4501,8 @@ struct FormatStyle {
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypenameMacros == R.TypenameMacros && UseTab == R.UseTab &&
+   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
+   UseTab == R.UseTab &&
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c71139d26ff80d..3df1b60d2cb958 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1051,6 +1051,7 @@ template <> struct MappingTraits {
Style.StatementAttributeLikeMacros);
 IO.mapOptional("StatementMacros", Style.StatementMacros);
 IO.mapOptional("TabWidth", Style.TabWidth);
+IO.mapOptional("TypeNames", Style.TypeNames);
 IO.mapOptional("TypenameMacros", Style.TypenameMacros);
 IO.mapOptional("UseTab", Style.UseTab);
 IO.mapOptional("VerilogBreakBetweenInstancePorts",

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index a7f2a01683fb38..4e45478d7424e6 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -141,6 +141,7 @@ namespace format {
   TYPE(TrailingReturnArrow)
\
   TYPE(TrailingUnaryOperator)  
\
   TYPE(TypeDeclarationParen)   
\
+  TYPE(TypeName)   
\
   TYPE(TypenameMacro) 

[PATCH] D134588: [clang-tidy] Fix bugprone-exception-escape warn on noexcept calls

2023-07-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL abandoned this revision.
PiotrZSL added a comment.

Already fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134588

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


[PATCH] D155641: [-Wunsafe-buffer-usage] Do not assert that function parameters have names.

2023-07-18 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: jkorous, NoQ, t-rasmud, malavikasamak.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It is possible that a function parameter does not have a name even in a 
function definition. 
So we should not assert that function parameters always have names.

This patch lets the analysis give up on generating fix-its in cases where a 
function parameter of a definition has no name.
Later we can come up with a better solution, e.g., generating a name for the 
parameter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155641

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp


Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
@@ -156,4 +156,9 @@
   if (++MyName){}
 }
 
+// CHECK-NOT: fix-it:{{.*}}:
+void parmHasNoName(int *p, int *) { // cannot fix the function because there 
is one parameter has no name.
+  p[5] = 5;
+}
+
 #endif
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1886,8 +1886,11 @@
 
   if (Parm->isImplicit())
 continue;
-  assert(Parm->getIdentifier() &&
- "A parameter of a function definition has no name");
+  // A parameter of a function definition has no name.
+  // FIXME: We should create a name for the parameter as part of the 
fix-it.
+  // Go through declarations of the function and look for a name?
+  if (!Parm->getIdentifier())
+return std::nullopt;
   if (i == ParmIdx)
 // This is our spanified paramter!
 SS << NewTypeText.str() << "(" << 
Parm->getIdentifier()->getName().str() << ", "


Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
@@ -156,4 +156,9 @@
   if (++MyName){}
 }
 
+// CHECK-NOT: fix-it:{{.*}}:
+void parmHasNoName(int *p, int *) { // cannot fix the function because there is one parameter has no name.
+  p[5] = 5;
+}
+
 #endif
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1886,8 +1886,11 @@
 
   if (Parm->isImplicit())
 continue;
-  assert(Parm->getIdentifier() &&
- "A parameter of a function definition has no name");
+  // A parameter of a function definition has no name.
+  // FIXME: We should create a name for the parameter as part of the fix-it.
+  // Go through declarations of the function and look for a name?
+  if (!Parm->getIdentifier())
+return std::nullopt;
   if (i == ParmIdx)
 // This is our spanified paramter!
 SS << NewTypeText.str() << "(" << Parm->getIdentifier()->getName().str() << ", "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153423: [clang-tidy] Allow explicit throwing in bugprone-exception-escape for special functions

2023-07-18 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff40c3488177: [clang-tidy] Allow explicit throwing in 
bugprone-exception-escape for special… (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D153423?vs=534059=541727#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153423

Files:
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
  clang/include/clang/Basic/ExceptionSpecificationType.h

Index: clang/include/clang/Basic/ExceptionSpecificationType.h
===
--- clang/include/clang/Basic/ExceptionSpecificationType.h
+++ clang/include/clang/Basic/ExceptionSpecificationType.h
@@ -50,6 +50,11 @@
   return ESpecType == EST_Unevaluated || ESpecType == EST_Uninstantiated;
 }
 
+inline bool isExplicitThrowExceptionSpec(ExceptionSpecificationType ESpecType) {
+  return ESpecType == EST_Dynamic || ESpecType == EST_MSAny ||
+ ESpecType == EST_NoexceptFalse;
+}
+
 /// Possible results from evaluation of a noexcept expression.
 enum CanThrowResult {
   CT_Cannot,
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
@@ -722,3 +722,27 @@
   test_basic_throw();
 }
 
+namespace PR55143 { namespace PR40583 {
+
+struct test_explicit_throw {
+test_explicit_throw() throw(int) { throw 42; }
+test_explicit_throw(const test_explicit_throw&) throw(int) { throw 42; }
+test_explicit_throw(test_explicit_throw&&) throw(int) { throw 42; }
+test_explicit_throw& operator=(const test_explicit_throw&) throw(int) { throw 42; }
+test_explicit_throw& operator=(test_explicit_throw&&) throw(int) { throw 42; }
+~test_explicit_throw() throw(int) { throw 42; }
+};
+
+struct test_implicit_throw {
+test_implicit_throw() { throw 42; }
+test_implicit_throw(const test_implicit_throw&) { throw 42; }
+test_implicit_throw(test_implicit_throw&&) { throw 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'test_implicit_throw' which should not throw exceptions
+test_implicit_throw& operator=(const test_implicit_throw&) { throw 42; }
+test_implicit_throw& operator=(test_implicit_throw&&) { throw 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: an exception may be thrown in function 'operator=' which should not throw exceptions
+~test_implicit_throw() { throw 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function '~test_implicit_throw' which should not throw exceptions
+};
+
+}}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp
@@ -183,7 +183,6 @@
 
 struct Evil {
   ~Evil() noexcept(false) {
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function '~Evil' which should not throw exceptions
 throw 42;
   }
 };
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
@@ -22,6 +22,12 @@
 operations are also used to create move operations. A throwing ``main()``
 function also results in unexpected termination.
 
+Functions declared explicitly with ``noexcept(false)`` or ``throw(exception)``
+will be excluded from the analysis, as even though it is not recommended for
+functions like ``swap()``, ``main()``, move constructors, move assignment operators
+and destructors, it is a clear indication of the developer's intention and
+should be respected.
+
 WARNING! This check may be expensive on large source files.
 
 Options
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -274,13 +274,10 @@
   Global options of the same name should be used instead.
 
 - Improved :doc:`bugprone-exception-escape
-  ` to not emit warnings for
-  forward declarations of functions and additionally modified it to skip
-  

[PATCH] D151047: [clang-format] Fix indent for selective formatting.

2023-07-18 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0570cc568f5c: [clang-format] Fix indent for selective 
formatting (authored by Sedeniono, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151047

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTestSelective.cpp

Index: clang/unittests/Format/FormatTestSelective.cpp
===
--- clang/unittests/Format/FormatTestSelective.cpp
+++ clang/unittests/Format/FormatTestSelective.cpp
@@ -528,6 +528,26 @@
 format("  int a;\n"
"void ff() {}",
11, 0));
+
+  // https://github.com/llvm/llvm-project/issues/59178
+  Style = getMozillaStyle();
+  EXPECT_EQ("int a()\n"
+"{\n"
+"return 0;\n"
+"}\n"
+"int b()\n"
+"{\n"
+"  return 42;\n"
+"}",
+format("int a()\n"
+   "{\n"
+   "return 0;\n"
+   "}\n"
+   "int b()\n"
+   "{\n"
+   "return 42;\n" // Format this line only
+   "}",
+   32, 0));
 }
 
 TEST_F(FormatTestSelective, UnderstandsTabs) {
@@ -617,6 +637,61 @@
  "namespace ns1 { namespace ns2 {\n"
  "}}";
   EXPECT_EQ(Code, format(Code, 0, 0));
+
+  // https://reviews.llvm.org/D151047#4369742
+  Style = getLLVMStyle();
+  Style.FixNamespaceComments = false;
+  Code = "namespace ns {\n"
+ "#define REF(alias) alias alias_var;\n"
+ "}"; // Format this line only
+  EXPECT_EQ(Code, format(Code, 51, 0));
+}
+
+TEST_F(FormatTestSelective, FormatMacroRegardlessOfPreviousIndent) {
+  // clang-format currently does not (or should not) take into account the
+  // indent of previous unformatted lines when formatting a PP directive.
+  // Technically speaking, LevelIndentTracker::IndentForLevel is only for non-PP
+  // lines. So these tests here check that the indent of previous non-PP lines
+  // do not affect the formatting. If this requirement changes, the tests here
+  // need to be adapted.
+  Style = getLLVMStyle();
+
+  const StringRef Code{"  class Foo {\n"
+   "void test() {\n"
+   "#ifdef 1\n"
+   "#define some\n" // format this line
+   " #endif\n"
+   "}};"};
+
+  EXPECT_EQ(Style.IndentPPDirectives,
+FormatStyle::PPDirectiveIndentStyle::PPDIS_None);
+  EXPECT_EQ("  class Foo {\n"
+"void test() {\n"
+"#ifdef 1\n"
+"#define some\n" // Formatted line
+"#endif\n"   // That this line is also formatted might be a bug.
+"}};", // Ditto: Bug?
+format(Code, 57, 0));
+
+  Style.IndentPPDirectives =
+  FormatStyle::PPDirectiveIndentStyle::PPDIS_BeforeHash;
+  EXPECT_EQ("  class Foo {\n"
+"void test() {\n"
+"#ifdef 1\n"
+"  #define some\n" // Formatted line
+" #endif\n"
+"}};",
+format(Code, 57, 0));
+
+  Style.IndentPPDirectives =
+  FormatStyle::PPDirectiveIndentStyle::PPDIS_AfterHash;
+  EXPECT_EQ("  class Foo {\n"
+"void test() {\n"
+"#ifdef 1\n"
+"#  define some\n" // Formatted line
+"#endif\n" // That this line is also formatted might be a bug.
+"}};",
+format(Code, 57, 0));
 }
 
 } // end namespace
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -74,6 +74,13 @@
: Line.Level * PPIndentWidth;
   Indent += AdditionalIndent;
 } else {
+  // When going to lower levels, forget previous higher levels so that we
+  // recompute future higher levels. But don't forget them if we enter a PP
+  // directive, since these do not terminate a C++ code block.
+  if (!Line.InPPDirective) {
+assert(Line.Level <= IndentForLevel.size());
+IndentForLevel.resize(Line.Level + 1);
+  }
   Indent = getIndent(Line.Level);
 }
 if (static_cast(Indent) + Offset >= 0)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ff40c34 - [clang-tidy] Allow explicit throwing in bugprone-exception-escape for special functions

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

Author: Piotr Zegar
Date: 2023-07-18T21:11:08Z
New Revision: ff40c34881772e0641027327cd1791f4acacf6ff

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

LOG: [clang-tidy] Allow explicit throwing in bugprone-exception-escape for 
special functions

Functions declared explicitly with noexcept(false) or throw(exception)
will be excluded from the analysis, as even though it is not recommended for
functions like swap, main, move constructors and assignment operators,
and destructors, it is a clear indication of the developer's intention and
should be respected.

Fixes: #40583, #55143

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
clang/include/clang/Basic/ExceptionSpecificationType.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index 635cc2ca05d120..90bf523ffb00b6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -15,15 +15,21 @@
 
 using namespace clang::ast_matchers;
 
-namespace clang {
+namespace clang::tidy::bugprone {
 namespace {
+
 AST_MATCHER_P(FunctionDecl, isEnabled, llvm::StringSet<>,
   FunctionsThatShouldNotThrow) {
   return FunctionsThatShouldNotThrow.count(Node.getNameAsString()) > 0;
 }
+
+AST_MATCHER(FunctionDecl, isExplicitThrow) {
+  return isExplicitThrowExceptionSpec(Node.getExceptionSpecType()) &&
+ Node.getExceptionSpecSourceRange().isValid();
+}
+
 } // namespace
 
-namespace tidy::bugprone {
 ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context), 
RawFunctionsThatShouldNotThrow(Options.get(
@@ -53,10 +59,12 @@ void 
ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   functionDecl(isDefinition(),
-   anyOf(isNoThrow(), cxxDestructorDecl(),
- cxxConstructorDecl(isMoveConstructor()),
- cxxMethodDecl(isMoveAssignmentOperator()),
- hasName("main"), hasName("swap"),
+   anyOf(isNoThrow(),
+ allOf(anyOf(cxxDestructorDecl(),
+ cxxConstructorDecl(isMoveConstructor()),
+ cxxMethodDecl(isMoveAssignmentOperator()),
+ isMain(), hasName("swap")),
+   unless(isExplicitThrow())),
  isEnabled(FunctionsThatShouldNotThrow)))
   .bind("thrower"),
   this);
@@ -77,5 +85,4 @@ void ExceptionEscapeCheck::check(const 
MatchFinder::MatchResult ) {
 << MatchedDecl;
 }
 
-} // namespace tidy::bugprone
-} // namespace clang
+} // namespace clang::tidy::bugprone

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index abe815e7cba756..1c542d4c9f2f30 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -274,13 +274,10 @@ Changes in existing checks
   Global options of the same name should be used instead.
 
 - Improved :doc:`bugprone-exception-escape
-  ` to not emit warnings for
-  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
-  throwing exceptions in their bodies.
+  ` check to not emit warnings for
+  forward declarations of functions, explicitly declared throwing functions,
+  coroutines throwing exceptions in their bodies and skip ``noexcept``
+  functions during call stack analysis.
 
 - Improved :doc:`bugprone-fold-init-type
   ` to handle iterators that do not

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
index 52f3ceff281494..e6aa8e001492a6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
@@ -22,6 +22,12 @@ are 

[clang] 0570cc5 - [clang-format] Fix indent for selective formatting

2023-07-18 Thread Owen Pan via cfe-commits

Author: Sedenion
Date: 2023-07-18T14:10:53-07:00
New Revision: 0570cc568f5c8047267be7ab5056f8c4f45349b5

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

LOG: [clang-format] Fix indent for selective formatting

The problem was that the LevelIndentTracker remembered
the indentation level of previous deeper levels when
leaving a scope. Afterwards, when it entered again a
deeper level, it blindly reused the previous
indentation level. In case the --lines option was used
such that the previous deeper level was not formatted,
that previous level was whatever happened to be there
in the source code. The formatter simply believed it.

This is fixed by letting the LevelIndentTracker forget
the previous deeper levels when stepping out of them
(=> change in LevelIndentTracker::nextLine()).
Note that this used to be the case until LLVM 14.0.6,
but was changed in https://reviews.llvm.org/D129064
(#56352) to fix a crash. Our commit here essentially
reverts that crash fix. It was incorrect/incomplete.

Fixes #58464.
Fixes #59178.
Fixes #62799.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTestSelective.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index b745838c1cc5e4..52519145279cce 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -74,6 +74,13 @@ class LevelIndentTracker {
: Line.Level * PPIndentWidth;
   Indent += AdditionalIndent;
 } else {
+  // When going to lower levels, forget previous higher levels so that we
+  // recompute future higher levels. But don't forget them if we enter a PP
+  // directive, since these do not terminate a C++ code block.
+  if (!Line.InPPDirective) {
+assert(Line.Level <= IndentForLevel.size());
+IndentForLevel.resize(Line.Level + 1);
+  }
   Indent = getIndent(Line.Level);
 }
 if (static_cast(Indent) + Offset >= 0)

diff  --git a/clang/unittests/Format/FormatTestSelective.cpp 
b/clang/unittests/Format/FormatTestSelective.cpp
index 86ed7aba1913d4..da252eb2ae3c38 100644
--- a/clang/unittests/Format/FormatTestSelective.cpp
+++ b/clang/unittests/Format/FormatTestSelective.cpp
@@ -528,6 +528,26 @@ TEST_F(FormatTestSelective, ReformatRegionAdjustsIndent) {
 format("  int a;\n"
"void ff() {}",
11, 0));
+
+  // https://github.com/llvm/llvm-project/issues/59178
+  Style = getMozillaStyle();
+  EXPECT_EQ("int a()\n"
+"{\n"
+"return 0;\n"
+"}\n"
+"int b()\n"
+"{\n"
+"  return 42;\n"
+"}",
+format("int a()\n"
+   "{\n"
+   "return 0;\n"
+   "}\n"
+   "int b()\n"
+   "{\n"
+   "return 42;\n" // Format this line only
+   "}",
+   32, 0));
 }
 
 TEST_F(FormatTestSelective, UnderstandsTabs) {
@@ -617,6 +637,61 @@ TEST_F(FormatTestSelective, DontAssert) {
  "namespace ns1 { namespace ns2 {\n"
  "}}";
   EXPECT_EQ(Code, format(Code, 0, 0));
+
+  // https://reviews.llvm.org/D151047#4369742
+  Style = getLLVMStyle();
+  Style.FixNamespaceComments = false;
+  Code = "namespace ns {\n"
+ "#define REF(alias) alias alias_var;\n"
+ "}"; // Format this line only
+  EXPECT_EQ(Code, format(Code, 51, 0));
+}
+
+TEST_F(FormatTestSelective, FormatMacroRegardlessOfPreviousIndent) {
+  // clang-format currently does not (or should not) take into account the
+  // indent of previous unformatted lines when formatting a PP directive.
+  // Technically speaking, LevelIndentTracker::IndentForLevel is only for 
non-PP
+  // lines. So these tests here check that the indent of previous non-PP lines
+  // do not affect the formatting. If this requirement changes, the tests here
+  // need to be adapted.
+  Style = getLLVMStyle();
+
+  const StringRef Code{"  class Foo {\n"
+   "void test() {\n"
+   "#ifdef 1\n"
+   "#define some\n" // format this line
+   " #endif\n"
+   "}};"};
+
+  EXPECT_EQ(Style.IndentPPDirectives,
+FormatStyle::PPDirectiveIndentStyle::PPDIS_None);
+  EXPECT_EQ("  class Foo {\n"
+"void test() {\n"
+"#ifdef 1\n"
+"#define some\n" // Formatted line
+"#endif\n"   // That this line is also formatted might be a 
bug.
+   

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

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

Yes, this diagnostic implements a core semantic rule and must be emitted.  
There are some situations where Clang will actually generate malformed IR 
(violating dominance rules) if you fail to diagnose jump violations correctly.  
The IR you get when there's a jump over a destructor is well-formed, but it's 
still arguably* a miscompile and must be diagnosed.

(*) It's a miscompile unless there's a rule saying it's U.B. to jump out of a 
scope.  I don't see such a rule in any of the docs about this feature.


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


[PATCH] D155580: [trivial-auto-var-init] Do not emit initialization code for empty class

2023-07-18 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

(sorry for sending twice, looks like email reply failed)

This is the same as padding, and is initialized on purpose. If it’s truly 
unused then the optimizer will eliminate it… unless it can’t prove whether the 
store is dead.

Does this show up in any meaningless performance case? If so, can we optimize 
it away?


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

https://reviews.llvm.org/D155580

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


[PATCH] D153310: Add codegen for llvm pow builtin

2023-07-18 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 541721.
bob80905 added a comment.

- add newline EOF


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153310

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
  clang/test/Sema/aarch64-sve-vector-pow-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-pow-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -198,3 +198,11 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_pow() {
+  const double a = 2;
+  double b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/riscv-sve-vector-pow-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-pow-ops.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+#include 
+
+
+vfloat32mf2_t test_pow_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_pow(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -438,6 +438,31 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_pow(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
+  i = __builtin_elementwise_pow(p, d);
+  // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+
+  struct Foo foo = __builtin_elementwise_pow(i, i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_pow(i);
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
+
+  i = __builtin_elementwise_pow();
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 0}}
+
+  i = __builtin_elementwise_pow(i, i, i);
+  // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
+
+  i = __builtin_elementwise_pow(v, iv);
+  // expected-error@-1 {{arguments are of different types ('float4' (vector of 4 'float' values) vs 'int3' (vector of 3 'int' values))}}
+
+  i = __builtin_elementwise_pow(uv, iv);
+  // expected-error@-1 {{arguments are of different types ('unsigned3' (vector of 3 'unsigned int' values) vs 'int3' (vector of 3 'int' values))}}
+  
+}
+
+
 void test_builtin_elementwise_roundeven(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_roundeven(f);
Index: clang/test/Sema/aarch64-sve-vector-pow-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-pow-ops.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple aarch64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh  -target-feature +sve -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+svfloat32_t test_pow_vv_i8mf8(svfloat32_t v) {
+
+  return __builtin_elementwise_pow(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
===
--- clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
+++ clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
@@ -217,3 +217,12 @@
   return __builtin_elementwise_fma(a, b, c);
 }
 
+// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_powDv4_fS_
+// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> @llvm.pow.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
+// CHECK-NEXT:ret <4 x float> [[TMP0]]
+//
+float4 strict_elementwise_pow(float4 a, float4 b) 

[PATCH] D153310: Add codegen for llvm pow builtin

2023-07-18 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 541717.
bob80905 added a comment.

- add strictfp test, use emitbinarybuiltin, fix some whitespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153310

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
  clang/test/Sema/aarch64-sve-vector-pow-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-pow-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -198,3 +198,11 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_pow() {
+  const double a = 2;
+  double b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/riscv-sve-vector-pow-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-pow-ops.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+#include 
+
+
+vfloat32mf2_t test_pow_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_pow(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
\ No newline at end of file
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -438,6 +438,31 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_pow(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
+  i = __builtin_elementwise_pow(p, d);
+  // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+
+  struct Foo foo = __builtin_elementwise_pow(i, i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_pow(i);
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
+
+  i = __builtin_elementwise_pow();
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 0}}
+
+  i = __builtin_elementwise_pow(i, i, i);
+  // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
+
+  i = __builtin_elementwise_pow(v, iv);
+  // expected-error@-1 {{arguments are of different types ('float4' (vector of 4 'float' values) vs 'int3' (vector of 3 'int' values))}}
+
+  i = __builtin_elementwise_pow(uv, iv);
+  // expected-error@-1 {{arguments are of different types ('unsigned3' (vector of 3 'unsigned int' values) vs 'int3' (vector of 3 'int' values))}}
+  
+}
+
+
 void test_builtin_elementwise_roundeven(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_roundeven(f);
Index: clang/test/Sema/aarch64-sve-vector-pow-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-pow-ops.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple aarch64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh  -target-feature +sve -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+svfloat32_t test_pow_vv_i8mf8(svfloat32_t v) {
+
+  return __builtin_elementwise_pow(v, v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
===
--- clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
+++ clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
@@ -217,3 +217,12 @@
   return __builtin_elementwise_fma(a, b, c);
 }
 
+// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_powDv4_fS_
+// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> @llvm.pow.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
+// CHECK-NEXT:ret 

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

2023-07-18 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: clang/lib/Sema/JumpDiagnostics.cpp:658
 
+if (auto *G = dyn_cast(Jump)) {
+  for (AddrLabelExpr *L : G->labels()) {

efriedma wrote:
> nickdesaulniers wrote:
> > efriedma wrote:
> > > nickdesaulniers wrote:
> > > > rjmccall wrote:
> > > > > nickdesaulniers wrote:
> > > > > > rjmccall wrote:
> > > > > > > I think it would be good to leave a comment here like this:
> > > > > > > 
> > > > > > > > We know the possible destinations of an asm goto, but we don't 
> > > > > > > > have the
> > > > > > > > ability to add code along those control flow edges, so we have 
> > > > > > > > to diagnose
> > > > > > > > jumps both in and out of scopes, just like we do with an 
> > > > > > > > indirect goto.
> > > > > > Depending on your definition of "we" (clang vs. llvm), llvm does 
> > > > > > have the ability to add code along those edges.
> > > > > > 
> > > > > > See llvm/lib/CodeGen/CallBrPrepare.cpp.  I'll clarify in your 
> > > > > > comment that "clang does not split critical edges during code 
> > > > > > generation of llvm ... "
> > > > > Okay, so, I don't really know much about this feature.  I was 
> > > > > thinking that the branch might go directly into some other assembly 
> > > > > block, which would not be splittable.  If the branch just goes to an 
> > > > > arbitrary basic block in IR, then it would be straightforward for 
> > > > > IRGen to just resolve the destination blocks for `asm goto` labels to 
> > > > > some new block that does a normal `goto` to that label.  If we did 
> > > > > that, we wouldn't need extra restrictions here at all and could just 
> > > > > check this like any other direct branch.
> > > > > 
> > > > > We don't need to do that work right away, but the comment should 
> > > > > probably reflect the full state of affairs — "but clang's IR 
> > > > > generation does not currently know how to add code along these 
> > > > > control flow edges, so we have to diagnose jumps both in and out of 
> > > > > scopes, like we do with indirect goto.  If we ever add that ability 
> > > > > to IRGen, this code could check these jumps just like ordinary 
> > > > > `goto`s."
> > > > > Okay, so, I don't really know much about this feature.
> > > > 
> > > > "Run this block of asm, then continue to either the next statement or 
> > > > one of the explicit labels in the label list."
> > > > 
> > > > ---
> > > > 
> > > > That comment still doesn't seem quite right to me.
> > > > 
> > > > `asm goto` is more like a direct `goto` or a switch in the sense that 
> > > > the cases or possible destination are known at compile time; that's not 
> > > > like indirect goto where you're jumping to literally anywhere.
> > > > 
> > > > We need to check the scopes like we would for direct `goto`, because we 
> > > > don't want to bypass non-trivial destructors.
> > > > 
> > > > ---
> > > > Interestingly, it looks like some of the cases 
> > > > inclang/test/Sema/asm-goto.cpp, `g++` permits, if you use the 
> > > > `-fpermissive` flag.  Clang doesn't error that it doesn't recognize 
> > > > that flag, but it doesn't seem to do anything in clang, FWICT playing 
> > > > with it in godbolt.
> > > > 
> > > > ---
> > > > 
> > > > That said, I would have thought
> > > > ```
> > > > void test4cleanup(int*);
> > > > // No errors expected.
> > > > void test4(void) {
> > > > l0:;
> > > > int x __attribute__((cleanup(test4cleanup)));
> > > > asm goto("# %l0"l0);
> > > > }
> > > > ```
> > > > To work with this change, but we still produce:
> > > > ```
> > > > x.c:6:5: error: cannot jump from this asm goto statement to one of its 
> > > > possible targets
> > > > 6 | asm goto("# %l0"l0);
> > > >   | ^
> > > > x.c:4:1: note: possible target of asm goto statement
> > > > 4 | l0:;
> > > >   | ^
> > > > x.c:5:9: note: jump exits scope of variable with 
> > > > __attribute__((cleanup))
> > > > 5 | int x __attribute__((cleanup(test4cleanup)));
> > > >   | ^
> > > > ```
> > > > Aren't those in the same scope though? I would have expected that to 
> > > > work just as if we had a direct `goto l0` rather than the `asm goto`.
> > > (There's some history here that the original implementation of asm goto 
> > > treated it semantically more like an indirect goto, including the use of 
> > > address-of-labels; for a variety of reasons, we changed it so it's more 
> > > like a switch statement.)
> > > 
> > > Suppose we have:
> > > 
> > > ```
> > > void test4cleanup(int*);
> > > void test4(void) {
> > > asm goto("# %l0"l0);
> > > l0:;
> > > int x __attribute__((cleanup(test4cleanup)));
> > > asm goto("# %l0"l0);
> > > }
> > > ```
> > > 
> > > To make this work correctly, the first goto needs to branch directly to 
> > > the destination, but the second needs to branch to a call to 
> > > test4cleanup().  It's probably not that hard to implement: instead of 
> > > branching directly 

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

2023-07-18 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/Sema/JumpDiagnostics.cpp:658
 
+if (auto *G = dyn_cast(Jump)) {
+  for (AddrLabelExpr *L : G->labels()) {

nickdesaulniers wrote:
> efriedma wrote:
> > nickdesaulniers wrote:
> > > rjmccall wrote:
> > > > nickdesaulniers wrote:
> > > > > rjmccall wrote:
> > > > > > I think it would be good to leave a comment here like this:
> > > > > > 
> > > > > > > We know the possible destinations of an asm goto, but we don't 
> > > > > > > have the
> > > > > > > ability to add code along those control flow edges, so we have to 
> > > > > > > diagnose
> > > > > > > jumps both in and out of scopes, just like we do with an indirect 
> > > > > > > goto.
> > > > > Depending on your definition of "we" (clang vs. llvm), llvm does have 
> > > > > the ability to add code along those edges.
> > > > > 
> > > > > See llvm/lib/CodeGen/CallBrPrepare.cpp.  I'll clarify in your comment 
> > > > > that "clang does not split critical edges during code generation of 
> > > > > llvm ... "
> > > > Okay, so, I don't really know much about this feature.  I was thinking 
> > > > that the branch might go directly into some other assembly block, which 
> > > > would not be splittable.  If the branch just goes to an arbitrary basic 
> > > > block in IR, then it would be straightforward for IRGen to just resolve 
> > > > the destination blocks for `asm goto` labels to some new block that 
> > > > does a normal `goto` to that label.  If we did that, we wouldn't need 
> > > > extra restrictions here at all and could just check this like any other 
> > > > direct branch.
> > > > 
> > > > We don't need to do that work right away, but the comment should 
> > > > probably reflect the full state of affairs — "but clang's IR generation 
> > > > does not currently know how to add code along these control flow edges, 
> > > > so we have to diagnose jumps both in and out of scopes, like we do with 
> > > > indirect goto.  If we ever add that ability to IRGen, this code could 
> > > > check these jumps just like ordinary `goto`s."
> > > > Okay, so, I don't really know much about this feature.
> > > 
> > > "Run this block of asm, then continue to either the next statement or one 
> > > of the explicit labels in the label list."
> > > 
> > > ---
> > > 
> > > That comment still doesn't seem quite right to me.
> > > 
> > > `asm goto` is more like a direct `goto` or a switch in the sense that the 
> > > cases or possible destination are known at compile time; that's not like 
> > > indirect goto where you're jumping to literally anywhere.
> > > 
> > > We need to check the scopes like we would for direct `goto`, because we 
> > > don't want to bypass non-trivial destructors.
> > > 
> > > ---
> > > Interestingly, it looks like some of the cases 
> > > inclang/test/Sema/asm-goto.cpp, `g++` permits, if you use the 
> > > `-fpermissive` flag.  Clang doesn't error that it doesn't recognize that 
> > > flag, but it doesn't seem to do anything in clang, FWICT playing with it 
> > > in godbolt.
> > > 
> > > ---
> > > 
> > > That said, I would have thought
> > > ```
> > > void test4cleanup(int*);
> > > // No errors expected.
> > > void test4(void) {
> > > l0:;
> > > int x __attribute__((cleanup(test4cleanup)));
> > > asm goto("# %l0"l0);
> > > }
> > > ```
> > > To work with this change, but we still produce:
> > > ```
> > > x.c:6:5: error: cannot jump from this asm goto statement to one of its 
> > > possible targets
> > > 6 | asm goto("# %l0"l0);
> > >   | ^
> > > x.c:4:1: note: possible target of asm goto statement
> > > 4 | l0:;
> > >   | ^
> > > x.c:5:9: note: jump exits scope of variable with __attribute__((cleanup))
> > > 5 | int x __attribute__((cleanup(test4cleanup)));
> > >   | ^
> > > ```
> > > Aren't those in the same scope though? I would have expected that to work 
> > > just as if we had a direct `goto l0` rather than the `asm goto`.
> > (There's some history here that the original implementation of asm goto 
> > treated it semantically more like an indirect goto, including the use of 
> > address-of-labels; for a variety of reasons, we changed it so it's more 
> > like a switch statement.)
> > 
> > Suppose we have:
> > 
> > ```
> > void test4cleanup(int*);
> > void test4(void) {
> > asm goto("# %l0"l0);
> > l0:;
> > int x __attribute__((cleanup(test4cleanup)));
> > asm goto("# %l0"l0);
> > }
> > ```
> > 
> > To make this work correctly, the first goto needs to branch directly to the 
> > destination, but the second needs to branch to a call to test4cleanup().  
> > It's probably not that hard to implement: instead of branching directly to 
> > the destination bb, each edge out of the callbr needs to branch to a newly 
> > created block, and that block needs to EmitBranchThroughCleanup() to the 
> > final destination.  (We create such blocks anyway to handle output values, 
> > but 

[PATCH] D155635: [OpenMP] [Reduction] Allow PLUS (+) operator on reduction clauses in OMP > 52

2023-07-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D155635#4512188 , @mdfazlay wrote:

> In D155635#4512183 , @ABataev wrote:
>
>> Tests?
>
> I think I need to use `-fopenmp-version=60` to test this revision. As OMP 6.0 
> is not official yet, am I allowed to use `-fopenmp-version=60` in my LIT test?

Yes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155635

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


[PATCH] D155636: [clang][dataflow] Add function to `WatchedLiteralsSolver` that reports whether the iteration limit has been reached.

2023-07-18 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, mboehme.
Herald added a subscriber: martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

This change provides a centralized record of whether the solver is
"exhausted". In general, once the solver is exhausted, further uses do not
produce meaningful conclusions. Clients can use this information, for example,
to choose to discard all results based on the solver, instead of trying to
distinguish those reached before the limit was reached. Providing it at in the
solver avoids the need to propagate it from each callsite to the client of the
solver.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155636

Files:
  clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -350,4 +350,23 @@
   EXPECT_EQ(solver.solve({A, B}).getStatus(), 
Solver::Result::Status::TimedOut);
 }
 
+TEST(SolverTest, ReachedLimitsReflectsTimeouts) {
+  WatchedLiteralsSolver solver(10);
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto Z = Ctx.atom();
+  auto W = Ctx.atom();
+
+  // !(X v Y) <=> !X ^ !Y
+  auto A = Ctx.iff(Ctx.neg(Ctx.disj(X, Y)), Ctx.conj(Ctx.neg(X), Ctx.neg(Y)));
+
+  // !(Z ^ W) <=> !Z v !W
+  auto B = Ctx.iff(Ctx.neg(Ctx.conj(Z, W)), Ctx.disj(Ctx.neg(Z), Ctx.neg(W)));
+
+  // A ^ B
+  ASSERT_EQ(solver.solve({A, B}).getStatus(), 
Solver::Result::Status::TimedOut);
+  EXPECT_TRUE(solver.reachedLimit());
+}
+
 } // namespace
Index: clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
===
--- clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
+++ clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
@@ -47,6 +47,9 @@
   : MaxIterations(WorkLimit) {}
 
   Result solve(llvm::ArrayRef Vals) override;
+
+  // The solver reached its maximum number of iterations.
+  bool reachedLimit() const { return MaxIterations == 0; }
 };
 
 } // namespace dataflow


Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -350,4 +350,23 @@
   EXPECT_EQ(solver.solve({A, B}).getStatus(), Solver::Result::Status::TimedOut);
 }
 
+TEST(SolverTest, ReachedLimitsReflectsTimeouts) {
+  WatchedLiteralsSolver solver(10);
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto Z = Ctx.atom();
+  auto W = Ctx.atom();
+
+  // !(X v Y) <=> !X ^ !Y
+  auto A = Ctx.iff(Ctx.neg(Ctx.disj(X, Y)), Ctx.conj(Ctx.neg(X), Ctx.neg(Y)));
+
+  // !(Z ^ W) <=> !Z v !W
+  auto B = Ctx.iff(Ctx.neg(Ctx.conj(Z, W)), Ctx.disj(Ctx.neg(Z), Ctx.neg(W)));
+
+  // A ^ B
+  ASSERT_EQ(solver.solve({A, B}).getStatus(), Solver::Result::Status::TimedOut);
+  EXPECT_TRUE(solver.reachedLimit());
+}
+
 } // namespace
Index: clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
===
--- clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
+++ clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
@@ -47,6 +47,9 @@
   : MaxIterations(WorkLimit) {}
 
   Result solve(llvm::ArrayRef Vals) override;
+
+  // The solver reached its maximum number of iterations.
+  bool reachedLimit() const { return MaxIterations == 0; }
 };
 
 } // namespace dataflow
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155635: [OpenMP] [Reduction] Allow PLUS (+) operator on reduction clauses in OMP > 52

2023-07-18 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay added a comment.

In D155635#4512183 , @ABataev wrote:

> Tests?

I think I need to use `-fopenmp-version=60` to test this revision. As OMP 6.0 
is not official yet, am I allowed to use `-fopenmp-version=60` in my LIT test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155635

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


[PATCH] D155094: [clang-format] Refactoring and asserts in LevelIndentTracker. (NFC)

2023-07-18 Thread Owen Pan 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 rGe4aa1428a28d: [clang-format] Refactoring and asserts in 
LevelIndentTracker. (NFC) (authored by Sedeniono, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155094

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -88,14 +88,15 @@
   /// level to the same indent.
   /// Note that \c nextLine must have been called before this method.
   void adjustToUnmodifiedLine(const AnnotatedLine ) {
+if (Line.InPPDirective)
+  return;
+assert(Line.Level < IndentForLevel.size());
+if (Line.First->is(tok::comment) && IndentForLevel[Line.Level] != -1)
+  return;
 unsigned LevelIndent = Line.First->OriginalColumn;
 if (static_cast(LevelIndent) - Offset >= 0)
   LevelIndent -= Offset;
-assert(Line.Level < IndentForLevel.size());
-if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) &&
-!Line.InPPDirective) {
-  IndentForLevel[Line.Level] = LevelIndent;
-}
+IndentForLevel[Line.Level] = LevelIndent;
   }
 
 private:
@@ -148,6 +149,7 @@
   /// at \p IndentForLevel[l], or a value < 0 if the indent for
   /// that level is unknown.
   unsigned getIndent(unsigned Level) const {
+assert(Level < IndentForLevel.size());
 if (IndentForLevel[Level] != -1)
   return IndentForLevel[Level];
 if (Level == 0)
@@ -159,7 +161,10 @@
   const AdditionalKeywords 
   const unsigned AdditionalIndent;
 
-  /// The indent in characters for each level.
+  /// The indent in characters for each level. It remembers the indent of
+  /// previous lines (that are not PP directives) of equal or lower levels. 
This
+  /// is used to align formatted lines to the indent of previous non-formatted
+  /// lines. Think about the --lines parameter of clang-format.
   SmallVector IndentForLevel;
 
   /// Offset of the current line relative to the indent level.


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -88,14 +88,15 @@
   /// level to the same indent.
   /// Note that \c nextLine must have been called before this method.
   void adjustToUnmodifiedLine(const AnnotatedLine ) {
+if (Line.InPPDirective)
+  return;
+assert(Line.Level < IndentForLevel.size());
+if (Line.First->is(tok::comment) && IndentForLevel[Line.Level] != -1)
+  return;
 unsigned LevelIndent = Line.First->OriginalColumn;
 if (static_cast(LevelIndent) - Offset >= 0)
   LevelIndent -= Offset;
-assert(Line.Level < IndentForLevel.size());
-if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) &&
-!Line.InPPDirective) {
-  IndentForLevel[Line.Level] = LevelIndent;
-}
+IndentForLevel[Line.Level] = LevelIndent;
   }
 
 private:
@@ -148,6 +149,7 @@
   /// at \p IndentForLevel[l], or a value < 0 if the indent for
   /// that level is unknown.
   unsigned getIndent(unsigned Level) const {
+assert(Level < IndentForLevel.size());
 if (IndentForLevel[Level] != -1)
   return IndentForLevel[Level];
 if (Level == 0)
@@ -159,7 +161,10 @@
   const AdditionalKeywords 
   const unsigned AdditionalIndent;
 
-  /// The indent in characters for each level.
+  /// The indent in characters for each level. It remembers the indent of
+  /// previous lines (that are not PP directives) of equal or lower levels. This
+  /// is used to align formatted lines to the indent of previous non-formatted
+  /// lines. Think about the --lines parameter of clang-format.
   SmallVector IndentForLevel;
 
   /// Offset of the current line relative to the indent level.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e4aa142 - [clang-format] Refactoring and asserts in LevelIndentTracker. (NFC)

2023-07-18 Thread Owen Pan via cfe-commits

Author: Sedenion
Date: 2023-07-18T13:32:07-07:00
New Revision: e4aa1428a28dce38cd4712b5720baa333cbdd25b

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

LOG: [clang-format] Refactoring and asserts in LevelIndentTracker. (NFC)

adjustToUnmodifiedLine: The code does something only for non-PP-directives.
This is now reflected by putting the if-check to the top. This also ensures
that the assert() there is executed only if IndentForLevel is actually
accessed.

getIndent(): assert valid index into IndentForLevel.

Added explanation regarding the intention of IndentForLevel.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 9413dbe59553bd..b745838c1cc5e4 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -88,14 +88,15 @@ class LevelIndentTracker {
   /// level to the same indent.
   /// Note that \c nextLine must have been called before this method.
   void adjustToUnmodifiedLine(const AnnotatedLine ) {
+if (Line.InPPDirective)
+  return;
+assert(Line.Level < IndentForLevel.size());
+if (Line.First->is(tok::comment) && IndentForLevel[Line.Level] != -1)
+  return;
 unsigned LevelIndent = Line.First->OriginalColumn;
 if (static_cast(LevelIndent) - Offset >= 0)
   LevelIndent -= Offset;
-assert(Line.Level < IndentForLevel.size());
-if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) &&
-!Line.InPPDirective) {
-  IndentForLevel[Line.Level] = LevelIndent;
-}
+IndentForLevel[Line.Level] = LevelIndent;
   }
 
 private:
@@ -148,6 +149,7 @@ class LevelIndentTracker {
   /// at \p IndentForLevel[l], or a value < 0 if the indent for
   /// that level is unknown.
   unsigned getIndent(unsigned Level) const {
+assert(Level < IndentForLevel.size());
 if (IndentForLevel[Level] != -1)
   return IndentForLevel[Level];
 if (Level == 0)
@@ -159,7 +161,10 @@ class LevelIndentTracker {
   const AdditionalKeywords 
   const unsigned AdditionalIndent;
 
-  /// The indent in characters for each level.
+  /// The indent in characters for each level. It remembers the indent of
+  /// previous lines (that are not PP directives) of equal or lower levels. 
This
+  /// is used to align formatted lines to the indent of previous non-formatted
+  /// lines. Think about the --lines parameter of clang-format.
   SmallVector IndentForLevel;
 
   /// Offset of the current line relative to the indent level.



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


[PATCH] D155635: [OpenMP] [Reduction] Allow PLUS (+) operator on reduction clauses in OMP > 52

2023-07-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155635

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


[PATCH] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute

2023-07-18 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

According to git blame @rsmith has done lots of changes in 
`clang/lib/AST/ExprConstant.cpp`; added as reviewer.


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] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes

2023-07-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D155342#4511879 , @rjmccall wrote:

>> We need to check the scopes like we would for direct goto, because we don't 
>> want to bypass non-trivial destructors.
>
> I think this is the basic misunderstanding here.  Direct `goto` is allowed to 
> jump out of scopes; it just runs destructors on the way.  It is only a direct 
> branch to the target block if there are no destructors along the path.
>
> Indirect `goto` is not allowed to jump out of scopes because, in general, the 
> labels could be in different scopes with different sets of destructors 
> required

Ah, got it.




Comment at: clang/lib/Sema/JumpDiagnostics.cpp:658
 
+if (auto *G = dyn_cast(Jump)) {
+  for (AddrLabelExpr *L : G->labels()) {

efriedma wrote:
> nickdesaulniers wrote:
> > rjmccall wrote:
> > > nickdesaulniers wrote:
> > > > rjmccall wrote:
> > > > > I think it would be good to leave a comment here like this:
> > > > > 
> > > > > > We know the possible destinations of an asm goto, but we don't have 
> > > > > > the
> > > > > > ability to add code along those control flow edges, so we have to 
> > > > > > diagnose
> > > > > > jumps both in and out of scopes, just like we do with an indirect 
> > > > > > goto.
> > > > Depending on your definition of "we" (clang vs. llvm), llvm does have 
> > > > the ability to add code along those edges.
> > > > 
> > > > See llvm/lib/CodeGen/CallBrPrepare.cpp.  I'll clarify in your comment 
> > > > that "clang does not split critical edges during code generation of 
> > > > llvm ... "
> > > Okay, so, I don't really know much about this feature.  I was thinking 
> > > that the branch might go directly into some other assembly block, which 
> > > would not be splittable.  If the branch just goes to an arbitrary basic 
> > > block in IR, then it would be straightforward for IRGen to just resolve 
> > > the destination blocks for `asm goto` labels to some new block that does 
> > > a normal `goto` to that label.  If we did that, we wouldn't need extra 
> > > restrictions here at all and could just check this like any other direct 
> > > branch.
> > > 
> > > We don't need to do that work right away, but the comment should probably 
> > > reflect the full state of affairs — "but clang's IR generation does not 
> > > currently know how to add code along these control flow edges, so we have 
> > > to diagnose jumps both in and out of scopes, like we do with indirect 
> > > goto.  If we ever add that ability to IRGen, this code could check these 
> > > jumps just like ordinary `goto`s."
> > > Okay, so, I don't really know much about this feature.
> > 
> > "Run this block of asm, then continue to either the next statement or one 
> > of the explicit labels in the label list."
> > 
> > ---
> > 
> > That comment still doesn't seem quite right to me.
> > 
> > `asm goto` is more like a direct `goto` or a switch in the sense that the 
> > cases or possible destination are known at compile time; that's not like 
> > indirect goto where you're jumping to literally anywhere.
> > 
> > We need to check the scopes like we would for direct `goto`, because we 
> > don't want to bypass non-trivial destructors.
> > 
> > ---
> > Interestingly, it looks like some of the cases 
> > inclang/test/Sema/asm-goto.cpp, `g++` permits, if you use the 
> > `-fpermissive` flag.  Clang doesn't error that it doesn't recognize that 
> > flag, but it doesn't seem to do anything in clang, FWICT playing with it in 
> > godbolt.
> > 
> > ---
> > 
> > That said, I would have thought
> > ```
> > void test4cleanup(int*);
> > // No errors expected.
> > void test4(void) {
> > l0:;
> > int x __attribute__((cleanup(test4cleanup)));
> > asm goto("# %l0"l0);
> > }
> > ```
> > To work with this change, but we still produce:
> > ```
> > x.c:6:5: error: cannot jump from this asm goto statement to one of its 
> > possible targets
> > 6 | asm goto("# %l0"l0);
> >   | ^
> > x.c:4:1: note: possible target of asm goto statement
> > 4 | l0:;
> >   | ^
> > x.c:5:9: note: jump exits scope of variable with __attribute__((cleanup))
> > 5 | int x __attribute__((cleanup(test4cleanup)));
> >   | ^
> > ```
> > Aren't those in the same scope though? I would have expected that to work 
> > just as if we had a direct `goto l0` rather than the `asm goto`.
> (There's some history here that the original implementation of asm goto 
> treated it semantically more like an indirect goto, including the use of 
> address-of-labels; for a variety of reasons, we changed it so it's more like 
> a switch statement.)
> 
> Suppose we have:
> 
> ```
> void test4cleanup(int*);
> void test4(void) {
> asm goto("# %l0"l0);
> l0:;
> int x __attribute__((cleanup(test4cleanup)));
> asm goto("# %l0"l0);
> }
> ```
> 
> To make this work correctly, the first goto needs to branch directly to the 
> 

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

2023-07-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 541705.
nickdesaulniers added a comment.

- rewrite comment based on feedback from @rjmccall and @efriedma


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155342

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/test/Sema/asm-goto.cpp
  clang/test/SemaCXX/goto2.cpp

Index: clang/test/SemaCXX/goto2.cpp
===
--- clang/test/SemaCXX/goto2.cpp
+++ clang/test/SemaCXX/goto2.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions %s
 // expected-no-diagnostics
 
 //PR9463
@@ -46,3 +46,20 @@
 
 	return 0;
 }
+
+void asm_goto_try_catch() {
+  try {
+__label__ label;
+asm goto("" : : : : label);
+label:;
+  } catch(...) {
+__label__ label;
+asm goto("" : : : : label);
+label:;
+  };
+  if constexpr(false) {
+__label__ label;
+asm goto("" : : : : label);
+label:;
+  }
+}
Index: clang/test/Sema/asm-goto.cpp
===
--- clang/test/Sema/asm-goto.cpp
+++ clang/test/Sema/asm-goto.cpp
@@ -59,3 +59,13 @@
 loop:
   return 0;
 }
+
+void test4cleanup(int*);
+// No errors expected.
+void test4(void) {
+  asm goto(""l0);
+l0:;
+  int x __attribute__((cleanup(test4cleanup)));
+  asm goto(""l1);
+l1:;
+}
Index: clang/lib/Sema/JumpDiagnostics.cpp
===
--- clang/lib/Sema/JumpDiagnostics.cpp
+++ clang/lib/Sema/JumpDiagnostics.cpp
@@ -72,10 +72,9 @@
   SmallVector Jumps;
 
   SmallVector IndirectJumps;
-  SmallVector AsmJumps;
+  SmallVector IndirectJumpTargets;
   SmallVector MustTailStmts;
-  SmallVector IndirectJumpTargets;
-  SmallVector AsmJumpTargets;
+
 public:
   JumpScopeChecker(Stmt *Body, Sema );
 private:
@@ -86,7 +85,7 @@
   void BuildScopeInformation(Stmt *S, unsigned );
 
   void VerifyJumps();
-  void VerifyIndirectOrAsmJumps(bool IsAsmGoto);
+  void VerifyIndirectJumps();
   void VerifyMustTailStmts();
   void NoteJumpIntoScopes(ArrayRef ToScopes);
   void DiagnoseIndirectOrAsmJump(Stmt *IG, unsigned IGScope, LabelDecl *Target,
@@ -115,8 +114,7 @@
 
   // Check that all jumps we saw are kosher.
   VerifyJumps();
-  VerifyIndirectOrAsmJumps(false);
-  VerifyIndirectOrAsmJumps(true);
+  VerifyIndirectJumps();
   VerifyMustTailStmts();
 }
 
@@ -333,11 +331,8 @@
 // operand (to avoid recording the address-of-label use), which
 // works only because of the restricted set of expressions which
 // we detect as constant targets.
-if (cast(S)->getConstantTarget()) {
-  LabelAndGotoScopes[S] = ParentScope;
-  Jumps.push_back(S);
-  return;
-}
+if (cast(S)->getConstantTarget())
+  goto RecordJumpScope;
 
 LabelAndGotoScopes[S] = ParentScope;
 IndirectJumps.push_back(S);
@@ -354,27 +349,21 @@
   BuildScopeInformation(Var, ParentScope);
   ++StmtsToSkip;
 }
+goto RecordJumpScope;
+
+  case Stmt::GCCAsmStmtClass:
+if (!cast(S)->isAsmGoto())
+  break;
 [[fallthrough]];
 
   case Stmt::GotoStmtClass:
+  RecordJumpScope:
 // Remember both what scope a goto is in as well as the fact that we have
 // it.  This makes the second scan not have to walk the AST again.
 LabelAndGotoScopes[S] = ParentScope;
 Jumps.push_back(S);
 break;
 
-  case Stmt::GCCAsmStmtClass:
-if (auto *GS = dyn_cast(S))
-  if (GS->isAsmGoto()) {
-// Remember both what scope a goto is in as well as the fact that we
-// have it.  This makes the second scan not have to walk the AST again.
-LabelAndGotoScopes[S] = ParentScope;
-AsmJumps.push_back(GS);
-for (auto *E : GS->labels())
-  AsmJumpTargets.push_back(E->getLabel());
-  }
-break;
-
   case Stmt::IfStmtClass: {
 IfStmt *IS = cast(S);
 if (!(IS->isConstexpr() || IS->isConsteval() ||
@@ -666,6 +655,21 @@
   continue;
 }
 
+// If an asm goto jumps to a different scope, things like destructors or
+// initializers might not be run which may be suprising to users. Perhaps
+// this behavior can be changed in the future, but today Clang will not
+// generate such code. Produce a diagnostic instead.
+if (auto *G = dyn_cast(Jump)) {
+  for (AddrLabelExpr *L : G->labels()) {
+LabelDecl *LD = L->getLabel();
+unsigned JumpScope = LabelAndGotoScopes[G];
+unsigned TargetScope = LabelAndGotoScopes[LD->getStmt()];
+if (JumpScope != TargetScope)
+  DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
+  }
+  continue;
+}
+
 // We only get indirect gotos here when they have a constant target.
 if (IndirectGotoStmt *IGS = dyn_cast(Jump)) {
   LabelDecl *Target = IGS->getConstantTarget();
@@ -694,17 +698,16 @@
   }
 }

[PATCH] D155635: [OpenMP] [Reduction] Allow PLUS (+) operator on reduction clauses in OMP > 52

2023-07-18 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay created this revision.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
mdfazlay requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

Currently, clang gives an incorrect reduction identifier error for the PLUS
operator for OpenMP version > 52. But, PLUS operator is allowed in OpenMP
version > 52. This revision fixes this issue and also modified the error
messages to show the correct expected operators in the message based on the 
OpenMP
version used (prior to OMP 6.0 and since OMP 6.0).

**Test Src:**

  void foo() {
   int a = 0 ;
#pragma omp parallel reduction(+:a)
   ;
 #pragma omp parallel reduction(-:a)
   ;
   }

**Before this revision:**

  $ clang -fopenmp -fopenmp-version=60 test.c -c
  test.c:3:34: error: incorrect reduction identifier, expected one of '+', '-', 
'*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 
'int'
3 |   #pragma omp parallel reduction(+:a)
  |  ^
  test.c:5:34: error: incorrect reduction identifier, expected one of '+', '-', 
'*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 
'int'
5 |   #pragma omp parallel reduction(-:a)
  |  ^
  2 errors generated.

**With this revision:**

  $  clang -fopenmp -fopenmp-version=60 test.c -c
  test.c:5:34: error: incorrect reduction identifier, expected one of '+', '*', 
'&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'
  5 |   #pragma omp parallel reduction(-:a)
|  ^


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155635

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -19169,6 +19169,8 @@
   // operators: +, -, *, &, |, ^, && and ||
   switch (OOK) {
   case OO_Plus:
+BOK = BO_Add;
+break;
   case OO_Minus:
 // Minus(-) operator is not supported in TR11 (OpenMP 6.0). Setting BOK to
 // BO_Comma will automatically diagnose it for OpenMP > 52 as not allowed
@@ -19418,9 +19420,14 @@
 }
 if (BOK == BO_Comma && DeclareReductionRef.isUnset()) {
   // Not allowed reduction identifier is found.
-  S.Diag(ReductionId.getBeginLoc(),
- diag::err_omp_unknown_reduction_identifier)
-  << Type << ReductionIdRange;
+  if (S.LangOpts.OpenMP > 52)
+S.Diag(ReductionId.getBeginLoc(),
+   diag::err_omp_unknown_reduction_identifier_since_omp_6_0)
+<< Type << ReductionIdRange;
+  else
+S.Diag(ReductionId.getBeginLoc(),
+   diag::err_omp_unknown_reduction_identifier_prior_omp_6_0)
+<< Type << ReductionIdRange;
   continue;
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10679,9 +10679,12 @@
 def warn_omp_loop_64_bit_var : Warning<
   "OpenMP loop iteration variable cannot have more than 64 bits size and will 
be narrowed">,
   InGroup;
-def err_omp_unknown_reduction_identifier : Error<
+def err_omp_unknown_reduction_identifier_prior_omp_6_0 : Error<
   "incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', 
'^', "
   "'&&', '||', 'min' or 'max' or declare reduction for type %0">;
+def err_omp_unknown_reduction_identifier_since_omp_6_0 : Error<
+  "incorrect reduction identifier, expected one of '+', '*', '&', '|', '^', "
+  "'&&', '||', 'min' or 'max' or declare reduction for type %0">;
 def err_omp_not_resolved_reduction_identifier : Error<
   "unable to resolve declare reduction construct for type %0">;
 def err_omp_reduction_ref_type_arg : Error<


Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -19169,6 +19169,8 @@
   // operators: +, -, *, &, |, ^, && and ||
   switch (OOK) {
   case OO_Plus:
+BOK = BO_Add;
+break;
   case OO_Minus:
 // Minus(-) operator is not supported in TR11 (OpenMP 6.0). Setting BOK to
 // BO_Comma will automatically diagnose it for OpenMP > 52 as not allowed
@@ -19418,9 +19420,14 @@
 }
 if (BOK == BO_Comma && DeclareReductionRef.isUnset()) {
   // Not allowed reduction identifier is found.
-  S.Diag(ReductionId.getBeginLoc(),
- diag::err_omp_unknown_reduction_identifier)
-  << Type << ReductionIdRange;
+  if (S.LangOpts.OpenMP > 52)
+S.Diag(ReductionId.getBeginLoc(),
+   

[PATCH] D155625: [clang-tidy] Warn only for copyable/movable classes in cppcoreguidelines-avoid-const-or-ref-members

2023-07-18 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.

LGTM, but I'm not sure if isCopyableOrMovable will always work correctly, for a 
user defined special members it looks ok, but for some implicit ones I worry it 
may not always work. Probably things like "(hasSimpleCopyAssigment()) || 
(hasUserDeclaredCopyAssigment() && check here if its not deleted)" would be 
needed.
Thing is that CXXRecordDecl got most info (in confused way), there are things 
like DefaultedMoveConstructorIsDeleted that could be used to verify somehow 
base class.




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp:91-102
+  Finder->addMatcher(
+  fieldDecl(unless(isMemberOfLambda()),
+hasDeclContext(cxxRecordDecl(isCopyableOrMovable())),
+hasType(hasCanonicalType(referenceType(
+  .bind("ref"),
+  this);
+  Finder->addMatcher(

Check first type, should be cheaper and consider mering those two. 



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-const-or-ref-data-members.rst:6
 
-This check warns when structs or classes have const-qualified or reference
-(lvalue or rvalue) data members. Having such members is rarely useful, and
-makes the class only copy-constructible but not copy-assignable.
+This check warns when structs or classes that are copyable or movable have
+const-qualified or reference (lvalue or rvalue) data members. Having such




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155625

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


  1   2   3   4   >