[PATCH] D142564: [clang-doc] Reduce duplicate code with template

2023-01-25 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek 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/D142564/new/

https://reviews.llvm.org/D142564

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


[clang] 7f48154 - Re-apply "[clang][Interp] Fix left-/right-shifting more than sizeof(unsigned)"

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-26T08:02:27+01:00
New Revision: 7f48154ca11fee6579fe29a51ab2a329424d31c4

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

LOG: Re-apply "[clang][Interp] Fix left-/right-shifting more than 
sizeof(unsigned)"

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/shifts.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index d5368167d967..0eb0990a0334 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -234,6 +234,18 @@ template  class Integral final 
{
 return false;
   }
 
+  template 
+  static void shiftLeft(const Integral A, const Integral B,
+unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V << B.V, OpBits);
+  }
+
+  template 
+  static void shiftRight(const Integral A, const Integral B,
+ unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V >> B.V, OpBits);
+  }
+
 private:
   template  static bool CheckAddUB(T A, T B, T ) {
 if constexpr (std::is_signed_v) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 466df04ac08d..b36b513c067f 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1334,8 +1334,9 @@ inline bool Shr(InterpState , CodePtr OpPC) {
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) >> URHS, LHS.bitWidth()));
+  Integral R;
+  Integral::shiftRight(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 
@@ -1350,9 +1351,9 @@ inline bool Shl(InterpState , CodePtr OpPC) {
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) << URHS, LHS.bitWidth()));
-
+  Integral R;
+  Integral::shiftLeft(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 

diff  --git a/clang/test/AST/Interp/shifts.cpp 
b/clang/test/AST/Interp/shifts.cpp
index 8fa78beb9302..3b2fc2619fe3 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -143,4 +143,13 @@ namespace shifts {
 
   constexpr char c2 = 1;
   constexpr int i3 = c2 << (__CHAR_BIT__ + 1); // Not ill-formed
+
+  /// The purpose of these few lines is to test that we can shift more bits
+  /// than an unsigned *of the host* has. There was a bug where we casted
+  /// to host-unsigned. However, we cannot query what a host-unsigned even is
+  /// here, so only test this on platforms where `sizeof(long long) > 
sizeof(unsigned)`.
+  constexpr long long int L = 1;
+  constexpr signed int R = (sizeof(unsigned) * 8) + 1;
+  constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
+  constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
 };



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


[clang] 7e629e4 - [AST] Use llvm::bit_width (NFC)

2023-01-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-01-25T22:59:51-08:00
New Revision: 7e629e4e888262abd8f076512b252208acd72d62

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

LOG: [AST] Use llvm::bit_width (NFC)

Added: 


Modified: 
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index a713d6e3bd03..206cf6ee09d2 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -158,7 +158,7 @@ unsigned ConstantArrayType::getNumAddressingBits(const 
ASTContext ,
   if ((ElementSize >> 32) == 0 && NumElements.getBitWidth() <= 64 &&
   (NumElements.getZExtValue() >> 32) == 0) {
 uint64_t TotalSize = NumElements.getZExtValue() * ElementSize;
-return 64 - llvm::countLeadingZeros(TotalSize);
+return llvm::bit_width(TotalSize);
   }
 
   // Otherwise, use APSInt to handle arbitrary sized values.



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


[PATCH] D139774: [libclang] Add API to set temporary directory location

2023-01-25 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy added a comment.

3 out of 4 alternatives remain:

> 1. Add an option to store the preamble-*.pch files in RAM instead of /tmp and 
> add a corresponding option in KDevelop configuration UI. This would work 
> perfectly for me, provided I don't change my mind and decide to turn this 
> option off, in which case I'll be back to square one.
> 2. Add an option to store the preamble-*.pch files in a custom directory 
> instead of a general temporary directory. The option could be named generally 
> (2a: overrideTemporaryDirectory) or specially (2b: setPreambleStoragePath). 
> If the option is named generally, other temporary files created by libclang 
> could be identified in the future and placed in the same directory without 
> changing the API.
> 3. 1 and 2 - the options can be propagated between identical end points 
> together, so this combination is natural.

I think **#3** is the way to go. @aaron.ballman has agreed to this.

**#3a** vs **#3b** hasn't been decided upon yet:

> The bool (1) and the path (2) options can be passed through API layers 
> together in a struct. They can both be named generally 
> (preferStoringTempFilesInMemory, setTemporaryDirectory) or specifically 
> (storePreamblesInMemory, setPreambleStoragePath).

@aaron.ballman has put forth arguments in favor of specific names and separate 
API for different temporary directory uses. I have replied with 
counterarguments in favor of general temporary storage API.

In D139774#4081055 , @aaron.ballman 
wrote:

> modify `FileSystemOptions` to store an override for the temp directory

I have mentioned that `FileSystemOptions` is widely used and only class 
`ASTUnit` would need the temp directory (and possibly a flag whether to prefer 
RAM storage). The wide usage in itself is not considered a reason not to add 
data members.

`ASTUnit::FileSystemOpts` is used in several places in //ASTUnit.cpp//:

  FileSystemOpts = Clang->getFileSystemOpts();
  AST->FileSystemOpts = CI->getFileSystemOpts();
  AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
  AST->FileSystemOpts = FileMgr->getFileSystemOpts();

I don't know whether propagating the new options to and from 
`CompilerInstance`, `CompilerInvocation` and `FileManager` is a good idea. As 
of now, only `ASTUnit::getMainBufferWithPrecompiledPreamble()` is going to use 
the new options.

> and updating APIs so that the temp directory can be specified by a new CIndex 
> constructor function.

Now that the temporary directory options are going to be propagated explicitly, 
I am no longer sure another constructor function is preferable to separate 
option setter(s). I don't see any use for temporary directory location in the 
definition of `clang_createIndex()`. And modifying the temporary directory 
location multiple times during program execution is no longer a problem: an 
updated location will be used for new preambles.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139774

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


[clang] 136c7ef - Revert "[clang][Interp] Fix left-/right-shifting more than sizeof(unsigned)"

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-26T07:49:10+01:00
New Revision: 136c7ef5d10fca0af101821b05084b428830e670

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

LOG: Revert "[clang][Interp] Fix left-/right-shifting more than 
sizeof(unsigned)"

This reverts commit 00e967f6c2d626d1913f5af5763beab7946978ce.

This breaks builders where long is only 32 bits, e.g.
https://lab.llvm.org/buildbot/#/builders/65/builds/7721
https://lab.llvm.org/buildbot/#/builders/245/builds/3899

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/shifts.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 0eb0990a0334..d5368167d967 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -234,18 +234,6 @@ template  class Integral final 
{
 return false;
   }
 
-  template 
-  static void shiftLeft(const Integral A, const Integral B,
-unsigned OpBits, Integral *R) {
-*R = Integral::from(A.V << B.V, OpBits);
-  }
-
-  template 
-  static void shiftRight(const Integral A, const Integral B,
- unsigned OpBits, Integral *R) {
-*R = Integral::from(A.V >> B.V, OpBits);
-  }
-
 private:
   template  static bool CheckAddUB(T A, T B, T ) {
 if constexpr (std::is_signed_v) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b36b513c067f..466df04ac08d 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1334,9 +1334,8 @@ inline bool Shr(InterpState , CodePtr OpPC) {
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  Integral R;
-  Integral::shiftRight(LHS.toUnsigned(), RHS, Bits, );
-  S.Stk.push(R);
+  unsigned URHS = static_cast(RHS);
+  S.Stk.push(LT::from(static_cast(LHS) >> URHS, LHS.bitWidth()));
   return true;
 }
 
@@ -1351,9 +1350,9 @@ inline bool Shl(InterpState , CodePtr OpPC) {
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  Integral R;
-  Integral::shiftLeft(LHS.toUnsigned(), RHS, Bits, );
-  S.Stk.push(R);
+  unsigned URHS = static_cast(RHS);
+  S.Stk.push(LT::from(static_cast(LHS) << URHS, LHS.bitWidth()));
+
   return true;
 }
 

diff  --git a/clang/test/AST/Interp/shifts.cpp 
b/clang/test/AST/Interp/shifts.cpp
index a9193258e6f5..8fa78beb9302 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -143,9 +143,4 @@ namespace shifts {
 
   constexpr char c2 = 1;
   constexpr int i3 = c2 << (__CHAR_BIT__ + 1); // Not ill-formed
-
-  constexpr signed long int L = 1;
-  constexpr signed int R = 62;
-  constexpr decltype(L) M = L << R;
-  constexpr decltype(L) M2 = L >> R;
 };



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


[clang] 5bf56a5 - [clang][Interp][NFCI] Don't crash on void builtin functions

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-26T07:32:33+01:00
New Revision: 5bf56a58775cb235b7ed9e9fcc6895b797e9721b

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

LOG: [clang][Interp][NFCI] Don't crash on void builtin functions

classifyPrim() runs into a llvm_unreachable() for those.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index aaab980ac81b..316ba6356436 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1479,10 +1479,9 @@ bool 
ByteCodeExprGen::VisitBuiltinCallExpr(const CallExpr *E) {
   if (!this->emitCallBI(Func, E))
 return false;
 
-  if (DiscardResult) {
-QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+  QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+  if (DiscardResult && !ReturnType->isVoidType()) {
 PrimType T = classifyPrim(ReturnType);
-
 return this->emitPop(T, E);
   }
 



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


[PATCH] D142604: [Clang] Fix __VA_OPT__ implementation so that it treats the concatenation of a non-placemaker token and placemaker token as a non-placemaker token

2023-01-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane, hubert.reinterpretcast.
Herald added a project: All.
shafik requested review of this revision.

Currently the implementation of `__VA_OPT__` will treat the concatenation of a 
non-placemaker token and placemaker token as a placemaker token which is not 
correct. This will fix the implementation and treat the result as a 
non-placemaker token.

This fixes: https://github.com/llvm/llvm-project/issues/60268


https://reviews.llvm.org/D142604

Files:
  clang/lib/Lex/TokenLexer.cpp
  clang/test/Preprocessor/macro_vaopt_p1042r1.cpp


Index: clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
===
--- clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
+++ clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
@@ -28,3 +28,9 @@
 #define H5C(X) H5B(X)
 5: H5C(H5A())
 // CHECK: 5: ab
+
+namespace GH60268 {
+#define H6(X, ...) __VA_OPT__(a ## X) ## b
+6: H6(, 1);  
+// CHECK: 6: ab
+}
Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -501,7 +501,7 @@
   assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__");
   VCtx.hasPlaceholderAfterHashhashAtStart();
 }
-if (RParenAfter)
+else if (RParenAfter)
   VCtx.hasPlaceholderBeforeRParen();
   }
   continue;
@@ -567,7 +567,7 @@
   continue;
 }
 
-if (RParenAfter)
+if (RParenAfter && !NonEmptyPasteBefore)
   VCtx.hasPlaceholderBeforeRParen();
 
 // If this is on the RHS of a paste operator, we've already copied the


Index: clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
===
--- clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
+++ clang/test/Preprocessor/macro_vaopt_p1042r1.cpp
@@ -28,3 +28,9 @@
 #define H5C(X) H5B(X)
 5: H5C(H5A())
 // CHECK: 5: ab
+
+namespace GH60268 {
+#define H6(X, ...) __VA_OPT__(a ## X) ## b
+6: H6(, 1);  
+// CHECK: 6: ab
+}
Index: clang/lib/Lex/TokenLexer.cpp
===
--- clang/lib/Lex/TokenLexer.cpp
+++ clang/lib/Lex/TokenLexer.cpp
@@ -501,7 +501,7 @@
   assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__");
   VCtx.hasPlaceholderAfterHashhashAtStart();
 }
-if (RParenAfter)
+else if (RParenAfter)
   VCtx.hasPlaceholderBeforeRParen();
   }
   continue;
@@ -567,7 +567,7 @@
   continue;
 }
 
-if (RParenAfter)
+if (RParenAfter && !NonEmptyPasteBefore)
   VCtx.hasPlaceholderBeforeRParen();
 
 // If this is on the RHS of a paste operator, we've already copied the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141472: [clang][Interp] Add function pointers

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

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

https://reviews.llvm.org/D141472

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/FunctionPointer.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.cpp
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -99,3 +99,58 @@
   huh(); // expected-error {{use of undeclared identifier}} \
  // ref-error {{use of undeclared identifier}}
 }
+
+namespace FunctionPointers {
+  constexpr int add(int a, int b) {
+return a + b;
+  }
+
+  struct S { int a; };
+  constexpr S getS() {
+return S{12};
+  }
+
+  constexpr int applyBinOp(int a, int b, int (*op)(int, int)) {
+return op(a, b);
+  }
+  static_assert(applyBinOp(1, 2, add) == 3, "");
+
+  constexpr int ignoreReturnValue() {
+int (*foo)(int, int) = add;
+
+foo(1, 2);
+return 1;
+  }
+  static_assert(ignoreReturnValue() == 1, "");
+
+  constexpr int createS(S (*gimme)()) {
+gimme(); // Ignored return value
+return gimme().a;
+  }
+  static_assert(createS(getS) == 12, "");
+
+namespace FunctionReturnType {
+  typedef int (*ptr)(int*);
+  typedef ptr (*pm)();
+
+  constexpr int fun1(int* y) {
+  return *y + 10;
+  }
+  constexpr ptr fun() {
+  return 
+  }
+  static_assert(fun() == nullptr, ""); // expected-error {{static assertion failed}} \
+   // ref-error {{static assertion failed}}
+
+  constexpr int foo() {
+int (*f)(int *) = fun();
+int m = 0;
+
+m = f();
+
+return m;
+  }
+  static_assert(foo() == 10);
+}
+
+}
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -24,6 +24,7 @@
 class Pointer;
 class Boolean;
 class Floating;
+class FunctionPointer;
 
 /// Enumeration of the primitive types of the VM.
 enum PrimType : unsigned {
@@ -38,6 +39,7 @@
   PT_Bool,
   PT_Float,
   PT_Ptr,
+  PT_FnPtr,
 };
 
 /// Mapping from primitive types to their representation.
@@ -53,6 +55,7 @@
 template <> struct PrimConv { using T = Floating; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
+template <> struct PrimConv { using T = FunctionPointer; };
 
 /// Returns the size of a primitive type in bytes.
 size_t primSize(PrimType Type);
@@ -90,6 +93,7 @@
   TYPE_SWITCH_CASE(PT_Float, B)\
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
+  TYPE_SWITCH_CASE(PT_FnPtr, B)\
 }  \
   } while (0)
 #define COMPOSITE_TYPE_SWITCH(Expr, B, D)  \
Index: clang/lib/AST/Interp/PrimType.cpp
===
--- clang/lib/AST/Interp/PrimType.cpp
+++ clang/lib/AST/Interp/PrimType.cpp
@@ -9,6 +9,7 @@
 #include "PrimType.h"
 #include "Boolean.h"
 #include "Floating.h"
+#include "FunctionPointer.h"
 #include "Pointer.h"
 
 using namespace clang;
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -27,6 +27,7 @@
 def Uint64 : Type;
 def Float : Type;
 def Ptr : Type;
+def FnPtr : Type;
 
 //===--===//
 // Types transferred to the interpreter.
@@ -77,7 +78,7 @@
 }
 
 def PtrTypeClass : TypeClass {
-  let Types = [Ptr];
+  let Types = [Ptr, FnPtr];
 }
 
 def BoolTypeClass : TypeClass {
@@ -187,6 +188,12 @@
   let ChangesPC = 1;
 }
 
+def CallPtr : Opcode {
+  let Args = [];
+  let Types = [];
+  let ChangesPC = 1;
+}
+
 //===--===//
 // Frame management
 //===--===//
@@ -228,6 +235,7 @@
 // [] -> [Pointer]
 def Null : Opcode {
   let Types = [PtrTypeClass];
+  let HasGroup = 1;
 }
 
 //===--===//
@@ -447,6 +455,14 @@
   let HasGroup = 0;
 }
 
+//===--===//
+// Function pointers.

[PATCH] D131306: [llvm][misexpect] Track provenance of branch weights

2023-01-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Drive by: There should be a lang ref component to this. Also, changing branch 
weight metadata might impact downstream users, an RFC seems in order (assuming 
I didn't miss one).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131306

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


[PATCH] D142596: [RISCV] Bump Zca, Zcd, Zcf version to 1.0.

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492337.
craig.topper added a comment.

Update tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142596

Files:
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -176,8 +176,14 @@
 .attribute arch, "rv32if_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 
-.attribute arch, "rv32izca0p70"
-# CHECK: attribute  5, "rv32i2p0_zca0p70"
+.attribute arch, "rv32izca1p0"
+# CHECK: attribute  5, "rv32i2p0_zca1p0"
+
+.attribute arch, "rv32izcd1p0"
+# CHECK: attribute  5, "rv32i2p0_zcd1p0"
+
+.attribute arch, "rv32izcf1p0"
+# CHECK: attribute  5, "rv32i2p0_zcf1p0"
 
 .attribute arch, "rv32izawrs1p0"
 # CHECK: attribute  5, "rv32i2p0_zawrs1p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -41,6 +41,8 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+svpbmt %s -o - | FileCheck --check-prefix=RV32SVPBMT %s
 ; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zca %s -o - | FileCheck --check-prefix=RV32ZCA %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcd %s -o - | FileCheck --check-prefix=RV32ZCD %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcf %s -o - | FileCheck --check-prefix=RV32ZCF %s
 
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
@@ -87,6 +89,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zca %s -o - | FileCheck --check-prefix=RV64ZCA %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcd %s -o - | FileCheck --check-prefix=RV64ZCD %s
 
 ; RV32M: .attribute 5, "rv32i2p0_m2p0"
 ; RV32ZMMUL: .attribute 5, "rv32i2p0_zmmul1p0"
@@ -128,7 +131,9 @@
 ; RV32SVNAPOT: .attribute 5, "rv32i2p0_svnapot1p0"
 ; RV32SVPBMT: .attribute 5, "rv32i2p0_svpbmt1p0"
 ; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
-; RV32ZCA: .attribute 5, "rv32i2p0_zca0p70"
+; RV32ZCA: .attribute 5, "rv32i2p0_zca1p0"
+; RV32ZCD: .attribute 5, "rv32i2p0_zcd1p0"
+; RV32ZCF: .attribute 5, "rv32i2p0_zcf1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -174,7 +179,8 @@
 ; RV64XVENTANACONDOPS: .attribute 5, "rv64i2p0_xventanacondops1p0"
 ; RV64XTHEADVDOT: .attribute 5, "rv64i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_xtheadvdot1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
-; RV64ZCA: .attribute 5, "rv64i2p0_zca0p70"
+; RV64ZCA: .attribute 5, "rv64i2p0_zca1p0"
+; RV64ZCD: .attribute 5, "rv64i2p0_zcd1p0"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -114,9 +114,9 @@
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
 {"zihintntl", RISCVExtensionVersion{0, 2}},
 
-{"zca", RISCVExtensionVersion{0, 70}},
-{"zcd", RISCVExtensionVersion{0, 70}},
-{"zcf", RISCVExtensionVersion{0, 70}},
+{"zca", RISCVExtensionVersion{1, 0}},
+{"zcd", RISCVExtensionVersion{1, 0}},
+{"zcf", RISCVExtensionVersion{1, 0}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 {"ztso", RISCVExtensionVersion{0, 1}},
Index: llvm/docs/RISCVUsage.rst
===
--- llvm/docs/RISCVUsage.rst
+++ llvm/docs/RISCVUsage.rst
@@ -136,13 +136,13 @@
   LLVM implements the `1.0-rc3 draft specification `_.  Note that have been backwards incompatible changes made between release candidates for the 1.0 draft.
 
 ``experimental-zca``
-  LLVM implements the `0.70 draft specification `_.
+  LLVM implements the `1.0.1 draft specification `_.
 
 ``experimental-zcd``
-  LLVM 

[PATCH] D141472: [clang][Interp] Add function pointers

2023-01-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:138-139
   case CK_IntegralToPointer: {
 if (isa(SubExpr))
   return this->visit(SubExpr);
 

aaron.ballman wrote:
> Can we still reach this bit now?
Nope!


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

https://reviews.llvm.org/D141472

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


[PATCH] D137706: [clang][Interp] Implement IntegralToPointer casts

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

Note that according to 
https://clang.llvm.org/docs/ConstantInterpreter.html#pointers, such pointers 
had their own pointer type (`TargetPointer`), so I'm not sure if the approach 
here is the right one.


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

https://reviews.llvm.org/D137706

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


[PATCH] D142596: [RISCV] Bump Zca version to 1.0.

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492331.
craig.topper added a comment.

Add Zcf and Zcd too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142596

Files:
  clang/test/Driver/riscv-arch.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -176,8 +176,8 @@
 .attribute arch, "rv32if_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 
-.attribute arch, "rv32izca0p70"
-# CHECK: attribute  5, "rv32i2p0_zca0p70"
+.attribute arch, "rv32izca1p0"
+# CHECK: attribute  5, "rv32i2p0_zca1p0"
 
 .attribute arch, "rv32izawrs1p0"
 # CHECK: attribute  5, "rv32i2p0_zawrs1p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -128,7 +128,7 @@
 ; RV32SVNAPOT: .attribute 5, "rv32i2p0_svnapot1p0"
 ; RV32SVPBMT: .attribute 5, "rv32i2p0_svpbmt1p0"
 ; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
-; RV32ZCA: .attribute 5, "rv32i2p0_zca0p70"
+; RV32ZCA: .attribute 5, "rv32i2p0_zca1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -174,7 +174,7 @@
 ; RV64XVENTANACONDOPS: .attribute 5, "rv64i2p0_xventanacondops1p0"
 ; RV64XTHEADVDOT: .attribute 5, 
"rv64i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_xtheadvdot1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
-; RV64ZCA: .attribute 5, "rv64i2p0_zca0p70"
+; RV64ZCA: .attribute 5, "rv64i2p0_zca1p0"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -114,9 +114,9 @@
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
 {"zihintntl", RISCVExtensionVersion{0, 2}},
 
-{"zca", RISCVExtensionVersion{0, 70}},
-{"zcd", RISCVExtensionVersion{0, 70}},
-{"zcf", RISCVExtensionVersion{0, 70}},
+{"zca", RISCVExtensionVersion{1, 0}},
+{"zcd", RISCVExtensionVersion{1, 0}},
+{"zcf", RISCVExtensionVersion{1, 0}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"zawrs", RISCVExtensionVersion{1, 0}},
 {"ztso", RISCVExtensionVersion{0, 1}},
Index: llvm/docs/RISCVUsage.rst
===
--- llvm/docs/RISCVUsage.rst
+++ llvm/docs/RISCVUsage.rst
@@ -136,13 +136,13 @@
   LLVM implements the `1.0-rc3 draft specification 
`_.  
Note that have been backwards incompatible changes made between release 
candidates for the 1.0 draft.
 
 ``experimental-zca``
-  LLVM implements the `0.70 draft specification 
`_.
+  LLVM implements the `1.0.1 draft specification 
`_.
 
 ``experimental-zcd``
-  LLVM implements the `0.70 draft specification 
`_.
+  LLVM implements the `1.0.1 draft specification 
`_.
 
 ``experimental-zcf``
-  LLVM implements the `0.70 draft specification 
`_.
+  LLVM implements the `1.0.1 draft specification 
`_.
 
 ``experimental-zihintntl``
   LLVM implements the `0.2 draft specification 
`_.
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -430,9 +430,9 @@
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32izca0p1 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS 
%s
 // RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32izca0p1'
-// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zca' (this compiler supports 0.70)
+// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zca' (this compiler supports 1.0)
 
-// RUN: %clang --target=riscv32-unknown-elf -march=rv32izca0p70 
-menable-experimental-extensions 

[PATCH] D140845: [clang][Interp] Fix left-/right-shifting more than sizeof(unsigned)

2023-01-25 Thread Timm Bäder 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 rG00e967f6c2d6: [clang][Interp] Fix left-/right-shifting more 
than sizeof(unsigned) (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140845

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/shifts.cpp


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -143,4 +143,9 @@
 
   constexpr char c2 = 1;
   constexpr int i3 = c2 << (__CHAR_BIT__ + 1); // Not ill-formed
+
+  constexpr signed long int L = 1;
+  constexpr signed int R = 62;
+  constexpr decltype(L) M = L << R;
+  constexpr decltype(L) M2 = L >> R;
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1334,8 +1334,9 @@
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) >> URHS, LHS.bitWidth()));
+  Integral R;
+  Integral::shiftRight(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 
@@ -1350,9 +1351,9 @@
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) << URHS, LHS.bitWidth()));
-
+  Integral R;
+  Integral::shiftLeft(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -234,6 +234,18 @@
 return false;
   }
 
+  template 
+  static void shiftLeft(const Integral A, const Integral B,
+unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V << B.V, OpBits);
+  }
+
+  template 
+  static void shiftRight(const Integral A, const Integral B,
+ unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V >> B.V, OpBits);
+  }
+
 private:
   template  static bool CheckAddUB(T A, T B, T ) {
 if constexpr (std::is_signed_v) {


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -143,4 +143,9 @@
 
   constexpr char c2 = 1;
   constexpr int i3 = c2 << (__CHAR_BIT__ + 1); // Not ill-formed
+
+  constexpr signed long int L = 1;
+  constexpr signed int R = 62;
+  constexpr decltype(L) M = L << R;
+  constexpr decltype(L) M2 = L >> R;
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1334,8 +1334,9 @@
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) >> URHS, LHS.bitWidth()));
+  Integral R;
+  Integral::shiftRight(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 
@@ -1350,9 +1351,9 @@
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) << URHS, LHS.bitWidth()));
-
+  Integral R;
+  Integral::shiftLeft(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -234,6 +234,18 @@
 return false;
   }
 
+  template 
+  static void shiftLeft(const Integral A, const Integral B,
+unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V << B.V, OpBits);
+  }
+
+  template 
+  static void shiftRight(const Integral A, const Integral B,
+ unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V >> B.V, OpBits);
+  }
+
 private:
   template  static bool CheckAddUB(T A, T B, T ) {
 if constexpr (std::is_signed_v) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 00e967f - [clang][Interp] Fix left-/right-shifting more than sizeof(unsigned)

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-26T07:07:17+01:00
New Revision: 00e967f6c2d626d1913f5af5763beab7946978ce

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

LOG: [clang][Interp] Fix left-/right-shifting more than sizeof(unsigned)

We were just casting to `unsigned` before, so that caused problems when
shifting more bits than `unsigned` has.

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

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/shifts.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index d5368167d967..0eb0990a0334 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -234,6 +234,18 @@ template  class Integral final 
{
 return false;
   }
 
+  template 
+  static void shiftLeft(const Integral A, const Integral B,
+unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V << B.V, OpBits);
+  }
+
+  template 
+  static void shiftRight(const Integral A, const Integral B,
+ unsigned OpBits, Integral *R) {
+*R = Integral::from(A.V >> B.V, OpBits);
+  }
+
 private:
   template  static bool CheckAddUB(T A, T B, T ) {
 if constexpr (std::is_signed_v) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 466df04ac08d..b36b513c067f 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1334,8 +1334,9 @@ inline bool Shr(InterpState , CodePtr OpPC) {
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) >> URHS, LHS.bitWidth()));
+  Integral R;
+  Integral::shiftRight(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 
@@ -1350,9 +1351,9 @@ inline bool Shl(InterpState , CodePtr OpPC) {
   if (!CheckShift(S, OpPC, RHS, Bits))
 return false;
 
-  unsigned URHS = static_cast(RHS);
-  S.Stk.push(LT::from(static_cast(LHS) << URHS, LHS.bitWidth()));
-
+  Integral R;
+  Integral::shiftLeft(LHS.toUnsigned(), RHS, Bits, );
+  S.Stk.push(R);
   return true;
 }
 

diff  --git a/clang/test/AST/Interp/shifts.cpp 
b/clang/test/AST/Interp/shifts.cpp
index 8fa78beb9302..a9193258e6f5 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -143,4 +143,9 @@ namespace shifts {
 
   constexpr char c2 = 1;
   constexpr int i3 = c2 << (__CHAR_BIT__ + 1); // Not ill-formed
+
+  constexpr signed long int L = 1;
+  constexpr signed int R = 62;
+  constexpr decltype(L) M = L << R;
+  constexpr decltype(L) M2 = L >> R;
 };



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


[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492325.
craig.topper added a comment.

Update RISCVUsage.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrFormatsC.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' 

[PATCH] D142592: [clang-tidy][libc] Add an inline function checker for the libc project.

2023-01-25 Thread Siva Chandra via Phabricator via cfe-commits
sivachandra updated this revision to Diff 492324.
sivachandra added a comment.

Use explicit type instead of auto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142592

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl-check.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.h

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.h
@@ -0,0 +1,56 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
+#define LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
+
+#define LIBC_INLINE inline
+
+namespace __llvm_libc {
+
+LIBC_INLINE int addi(int a, int b) {
+  return a + b;
+}
+
+LIBC_INLINE constexpr long addl(long a, long b) {
+  return a + b;
+}
+
+constexpr long long addll(long long a, long long b) {
+  return a + b;
+}
+
+inline unsigned long addul(unsigned long a, unsigned long b) {
+  return a + b;
+}
+
+class  MyClass {
+  int A;
+public:
+  MyClass() : A(123) {}
+
+  LIBC_INLINE MyClass(int V) : A(V) {}
+
+  constexpr operator int() const { return A; }
+
+  LIBC_INLINE bool operator==(const MyClass ) {
+return RHS.A == A;
+  }
+
+  static int getVal(const MyClass ) {
+return V.A;
+  }
+
+  LIBC_INLINE static void setVal(MyClass , int A) {
+V.A = A;
+  }
+
+  constexpr static int addInt(MyClass , int A) {
+return V.A += A;
+  }
+
+  static LIBC_INLINE int mulInt(MyClass , int A) {
+return V.A *= A;
+  }
+};
+
+} // namespace __llvm_libc
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s llvmlibc-inline-function-decl-check %t \
+// RUN:   -- -header-filter=.* -- -I %S
+
+#include "inline-function-decl.h"
+
+namespace __llvm_libc {
+
+// Inline functions in .cpp files need not use the LIBC_INLINE tag.
+inline float addf(float a, float b) {
+  return a + b;
+}
+
+// Non-inline functions should not trigger any warning.
+int mul(int a, int b) {
+  return addf(a * b, b);
+}
+
+// CHECK-MESSAGES: warning: 'addll' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'addul' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'MyClass' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'operator int' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'getVal' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'addInt' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'mulInt' must be tagged with the LIBC_INLINE macro
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl-check.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl-check.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - llvmlibc-inline-funciton-decl-check
+
+llvmlibc-inline-function-decl-check
+
+
+Checks that all implicit and explicit inline functions in header files are
+tagged with the ``LIBC_INLINE`` macro. See the `libc style guide
+`_ for more information about this macro.
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "CalleeNamespaceCheck.h"
 #include "ImplementationInNamespaceCheck.h"
+#include "InlineFunctionDeclCheck.h"
 #include "RestrictSystemLibcHeadersCheck.h"
 
 namespace clang::tidy {
@@ -23,6 +24,8 @@
 "llvmlibc-callee-namespace");
 CheckFactories.registerCheck(
 "llvmlibc-implementation-in-namespace");
+CheckFactories.registerCheck(
+"llvmlibc-inline-function-decl-check");
 CheckFactories.registerCheck(
 "llvmlibc-restrict-system-libc-headers");
   }
Index: 

[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

@VincentWu are you ok with the changes I made?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

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


[PATCH] D140809: [clang][Interp] Implement logical and/or operators

2023-01-25 Thread Timm Bäder 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 rGd2ea8ae5d43e: [clang][Interp] Implement logical and/or 
operators (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D140809?vs=485784=492323#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140809

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/cond.cpp

Index: clang/test/AST/Interp/cond.cpp
===
--- clang/test/AST/Interp/cond.cpp
+++ clang/test/AST/Interp/cond.cpp
@@ -9,3 +9,29 @@
 return a - b;
   }
 }
+
+constexpr int dontCallMe(unsigned m) {
+  if (m == 0) return 0;
+  return dontCallMe(m - 2);
+}
+
+// Can't call this because it will run into infinite recursion.
+constexpr int assertNotReached() {
+  return dontCallMe(3);
+}
+
+static_assert(true || true, "");
+static_assert(true || false, "");
+static_assert(false || true, "");
+static_assert(!(false || false), "");
+
+static_assert(true || assertNotReached(), "");
+static_assert(true || true || true || false, "");
+
+static_assert(true && true, "");
+static_assert(!(true && false), "");
+static_assert(!(false && true), "");
+static_assert(!(false && false), "");
+
+static_assert(!(false && assertNotReached()), "");
+static_assert(!(true && true && true && false), "");
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -61,6 +61,7 @@
   bool VisitFloatingLiteral(const FloatingLiteral *E);
   bool VisitParenExpr(const ParenExpr *E);
   bool VisitBinaryOperator(const BinaryOperator *E);
+  bool VisitLogicalBinOp(const BinaryOperator *E);
   bool VisitPointerArithBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -187,6 +187,10 @@
 
 template 
 bool ByteCodeExprGen::VisitBinaryOperator(const BinaryOperator *BO) {
+  // Need short-circuiting for these.
+  if (BO->isLogicalOp())
+return this->VisitLogicalBinOp(BO);
+
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
@@ -270,8 +274,9 @@
 return Discard(this->emitShr(*LT, *RT, BO));
   case BO_Xor:
 return Discard(this->emitBitXor(*T, BO));
-  case BO_LAnd:
   case BO_LOr:
+  case BO_LAnd:
+llvm_unreachable("Already handled earlier");
   default:
 return this->bail(BO);
   }
@@ -329,6 +334,65 @@
   return this->bail(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitLogicalBinOp(const BinaryOperator *E) {
+  assert(E->isLogicalOp());
+  BinaryOperatorKind Op = E->getOpcode();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+
+  if (Op == BO_LOr) {
+// Logical OR. Visit LHS and only evaluate RHS if LHS was FALSE.
+LabelTy LabelTrue = this->getLabel();
+LabelTy LabelEnd = this->getLabel();
+
+if (!this->visit(LHS))
+  return false;
+if (!this->jumpTrue(LabelTrue))
+  return false;
+
+if (!this->visit(RHS))
+  return false;
+if (!this->jump(LabelEnd))
+  return false;
+
+this->emitLabel(LabelTrue);
+this->emitConstBool(true, E);
+this->fallthrough(LabelEnd);
+this->emitLabel(LabelEnd);
+
+if (DiscardResult)
+  return this->emitPopBool(E);
+
+return true;
+  }
+
+  // Logical AND.
+  // Visit LHS. Only visit RHS if LHS was TRUE.
+  LabelTy LabelFalse = this->getLabel();
+  LabelTy LabelEnd = this->getLabel();
+
+  if (!this->visit(LHS))
+return false;
+  if (!this->jumpFalse(LabelFalse))
+return false;
+
+  if (!this->visit(RHS))
+return false;
+  if (!this->jump(LabelEnd))
+return false;
+
+  this->emitLabel(LabelFalse);
+  this->emitConstBool(false, E);
+  this->fallthrough(LabelEnd);
+  this->emitLabel(LabelEnd);
+
+  if (DiscardResult)
+return this->emitPopBool(E);
+
+  return true;
+}
+
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
   std::optional T = classify(E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d2ea8ae - [clang][Interp] Implement logical and/or operators

2023-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-01-26T06:52:35+01:00
New Revision: d2ea8ae5d43e05791a201e7ca233d3f637254597

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

LOG: [clang][Interp] Implement logical and/or operators

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/cond.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a2f0a77142ad8..aaab980ac81bc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -187,6 +187,10 @@ bool ByteCodeExprGen::VisitParenExpr(const 
ParenExpr *PE) {
 
 template 
 bool ByteCodeExprGen::VisitBinaryOperator(const BinaryOperator *BO) {
+  // Need short-circuiting for these.
+  if (BO->isLogicalOp())
+return this->VisitLogicalBinOp(BO);
+
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
@@ -270,8 +274,9 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
 return Discard(this->emitShr(*LT, *RT, BO));
   case BO_Xor:
 return Discard(this->emitBitXor(*T, BO));
-  case BO_LAnd:
   case BO_LOr:
+  case BO_LAnd:
+llvm_unreachable("Already handled earlier");
   default:
 return this->bail(BO);
   }
@@ -329,6 +334,65 @@ bool 
ByteCodeExprGen::VisitPointerArithBinOp(const BinaryOperator *E) {
   return this->bail(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitLogicalBinOp(const BinaryOperator *E) {
+  assert(E->isLogicalOp());
+  BinaryOperatorKind Op = E->getOpcode();
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+
+  if (Op == BO_LOr) {
+// Logical OR. Visit LHS and only evaluate RHS if LHS was FALSE.
+LabelTy LabelTrue = this->getLabel();
+LabelTy LabelEnd = this->getLabel();
+
+if (!this->visit(LHS))
+  return false;
+if (!this->jumpTrue(LabelTrue))
+  return false;
+
+if (!this->visit(RHS))
+  return false;
+if (!this->jump(LabelEnd))
+  return false;
+
+this->emitLabel(LabelTrue);
+this->emitConstBool(true, E);
+this->fallthrough(LabelEnd);
+this->emitLabel(LabelEnd);
+
+if (DiscardResult)
+  return this->emitPopBool(E);
+
+return true;
+  }
+
+  // Logical AND.
+  // Visit LHS. Only visit RHS if LHS was TRUE.
+  LabelTy LabelFalse = this->getLabel();
+  LabelTy LabelEnd = this->getLabel();
+
+  if (!this->visit(LHS))
+return false;
+  if (!this->jumpFalse(LabelFalse))
+return false;
+
+  if (!this->visit(RHS))
+return false;
+  if (!this->jump(LabelEnd))
+return false;
+
+  this->emitLabel(LabelFalse);
+  this->emitConstBool(false, E);
+  this->fallthrough(LabelEnd);
+  this->emitLabel(LabelEnd);
+
+  if (DiscardResult)
+return this->emitPopBool(E);
+
+  return true;
+}
+
 template 
 bool ByteCodeExprGen::VisitImplicitValueInitExpr(const 
ImplicitValueInitExpr *E) {
   std::optional T = classify(E);

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index ed33e0285a8f1..0a64ff3513dd8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -61,6 +61,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitFloatingLiteral(const FloatingLiteral *E);
   bool VisitParenExpr(const ParenExpr *E);
   bool VisitBinaryOperator(const BinaryOperator *E);
+  bool VisitLogicalBinOp(const BinaryOperator *E);
   bool VisitPointerArithBinOp(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);

diff  --git a/clang/test/AST/Interp/cond.cpp b/clang/test/AST/Interp/cond.cpp
index 1fc69ed333e15..8679c116f57bb 100644
--- a/clang/test/AST/Interp/cond.cpp
+++ b/clang/test/AST/Interp/cond.cpp
@@ -9,3 +9,29 @@ constexpr int cond_then_else(int a, int b) {
 return a - b;
   }
 }
+
+constexpr int dontCallMe(unsigned m) {
+  if (m == 0) return 0;
+  return dontCallMe(m - 2);
+}
+
+// Can't call this because it will run into infinite recursion.
+constexpr int assertNotReached() {
+  return dontCallMe(3);
+}
+
+static_assert(true || true, "");
+static_assert(true || false, "");
+static_assert(false || true, "");
+static_assert(!(false || false), "");
+
+static_assert(true || assertNotReached(), "");
+static_assert(true || true || true || false, "");
+
+static_assert(true && true, "");
+static_assert(!(true && false), "");
+static_assert(!(false && true), "");
+static_assert(!(false && false), "");
+
+static_assert(!(false && assertNotReached()), "");
+static_assert(!(true && true && true && false), "");



___
cfe-commits 

[clang-tools-extra] a5cd202 - Use llvm::Log2_32 and llvm::Log2_64 instead of llvm::findLastSet (NFC)

2023-01-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-01-25T21:34:09-08:00
New Revision: a5cd202e21e52c1e00963ad5bdfeb83b4fec820e

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

LOG: Use llvm::Log2_32 and llvm::Log2_64 instead of llvm::findLastSet (NFC)

For a nonzero argument, llvm::findLastSet(x) is equivalent to
llvm::Log2_32(x) or llvm::Log2_64(x).  None of the calls to
llvm::findLastSet in this patch relies on llvm::findLastSet's ability
to return std::numeric_limits::max() on input 0.

Added: 


Modified: 
clang-tools-extra/clangd/index/dex/PostingList.cpp
clang/lib/CodeGen/SwiftCallingConv.cpp
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/dex/PostingList.cpp 
b/clang-tools-extra/clangd/index/dex/PostingList.cpp
index c02d52734972b..691975d2f2244 100644
--- a/clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ b/clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -132,7 +132,7 @@ bool encodeVByte(DocID Delta, 
llvm::MutableArrayRef ) {
   assert(Delta != 0 && "0 is not a valid PostingList delta.");
   // Calculate number of bytes Delta encoding would take by examining the
   // meaningful bits.
-  unsigned Width = 1 + llvm::findLastSet(Delta) / BitsPerEncodingByte;
+  unsigned Width = 1 + llvm::Log2_64(Delta) / BitsPerEncodingByte;
   if (Width > Payload.size())
 return false;
 

diff  --git a/clang/lib/CodeGen/SwiftCallingConv.cpp 
b/clang/lib/CodeGen/SwiftCallingConv.cpp
index 63d975193c027..055dd37043866 100644
--- a/clang/lib/CodeGen/SwiftCallingConv.cpp
+++ b/clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -728,7 +728,7 @@ void swiftcall::legalizeVectorType(CodeGenModule , 
CharUnits origVectorSize,
 
   // The largest size that we're still considering making subvectors of.
   // Always a power of 2.
-  unsigned logCandidateNumElts = llvm::findLastSet(numElts, 
llvm::ZB_Undefined);
+  unsigned logCandidateNumElts = llvm::Log2_32(numElts);
   unsigned candidateNumElts = 1U << logCandidateNumElts;
   assert(candidateNumElts <= numElts && candidateNumElts * 2 > numElts);
 

diff  --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 22d11a96a8646..78adb143453ee 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -2328,7 +2328,7 @@ static bool isSeveralBitsExtractOpFromShr(SDNode *N, 
unsigned ,
   //
   // This gets selected into a single UBFM:
   //
-  // UBFM Value, ShiftImm, findLastSet(MaskImm)
+  // UBFM Value, ShiftImm, Log2_64(MaskImm)
   //
 
   if (N->getOpcode() != ISD::SRL)
@@ -2350,7 +2350,7 @@ static bool isSeveralBitsExtractOpFromShr(SDNode *N, 
unsigned ,
 
   Opc = N->getValueType(0) == MVT::i32 ? AArch64::UBFMWri : AArch64::UBFMXri;
   LSB = SrlImm;
-  MSB = findLastSet(AndMask, ZB_Undefined);
+  MSB = llvm::Log2_64(AndMask);
   return true;
 }
 

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index c916d5d547c44..9035ae6f7e396 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -761,7 +761,7 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo 
,
   // There are some rare circumstances where InputAddr is non-zero and
   // InputEna can be set to 0. In this case we default to setting LastEna
   // to 1.
-  LastEna = InputEna ? findLastSet(InputEna) + 1 : 1;
+  LastEna = InputEna ? llvm::Log2_32(InputEna) + 1 : 1;
 }
 
 // FIXME: We should be using the number of registers determined during



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


[clang] a5cd202 - Use llvm::Log2_32 and llvm::Log2_64 instead of llvm::findLastSet (NFC)

2023-01-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-01-25T21:34:09-08:00
New Revision: a5cd202e21e52c1e00963ad5bdfeb83b4fec820e

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

LOG: Use llvm::Log2_32 and llvm::Log2_64 instead of llvm::findLastSet (NFC)

For a nonzero argument, llvm::findLastSet(x) is equivalent to
llvm::Log2_32(x) or llvm::Log2_64(x).  None of the calls to
llvm::findLastSet in this patch relies on llvm::findLastSet's ability
to return std::numeric_limits::max() on input 0.

Added: 


Modified: 
clang-tools-extra/clangd/index/dex/PostingList.cpp
clang/lib/CodeGen/SwiftCallingConv.cpp
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/dex/PostingList.cpp 
b/clang-tools-extra/clangd/index/dex/PostingList.cpp
index c02d52734972b..691975d2f2244 100644
--- a/clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ b/clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -132,7 +132,7 @@ bool encodeVByte(DocID Delta, 
llvm::MutableArrayRef ) {
   assert(Delta != 0 && "0 is not a valid PostingList delta.");
   // Calculate number of bytes Delta encoding would take by examining the
   // meaningful bits.
-  unsigned Width = 1 + llvm::findLastSet(Delta) / BitsPerEncodingByte;
+  unsigned Width = 1 + llvm::Log2_64(Delta) / BitsPerEncodingByte;
   if (Width > Payload.size())
 return false;
 

diff  --git a/clang/lib/CodeGen/SwiftCallingConv.cpp 
b/clang/lib/CodeGen/SwiftCallingConv.cpp
index 63d975193c027..055dd37043866 100644
--- a/clang/lib/CodeGen/SwiftCallingConv.cpp
+++ b/clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -728,7 +728,7 @@ void swiftcall::legalizeVectorType(CodeGenModule , 
CharUnits origVectorSize,
 
   // The largest size that we're still considering making subvectors of.
   // Always a power of 2.
-  unsigned logCandidateNumElts = llvm::findLastSet(numElts, 
llvm::ZB_Undefined);
+  unsigned logCandidateNumElts = llvm::Log2_32(numElts);
   unsigned candidateNumElts = 1U << logCandidateNumElts;
   assert(candidateNumElts <= numElts && candidateNumElts * 2 > numElts);
 

diff  --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 22d11a96a8646..78adb143453ee 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -2328,7 +2328,7 @@ static bool isSeveralBitsExtractOpFromShr(SDNode *N, 
unsigned ,
   //
   // This gets selected into a single UBFM:
   //
-  // UBFM Value, ShiftImm, findLastSet(MaskImm)
+  // UBFM Value, ShiftImm, Log2_64(MaskImm)
   //
 
   if (N->getOpcode() != ISD::SRL)
@@ -2350,7 +2350,7 @@ static bool isSeveralBitsExtractOpFromShr(SDNode *N, 
unsigned ,
 
   Opc = N->getValueType(0) == MVT::i32 ? AArch64::UBFMWri : AArch64::UBFMXri;
   LSB = SrlImm;
-  MSB = findLastSet(AndMask, ZB_Undefined);
+  MSB = llvm::Log2_64(AndMask);
   return true;
 }
 

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index c916d5d547c44..9035ae6f7e396 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -761,7 +761,7 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo 
,
   // There are some rare circumstances where InputAddr is non-zero and
   // InputEna can be set to 0. In this case we default to setting LastEna
   // to 1.
-  LastEna = InputEna ? findLastSet(InputEna) + 1 : 1;
+  LastEna = InputEna ? llvm::Log2_32(InputEna) + 1 : 1;
 }
 
 // FIXME: We should be using the number of registers determined during



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


[PATCH] D142569: [WIP][OpenMP] Introduce kernel argument

2023-01-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 492322.
tianshilei1992 added a comment.

fix bugs and add plugin support


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/include/State.h
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/State.cpp
  openmp/libomptarget/include/DeviceEnvironment.h
  openmp/libomptarget/include/Environment.h
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
  openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins/cuda/src/rtl.cpp

Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -23,7 +23,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "omptarget.h"
 #include "omptargetplugin.h"
 
Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -37,7 +37,7 @@
 #include "internal.h"
 #include "rt.h"
 
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "get_elf_mach_gfx_name.h"
 #include "omptargetplugin.h"
 #include "print_tracing.h"
Index: openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 #include "omptarget.h"
Index: openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
@@ -19,7 +19,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "JIT.h"
 #include "MemoryManager.h"
@@ -627,6 +627,11 @@
 
   /// Map of host pinned allocations used for optimize device transfers.
   PinnedAllocationMapTy PinnedAllocs;
+
+private:
+  /// Return the kernel environment object for kernel \p Name.
+  Expected
+  getKernelEnvironmentForKernel(StringRef Name, DeviceImageTy );
 };
 
 /// Class implementing common functionalities of offload plugins. Each plugin
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp
@@ -554,32 +554,43 @@
   return Plugin::success();
 }
 
-Expected
-GenericDeviceTy::getExecutionModeForKernel(StringRef Name,
-   DeviceImageTy ) {
-  // Create a metadata object for the exec mode global (auto-generated).
-  StaticGlobalTy ExecModeGlobal(Name.data(),
-"_exec_mode");
+Expected
+GenericDeviceTy::getKernelEnvironmentForKernel(StringRef Name,
+   DeviceImageTy ) {
+  // Create a metadata object for the kernel environment object.
+  StaticGlobalTy KernelEnv(Name.data(), "_kernel_info");
 
-  // Retrieve execution mode for the 

[PATCH] D141959: [clang-format] Fix inconsistent identification of operator

2023-01-25 Thread David K Turner via Phabricator via cfe-commits
dkt01 added a comment.

David Turner 

Good to know it worked as expected on your project as well.


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

https://reviews.llvm.org/D141959

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


[PATCH] D140059: [APSInt] Fix bug in APSInt mentioned in https://github.com/llvm/llvm-project/issues/59515

2023-01-25 Thread Peter Rong via Phabricator via cfe-commits
Peter added a comment.

In D140059#4081549 , @vabridgers 
wrote:

> Hello, it appears this patch causes a crash when I analyze this reproducer, 
> with Z3 enabled. In the case shown here, the analyzer finds that 'f' to the 
> call a(f) is uninitialized, and then is attempted to be refuted through 
> SMTConv, leading to the assertion.
>
> If I modify the below code to not use isRepresentableByIn64(), or use 
> 'assert(getMinSignedBits() <= 64 && "Too many bits for int64_t");' instead, I 
> do not see the crash.
>
> clang --analyze -Xclang -analyzer-config -Xclang crosscheck-with-z3=true 
> --target=x86_64-redhat-linux case.c
>
>   void a(int);
>   typedef struct {
> int b;
>   } c;
>   c *d;
>   void e() {
> (void)d->b;
> int f;
> a(f);
>   }
>
> The assert ...
>
>   clang-16: ../include/llvm/ADT/APSInt.h:99: int64_t 
> llvm::APSInt::getExtValue() const: Assertion `isRepresentableByInt64() && 
> "Too many bits for int64_t"' failed.Program received signal SIGABRT, Aborted.

Thanks for helping identifying the bug.

This is not a problem in this patch, the semantics of `getExtValue` changed in 
this patch as carefully discussed here 
.
To summarize, we believe its not reasonable to carry out ext for 
`(signed)(int64::Max + 1)`. Although it's still 64 bit, the returned value 
would be interpreted as `int64::Min` instead of a large positive integer. This 
behavior was allowed before.

To provide a fix for this problem, this patch provides a better way to 
determine if the extension is possible `isRepresentableByInt64`, I would 
recommend replacing `if (LLVM_UNLIKELY(Int.getBitWidth() > 64u))` in 
Z3Solver.cpp:732 with `if (LLVM_UNLIKELY(!Int.isRepresentableByInt64()))`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140059

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


[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 492319.
VincentWu added a comment.

reset HEAD back to Diff 492315 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrFormatsC.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication 

[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 492318.
VincentWu added a comment.

rebase to upstream


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' (Integer Multiplication), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.mul s0, s1
+
+# CHECK-ASM-AND-OBJ: c.lbu a5, 2(a4)
+# CHECK-ASM: encoding: [0x3c,0x83]
+# CHECK-NO-EXT: error: instruction 

[PATCH] D129008: [Clang][OpenMP] Fix the issue that globalization doesn't work with byval struct function argument

2023-01-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Right. C structs can require more than just `memcpy` to copy in several 
different situations (all involving language extensions), but it doesn't 
require Sema to be involved: it doesn't introduce uses of user declarations, 
and the compiler can figure out the work it needs to do with a straightforward 
recursive inspection of the field types, so IRGen just synthesizes those 
operations automatically when requested.  Neither condition holds in C++, so 
Sema has to synthesize a copy expression which resolves the correct copy 
constructor and sets up any extra arguments it might require, triggering 
appropriate diagnostics and/or tracking of used decls.  There are a bunch of 
places we do that for various language extensions already, including a bunch in 
the OpenMP code, and we usually just store the expression in the associated AST 
node.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129008

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


[PATCH] D142569: [WIP][OpenMP] Introduce kernel argument

2023-01-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 492316.
tianshilei1992 added a comment.

rebase, fix comments, added more code.

features are finished now. time to move to tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/include/State.h
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/State.cpp
  openmp/libomptarget/include/DeviceEnvironment.h
  openmp/libomptarget/include/Environment.h
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
  openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins/cuda/src/rtl.cpp

Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -23,7 +23,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "omptarget.h"
 #include "omptargetplugin.h"
 
Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -37,7 +37,7 @@
 #include "internal.h"
 #include "rt.h"
 
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "get_elf_mach_gfx_name.h"
 #include "omptargetplugin.h"
 #include "print_tracing.h"
Index: openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 #include "omptarget.h"
Index: openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
@@ -19,7 +19,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "JIT.h"
 #include "MemoryManager.h"
Index: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -21,7 +21,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 #include "Utilities.h"
@@ -431,7 +431,7 @@
 
   /// Launch the AMDGPU kernel function.
   Error launchImpl(GenericDeviceTy , uint32_t NumThreads,
-   uint64_t NumBlocks, 
+   uint64_t NumBlocks,
KernelArgsTy , void *Args,
AsyncInfoWrapperTy ) const override;
 
Index: openmp/libomptarget/include/Environment.h
===
--- /dev/null
+++ openmp/libomptarget/include/Environment.h
@@ -0,0 +1,53 @@
+//=== Environment.h - OpenMP GPU environments - C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Environments shared between host and device.
+//

[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-01-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D142584#4081345 , @efriedma wrote:

> I'm having a little trouble following what the meaning of an "Address" is 
> with this patch.  The `Pointer` member refers to an encoded value, and 
> calling getPointer() emits IR to decode it?  Could use a few comments to

explain the API.

That's something of a future direction w.r.t this patch, but it's reasonable to 
talk about it, yeah.

Pointer authentication includes the ability to have signed data pointers.  
Function pointers can only be used opaquely in C, but data pointers are subject 
to a lot of operations that boil down to pointer arithmetic, both as part of 
l-value accesses (such as `signedPtr->array[i] = 5`) and just in abstract 
pointer-typed expressions (such as `>array[i]`).  For l-values that are 
ultimately accessed, we really want to make sure that we do the authentication 
as close as possible to the actual access rather than authenticating it 
immediately and then having a raw, attackable pointer sitting around while we 
set up the access.  For pointer expressions in general, if they ultimately need 
to produce another signed pointer (e.g. we assign into a `__ptrauth`-qualified 
l-value), for similar reasons we really want to set up all the arithmetic ahead 
of time for a secure auth-add-and-resign sequence instead of authenticating and 
having raw, attackable pointers sitting around as we do the arithmetic.  We 
could do all that with a specialized pointer-with-signature emitter that covers 
literally every kind of pointer arithmetic, but that requires duplication of a 
*lot* of code, especially because we have a lot of sanitizers and other special 
logic also tied to those operations.  It seemed much less invasive to add a 
state to `Address` where it can be a pair of a signed pointer and an offset, 
then make a few basic GEP-formation operations accumulate into the offset when 
the pointer is in that state.  Of course, converting an `Address` into a normal 
pointer then becomes a non-trivial operation that needs a CGF.

Pointer authentication doesn't sign null pointers, so we have to do some 
explicit extra checks as part of this when the pointer is possibly null, and 
this patch is trying to make that easier to avoid.




Comment at: clang/lib/CodeGen/Address.h:26
+// Indicates whether a pointer is known not to be null.
+enum class KnownNonNull_t { False, True };
+

The usual idiom for this kind of boolean enum is that you just use an unscoped 
enum (not `enum class`), and you spell the enumerators something that reads 
well where it'll be used.  So you'd make the enumerators `KnownNotNull` and (I 
guess) something like `NotKnownNotNull` or `NullnessUnknown`.



Comment at: clang/lib/CodeGen/Address.h:97
+  llvm::Value *
+  getPointer(KnownNonNull_t KnownNonNull = KnownNonNull_t::False) const {
 assert(isValid());

Apologies if this rehashes a conversation we had earlier, but does it make more 
sense to track this internally in `Address`?  Some `Address` sources definitely 
known that they're non-null, and the places where we only know that 
*contextually* could definitely just pass it down to e.g. 
`EmitPointerWithAlignment`.  That would make it a less invasive change for all 
the clients of `getPointer()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492315.
craig.topper added a comment.

Fix RUN line that was duplicate testing riscv64


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrFormatsC.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv32 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' 

[PATCH] D142354: [analyzer] Create a stub for an std::variant checker

2023-01-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D142354#4079643 , @Szelethus wrote:

>> In the latter case, have you explored the possibility of force-inlining the 
>> class instead, like I suggested in the thread?
>
> I have done some tests then, and figured that the analyzer can't really 
> follow what happens in std::variant. I admit, now that I've taken a more 
> thorough look, I was wrong! Here are some examples.
>
>   std::variant v = 0;
>   int i = std::get(v);
>   clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
>   10 / i; // FIXME: This should warn for division by zero!
>
>
>
>   std::variant v = 0;
>   std::string *sptr = std::get_if();
>   clang_analyzer_eval(sptr == nullptr); // expected-warning{{TRUE}}
>   *sptr = "Alma!"; // FIXME: Should warn, sptr is a null pointer!
>
>
>
>   void g(std::variant v) {
> if (!std::get_if())
>   return;
> int *iptr = std::get_if();
> clang_analyzer_eval(iptr == nullptr); // expected-warning{{TRUE}}
> *iptr = 5; // FIXME: Should warn, iptr is a null pointer!
>   }
>
> In neither of these cases was a warning emitted, but that was a result of bug 
> report suppression, because the exploded graph indicates that the errors were 
> found.
>
> We will need to teach these suppression strategies in these cases, the 
> heuristic is too conservative, and I wouldn't mind some `NoteTag`s to tell 
> the user something along the lines of "Assuming this variant holds and 
> std::string value".

Yeah, right, these are probably inlined defensive check suppressions (type-2, 
the ones with "let's early-return null"). So you'll need to see how these 
inlined stack frames look like and what makes them different from the unwanted 
case. (And it's possible that there are no formal differences, other than the 
programmer's "intention"; but it could also be something really simple).

So in any case, I'm really curious whether there's any solution besides "let's 
model everything manually", given that we've spent two summers modeling 
`unique_ptr` manually and never finished it.


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

https://reviews.llvm.org/D142354

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


[PATCH] D140795: [Flang] Add user option -funderscoring/-fnounderscoring to control trailing underscore added to external names

2023-01-25 Thread Mark Danial via Phabricator via cfe-commits
madanial updated this revision to Diff 492312.
madanial retitled this revision from "[Flang] Add user option 
-funderscoring/-fnounderscoring to enable/disable ExternalNameConversionPass" 
to "[Flang] Add user option -funderscoring/-fnounderscoring to control trailing 
underscore added to external names".
madanial edited the summary of this revision.
madanial added a comment.
Herald added a reviewer: sscalpone.
Herald added subscribers: sunshaoce, mehdi_amini.

Implementing functionality to control just the trailing underscore for external 
names to achieve similar functionality to the option in gfortran, as well as 
rebase and address review comments.


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

https://reviews.llvm.org/D140795

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.def
  flang/include/flang/Optimizer/Transforms/Passes.h
  flang/include/flang/Optimizer/Transforms/Passes.td
  flang/include/flang/Tools/CLOptions.inc
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/underscoring.f90

Index: flang/test/Driver/underscoring.f90
===
--- /dev/null
+++ flang/test/Driver/underscoring.f90
@@ -0,0 +1,24 @@
+! Test the -funderscoring flag
+
+! RUN: %flang_fc1 -S %s -o - 2>&1 | FileCheck %s --check-prefix=UNDERSCORING
+! RUN: %flang_fc1 -S -fno-underscoring %s -o - 2>&1 | FileCheck %s --check-prefix=NO-UNDERSCORING
+
+subroutine test()
+  common /comblk/ a, b
+  external :: ext_sub
+  call ext_sub()
+end
+
+! UNDERSCORING: test_
+! UNDERSCORING: ext_sub_
+! UNDERSCORING: comblk_
+
+! NO-UNDERSCORING-NOT: test_
+! NO-UNDERSCORING-NOT: _QPtest
+! NO-UNDERSCORING: test
+! NO-UNDERSCORING-NOT: ext_sub_
+! NO-UNDERSCORING-NOT: _QPext_sub
+! NO-UNDERSCORING: ext_sub
+! NO-UNDERSCORING-NOT: comblk_
+! NO-UNDERSCORING-NOT: _QBcomblk
+! NO-UNDERSCORING: comblk
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -50,6 +50,7 @@
 ! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-NEXT: -freciprocal-math  Allow division operations to be reassociated
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
+! HELP-NEXT: -funderscoring Appends one trailing underscore to external names
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
@@ -135,6 +136,7 @@
 ! HELP-FC1-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-FC1-NEXT: -freciprocal-math  Allow division operations to be reassociated
 ! HELP-FC1-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
+! HELP-FC1-NEXT: -funderscoring Appends one trailing underscore to external names
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -init-only Only execute frontend initialization
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -52,6 +52,7 @@
 ! CHECK-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! CHECK-NEXT: -freciprocal-math  Allow division operations to be reassociated
 ! CHECK-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
+! CHECK-NEXT: -funderscoring Appends one trailing underscore to external names
 ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
Index: flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
===
--- flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
+++ flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
@@ -32,11 +32,17 @@
 std::string
 mangleExternalName(const std::pair
-   result) {
+   result,
+   bool appendUnderscore) {
   if (result.first == fir::NameUniquer::NameKind::COMMON &&
   result.second.name.empty())
 return "__BLNK__";
-  return result.second.name + "_";

[PATCH] D142592: [clang-tidy][libc] Add an inline function checker for the libc project.

2023-01-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please add entry in Release Notes.




Comment at: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp:29
+
+  auto SrcBegin = FuncDecl->getSourceRange().getBegin();
+  // Consider functions only in header files.

Please don't use `auto` unless type is explicitly stated in same statement or 
iterator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142592

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


[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492311.
craig.topper added a comment.

Fix typo in RISCVBaseInfo.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrFormatsC.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' (Integer Multiplication), 

[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492310.
craig.topper added a comment.

Merge uimm32_zc into uimm2.
Add RISCVOp::OPERAND_TYPE_UIMM2_LSB0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrFormatsC.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication and Division) 

[PATCH] D142596: [RISCV] Bump Zca version to 1.0.

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142596

Files:
  clang/test/Driver/riscv-arch.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s


Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -176,8 +176,8 @@
 .attribute arch, "rv32if_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 
-.attribute arch, "rv32izca0p70"
-# CHECK: attribute  5, "rv32i2p0_zca0p70"
+.attribute arch, "rv32izca1p0"
+# CHECK: attribute  5, "rv32i2p0_zca1p0"
 
 .attribute arch, "rv32izawrs1p0"
 # CHECK: attribute  5, "rv32i2p0_zawrs1p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -128,7 +128,7 @@
 ; RV32SVNAPOT: .attribute 5, "rv32i2p0_svnapot1p0"
 ; RV32SVPBMT: .attribute 5, "rv32i2p0_svpbmt1p0"
 ; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
-; RV32ZCA: .attribute 5, "rv32i2p0_zca0p70"
+; RV32ZCA: .attribute 5, "rv32i2p0_zca1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -174,7 +174,7 @@
 ; RV64XVENTANACONDOPS: .attribute 5, "rv64i2p0_xventanacondops1p0"
 ; RV64XTHEADVDOT: .attribute 5, 
"rv64i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_xtheadvdot1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
-; RV64ZCA: .attribute 5, "rv64i2p0_zca0p70"
+; RV64ZCA: .attribute 5, "rv64i2p0_zca1p0"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -114,7 +114,7 @@
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
 {"zihintntl", RISCVExtensionVersion{0, 2}},
 
-{"zca", RISCVExtensionVersion{0, 70}},
+{"zca", RISCVExtensionVersion{1, 0}},
 {"zcd", RISCVExtensionVersion{0, 70}},
 {"zcf", RISCVExtensionVersion{0, 70}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
Index: llvm/docs/RISCVUsage.rst
===
--- llvm/docs/RISCVUsage.rst
+++ llvm/docs/RISCVUsage.rst
@@ -136,7 +136,7 @@
   LLVM implements the `1.0-rc3 draft specification 
`_.  
Note that have been backwards incompatible changes made between release 
candidates for the 1.0 draft.
 
 ``experimental-zca``
-  LLVM implements the `0.70 draft specification 
`_.
+  LLVM implements the `1.0.1 draft specification 
`_.
 
 ``experimental-zihintntl``
   LLVM implements the `0.2 draft specification 
`_.
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -430,9 +430,9 @@
 // RUN: %clang --target=riscv32-unknown-elf -march=rv32izca0p1 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS 
%s
 // RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32izca0p1'
-// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zca' (this compiler supports 0.70)
+// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zca' (this compiler supports 1.0)
 
-// RUN: %clang --target=riscv32-unknown-elf -march=rv32izca0p70 
-menable-experimental-extensions -### %s \
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32izca1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
 // RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-zca"
 


Index: llvm/test/MC/RISCV/attribute-arch.s

[PATCH] D141826: [clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-25 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 492306.
Michael137 added a comment.

- Remove redundant constructor call change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateArgumentDefaulted) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5897,6 +5897,11 @@
 CTAK_Specified))
 return true;
 
+  CanonicalConverted.back().setIsDefaulted(
+  clang::isSubstitutedDefaultArgument(
+  Context, NewArgs[ArgIdx].getArgument(), *Param,
+  CanonicalConverted, Params->getDepth()));
+
   bool PackExpansionIntoNonPack =
   NewArgs[ArgIdx].getArgument().isPackExpansion() &&
   (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
@@ -6072,6 +6077,8 @@
   CTAK_Specified))
   return true;
 
+CanonicalConverted.back().setIsDefaulted(true);
+
 // Core issue 150 (assumed resolution): if this is a template template
 // parameter, keep track of the default template arguments from the
 // template definition.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext , const llvm::APSInt ,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6739,26 +6739,29 @@
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
-  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
+  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()),
+  Arg.getIsDefaulted());
 }
 
 case TemplateArgument::NullPtr:
   return TemplateArgument(getCanonicalType(Arg.getNullPtrType()),
-  /*isNullPtr*/true);
+  /*isNullPtr*/ true, Arg.getIsDefaulted());
 
 case TemplateArgument::Template:
-  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()));
+  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()),
+  Arg.getIsDefaulted());
 
 case TemplateArgument::TemplateExpansion:
-  return TemplateArgument(getCanonicalTemplateName(
- Arg.getAsTemplateOrTemplatePattern()),
-  Arg.getNumTemplateExpansions());
+  return TemplateArgument(
+  getCanonicalTemplateName(Arg.getAsTemplateOrTemplatePattern()),
+  Arg.getNumTemplateExpansions(), Arg.getIsDefaulted());
 
 case TemplateArgument::Integral:
   return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType()));
 
 case TemplateArgument::Type:
-  return TemplateArgument(getCanonicalType(Arg.getAsType()));
+  return TemplateArgument(getCanonicalType(Arg.getAsType()),
+  /*isNullPtr*/ false, 

[PATCH] D142595: [Driver][AVR] Don't emit default '-Tdata' when a linker script is specified

2023-01-25 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: MaskRay, aykevl, Miss_Grape.
Herald added subscribers: Jim, dylanmckay.
Herald added a project: All.
benshi001 requested review of this revision.
Herald added subscribers: cfe-commits, jacquesguan.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142595

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/avr35.lds
  clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/avr51.lds
  clang/test/Driver/avr-ld.c


Index: clang/test/Driver/avr-ld.c
===
--- clang/test/Driver/avr-ld.c
+++ clang/test/Driver/avr-ld.c
@@ -42,3 +42,11 @@
 
 // RUN: %clang -### --target=avr -mmcu=atxmega128a1 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKO %s
 // LINKO: {{".*ld.*"}} {{.*}} {{"-L.*avrxmega7"}} {{.*}} "-Tdata=0x802000" 
"--start-group" {{.*}} "-latxmega128a1" {{.*}} "--end-group" "-mavrxmega7"
+
+// RUN: %clang -### --target=avr -mmcu=atmega8u2 --sysroot 
%S/Inputs/basic_avr_tree %s -T 
%S/Inputs/basic_avr_tree/usr/lib/avr/lib/avr35.lds 2>&1 | FileCheck 
-check-prefix LINKP %s
+// LINKP: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "--start-group" {{.*}} 
"-latmega8u2" {{.*}} "--end-group" "-T" {{".*avr35.lds"}} "-mavr35"
+// LINKP-NOT: "-Tdata"
+
+// RUN: %clang -### --target=avr --sysroot %S/Inputs/basic_avr_tree %s -T 
%S/Inputs/basic_avr_tree/usr/lib/avr/lib/avr51.lds 2>&1 | FileCheck 
-check-prefix LINKQ %s
+// LINKQ-NOT: "-Tdata"
+// LINKQ-NOT: "warning:" {{.*}} "section address"
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -497,12 +497,14 @@
   D.Diag(diag::warn_drv_avr_stdlib_not_linked);
   }
 
-  if (SectionAddressData) {
-CmdArgs.push_back(Args.MakeArgString(
-"-Tdata=0x" + Twine::utohexstr(*SectionAddressData)));
-  } else {
-// We do not have an entry for this CPU in the address mapping table yet.
-D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU;
+  if (!Args.hasArg(options::OPT_T)) {
+if (SectionAddressData) {
+  CmdArgs.push_back(Args.MakeArgString(
+  "-Tdata=0x" + Twine::utohexstr(*SectionAddressData)));
+} else {
+  // We do not have an entry for this CPU in the address mapping table yet.
+  D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << 
CPU;
+}
   }
 
   // If the family name is known, we can link with the device-specific libgcc.


Index: clang/test/Driver/avr-ld.c
===
--- clang/test/Driver/avr-ld.c
+++ clang/test/Driver/avr-ld.c
@@ -42,3 +42,11 @@
 
 // RUN: %clang -### --target=avr -mmcu=atxmega128a1 --rtlib=libgcc --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKO %s
 // LINKO: {{".*ld.*"}} {{.*}} {{"-L.*avrxmega7"}} {{.*}} "-Tdata=0x802000" "--start-group" {{.*}} "-latxmega128a1" {{.*}} "--end-group" "-mavrxmega7"
+
+// RUN: %clang -### --target=avr -mmcu=atmega8u2 --sysroot %S/Inputs/basic_avr_tree %s -T %S/Inputs/basic_avr_tree/usr/lib/avr/lib/avr35.lds 2>&1 | FileCheck -check-prefix LINKP %s
+// LINKP: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "-T" {{".*avr35.lds"}} "-mavr35"
+// LINKP-NOT: "-Tdata"
+
+// RUN: %clang -### --target=avr --sysroot %S/Inputs/basic_avr_tree %s -T %S/Inputs/basic_avr_tree/usr/lib/avr/lib/avr51.lds 2>&1 | FileCheck -check-prefix LINKQ %s
+// LINKQ-NOT: "-Tdata"
+// LINKQ-NOT: "warning:" {{.*}} "section address"
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -497,12 +497,14 @@
   D.Diag(diag::warn_drv_avr_stdlib_not_linked);
   }
 
-  if (SectionAddressData) {
-CmdArgs.push_back(Args.MakeArgString(
-"-Tdata=0x" + Twine::utohexstr(*SectionAddressData)));
-  } else {
-// We do not have an entry for this CPU in the address mapping table yet.
-D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU;
+  if (!Args.hasArg(options::OPT_T)) {
+if (SectionAddressData) {
+  CmdArgs.push_back(Args.MakeArgString(
+  "-Tdata=0x" + Twine::utohexstr(*SectionAddressData)));
+} else {
+  // We do not have an entry for this CPU in the address mapping table yet.
+  D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU;
+}
   }
 
   // If the family name is known, we can link with the device-specific libgcc.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D142592: [clang-tidy][libc] Add an inline function checker for the libc project.

2023-01-25 Thread Siva Chandra via Phabricator via cfe-commits
sivachandra created this revision.
sivachandra added a reviewer: aaron.ballman.
Herald added subscribers: ChuanqiXu, carlosgalvezp, ecnelises, tschuett, 
xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
sivachandra requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The new checker checks if inline functions defined in header files are
tagged with the LIBC_INLINE macro. See https://libc.llvm.org/code_style.html
for more information about this macro.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142592

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl-check.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.h

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.h
@@ -0,0 +1,56 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
+#define LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
+
+#define LIBC_INLINE inline
+
+namespace __llvm_libc {
+
+LIBC_INLINE int addi(int a, int b) {
+  return a + b;
+}
+
+LIBC_INLINE constexpr long addl(long a, long b) {
+  return a + b;
+}
+
+constexpr long long addll(long long a, long long b) {
+  return a + b;
+}
+
+inline unsigned long addul(unsigned long a, unsigned long b) {
+  return a + b;
+}
+
+class  MyClass {
+  int A;
+public:
+  MyClass() : A(123) {}
+
+  LIBC_INLINE MyClass(int V) : A(V) {}
+
+  constexpr operator int() const { return A; }
+
+  LIBC_INLINE bool operator==(const MyClass ) {
+return RHS.A == A;
+  }
+
+  static int getVal(const MyClass ) {
+return V.A;
+  }
+
+  LIBC_INLINE static void setVal(MyClass , int A) {
+V.A = A;
+  }
+
+  constexpr static int addInt(MyClass , int A) {
+return V.A += A;
+  }
+
+  static LIBC_INLINE int mulInt(MyClass , int A) {
+return V.A *= A;
+  }
+};
+
+} // namespace __llvm_libc
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s llvmlibc-inline-function-decl-check %t \
+// RUN:   -- -header-filter=.* -- -I %S
+
+#include "inline-function-decl.h"
+
+namespace __llvm_libc {
+
+// Inline functions in .cpp files need not use the LIBC_INLINE tag.
+inline float addf(float a, float b) {
+  return a + b;
+}
+
+// Non-inline functions should not trigger any warning.
+int mul(int a, int b) {
+  return addf(a * b, b);
+}
+
+// CHECK-MESSAGES: warning: 'addll' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'addul' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'MyClass' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'operator int' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'getVal' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'addInt' must be tagged with the LIBC_INLINE macro
+// CHECK-MESSAGES: warning: 'mulInt' must be tagged with the LIBC_INLINE macro
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl-check.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc/inline-function-decl-check.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - llvmlibc-inline-funciton-decl-check
+
+llvmlibc-inline-function-decl-check
+
+
+Checks that all implicit and explicit inline functions in header files are
+tagged with the ``LIBC_INLINE`` macro. See the `libc style guide
+`_ for more information about this macro.
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "CalleeNamespaceCheck.h"
 #include "ImplementationInNamespaceCheck.h"
+#include "InlineFunctionDeclCheck.h"
 #include "RestrictSystemLibcHeadersCheck.h"
 
 namespace clang::tidy {
@@ 

[PATCH] D142569: [WIP][OpenMP] Introduce kernel argument

2023-01-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: openmp/libomptarget/DeviceRTL/src/Configuration.cpp:57
+  return !__omp_rtl_assume_no_nested_parallelism ||
+ state::getKernelEnvironment().Configuration.MayUseNestedParallelism;
 }

jdoerfert wrote:
> This looks wrong. We want either flag to allow us to remove nested 
> parallelism handling. So 
> `__omp_rtl_assume_no_nested_parallelism ` is good enough, and
> `!state::getKernelEnvironment().Configuration.MayUseNestedParallelism` is 
> good enough.
Yeah, since I already updated `OpenMPOpt.cpp`, 
`__omp_rtl_assume_no_nested_parallelism` will not be generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


[PATCH] D142569: [WIP][OpenMP] Introduce kernel argument

2023-01-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: openmp/libomptarget/DeviceRTL/src/Configuration.cpp:57
+  return !__omp_rtl_assume_no_nested_parallelism ||
+ state::getKernelEnvironment().Configuration.MayUseNestedParallelism;
 }

This looks wrong. We want either flag to allow us to remove nested parallelism 
handling. So 
`__omp_rtl_assume_no_nested_parallelism ` is good enough, and
`!state::getKernelEnvironment().Configuration.MayUseNestedParallelism` is good 
enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492298.
craig.topper added a comment.

Update for rename CS_ALU to CA_ALU


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrFormatsC.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' (Integer Multiplication), 'Zcb' (Shortened format for basic bit 

[PATCH] D140059: [APSInt] Fix bug in APSInt mentioned in https://github.com/llvm/llvm-project/issues/59515

2023-01-25 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Hello, it appears this patch causes a crash when I analyze this reproducer, 
with Z3 enabled. In the case shown here, the analyzer finds that 'f' to the 
call a(f) is uninitialized, and then is attempted to be refuted through 
SMTConv, leading to the assertion.

If I modify the below code to not use isRepresentableByIn64(), or use 
'assert(getMinSignedBits() <= 64 && "Too many bits for int64_t");' instead, I 
do not see the crash.

clang --analyze -Xclang -analyzer-config -Xclang crosscheck-with-z3=true 
--target=x86_64-redhat-linux case.c

  void a(int);
  typedef struct {
int b;
  } c;
  c *d;
  void e() {
(void)d->b;
int f;
a(f);
  }

The assert ...

  clang-16: ../include/llvm/ADT/APSInt.h:99: int64_t 
llvm::APSInt::getExtValue() const: Assertion `isRepresentableByInt64() && "Too 
many bits for int64_t"' failed.Program received signal SIGABRT, Aborted.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140059

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


[PATCH] D129951: adds `__disable_adl` attribute

2023-01-25 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:542
 If a statement is marked ``nomerge`` and contains call expressions, those call
-expressions inside the statement will not be merged during optimization. This 
+expressions inside the statement will not be merged during optimization. This
 attribute can be used to prevent the optimizer from obscuring the source

shafik wrote:
> A lot of these look like unrelated changes.
I tend to not argue with autoformatters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129951

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


[PATCH] D129951: adds `__disable_adl` attribute

2023-01-25 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 492296.
cjdb marked 6 inline comments as done.
cjdb added a comment.

responds to feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129951

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/disable-adl.cpp

Index: clang/test/SemaCXX/disable-adl.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/disable-adl.cpp
@@ -0,0 +1,179 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++2b
+
+namespace NS1 {
+  struct S1 {};
+  S1 inhibited(S1); // expected-note 2 {{candidate function}}
+
+  namespace NNS1 {
+struct S2 {};
+__disable_adl void hidden(S2);   // expected-note{{declared here}}
+__disable_adl int inhibited(S1); // expected-note 4 {{candidate function}}
+  }
+}
+
+namespace NS2 {
+  __disable_adl void inhibited(NS1::S1); // expected-note 2 {{candidate function}}
+}
+
+void test_functions() {
+  hidden(NS1::NNS1::S2{}); // expected-error{{use of undeclared identifier 'hidden'; did you mean 'NS1::NNS1::hidden'?}}
+  {
+NS1::S1 x = inhibited(NS1::S1{}); // no error
+  }
+  {
+using namespace NS1::NNS1;
+int x = inhibited(NS1::S1{}); // no error
+
+using namespace NS1;
+S1 y = inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+  {
+using NS1::NNS1::inhibited;
+int x = inhibited(NS1::S1{}); // no error
+
+using NS1::inhibited;
+NS1::S1 y = inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+  {
+using namespace NS2;
+inhibited(NS1::S1{}); // no error
+
+using namespace NS1::NNS1;
+inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+  {
+using NS2::inhibited;
+inhibited(NS1::S1{}); // no error
+
+using NS1::NNS1::inhibited;
+inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+}
+
+namespace NS1 {
+  template
+  S1 inhibited_template(T); // expected-note 2 {{candidate function}}
+
+  namespace NNS1 {
+template
+__disable_adl void hidden_template(T); // expected-note{{declared here}}
+
+template
+__disable_adl int inhibited_template(T); // expected-note 4 {{candidate function}}
+  }
+}
+
+namespace NS2 {
+  template
+  __disable_adl int inhibited_template(T); // expected-note 2 {{candidate function}}
+}
+
+void test_function_templates() {
+  hidden_template(NS1::NNS1::S2{}); // expected-error{{use of undeclared identifier 'hidden_template'; did you mean 'NS1::NNS1::hidden_template'?}}
+
+  {
+NS1::S1 x = inhibited_template(NS1::S1{}); // no error
+  }
+  {
+using namespace NS1::NNS1;
+int x = inhibited_template(NS1::S1{}); // no error
+
+using namespace NS1;
+S1 y = inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+  {
+using NS1::NNS1::inhibited_template;
+int x = inhibited_template(NS1::S1{}); // no error
+
+using NS1::inhibited_template;
+NS1::S1 y = inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+  {
+using namespace NS2;
+inhibited_template(NS1::S1{}); // no error
+
+using namespace NS1::NNS1;
+inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+  {
+using NS2::inhibited_template;
+inhibited_template(NS1::S1{}); // no error
+
+using NS1::NNS1::inhibited_template;
+inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+}
+
+namespace NS1 {
+  S1 inhibited_mixed(S1);
+
+  namespace NNS1 {
+template
+__disable_adl int inhibited_mixed(T);
+  }
+}
+
+void test_mixed() {
+  using namespace NS1::NNS1;
+  int x = inhibited_mixed(NS1::S1{}); // no error
+}
+
+// Should be covered by the hidden functions checks, but just to be sure.
+void test_NNS1_hidden() {
+  {
+NS1::S1 a = inhibited(NS1::S1{});
+NS1::S1 b = inhibited_template(NS1::S1{});
+NS1::S1 c = inhibited_mixed(NS1::S1{});
+  }
+  {
+using namespace NS1;
+NS1::S1 a = inhibited(NS1::S1{});
+NS1::S1 b = inhibited_template(NS1::S1{});
+NS1::S1 c = inhibited_mixed(NS1::S1{});
+  }
+}
+
+namespace NS1 {
+  namespace NNS1 {
+__disable_adl void operator-(S2); // expected-error{{can't apply '__disable_adl' to operators, since they're supposed to be used with ADL}}
+
+struct hidden_friend_operator {
+  friend void operator-(hidden_friend_operator i, int) {}
+};
+
+struct hidden_friend_swap {

[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492295.
craig.topper added a comment.

Add CSZN format as named in the spec.
Reuse CLoad_ri/CStore_rri classes instead of creating new ones that were almost 
the same.
Use CS_ALU class for c.mul.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrFormatsC.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the 

[PATCH] D140628: [flang] Add driver install directory to AIX toolchain program paths list

2023-01-25 Thread wael yehia via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e72407635a4: [flang] Add driver install directory to AIX 
toolchain program paths list. (authored by pscoro, committed by w2yehia).

Changed prior to commit:
  https://reviews.llvm.org/D140628?vs=485112=492294#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140628

Files:
  clang/lib/Driver/ToolChains/AIX.cpp


Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -287,6 +287,10 @@
 /// AIX - AIX tool chain which can call as(1) and ld(1) directly.
 AIX::AIX(const Driver , const llvm::Triple , const ArgList )
 : ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+
   ParseInlineAsmUsingAsmParser = Args.hasFlag(
   options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);
   getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib");


Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -287,6 +287,10 @@
 /// AIX - AIX tool chain which can call as(1) and ld(1) directly.
 AIX::AIX(const Driver , const llvm::Triple , const ArgList )
 : ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+
   ParseInlineAsmUsingAsmParser = Args.hasFlag(
   options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);
   getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5e72407 - [flang] Add driver install directory to AIX toolchain program paths list.

2023-01-25 Thread Wael Yehia via cfe-commits

Author: Paul Scoropan
Date: 2023-01-26T00:39:51Z
New Revision: 5e72407635a43b8b7f85c1658b6738f023a21f03

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

LOG: [flang] Add driver install directory to AIX toolchain program paths list.

flang-new encounters an issue where its unable to invoke itself because the
install directory was missing from the program paths on AIX.

Reviewed By: w2yehia

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AIX.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index abbd3ef6c68f3..f62b566c3946e 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -287,6 +287,10 @@ void aix::Linker::ConstructJob(Compilation , const 
JobAction ,
 /// AIX - AIX tool chain which can call as(1) and ld(1) directly.
 AIX::AIX(const Driver , const llvm::Triple , const ArgList )
 : ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+
   ParseInlineAsmUsingAsmParser = Args.hasFlag(
   options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);
   getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib");



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


[PATCH] D142577: [clang-doc] Removed unused method in the Info class

2023-01-25 Thread Paul Kirth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG881d151c527c: [clang-doc] Removed unused method in the Info 
class (authored by paulkirth).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142577

Files:
  clang-tools-extra/clang-doc/Representation.h


Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -290,10 +290,6 @@
 
   /// Returns the basename that should be used for this Info.
   llvm::SmallString<16> getFileBaseName() const;
-
-  // Returns a reference to the parent scope (that is, the immediate parent
-  // namespace or class in which this decl resides).
-  llvm::Expected getEnclosingScope();
 };
 
 // Info for namespaces.


Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -290,10 +290,6 @@
 
   /// Returns the basename that should be used for this Info.
   llvm::SmallString<16> getFileBaseName() const;
-
-  // Returns a reference to the parent scope (that is, the immediate parent
-  // namespace or class in which this decl resides).
-  llvm::Expected getEnclosingScope();
 };
 
 // Info for namespaces.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 881d151 - [clang-doc] Removed unused method in the Info class

2023-01-25 Thread Paul Kirth via cfe-commits

Author: Paul Kirth
Date: 2023-01-25T23:55:59Z
New Revision: 881d151c527c0eaae89af5842f4167f7a2439a13

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

LOG: [clang-doc] Removed unused method in the Info class

Reviewed By: brettw

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

Added: 


Modified: 
clang-tools-extra/clang-doc/Representation.h

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index 15e1abf858aaa..aa5fa7f07083e 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -290,10 +290,6 @@ struct Info {
 
   /// Returns the basename that should be used for this Info.
   llvm::SmallString<16> getFileBaseName() const;
-
-  // Returns a reference to the parent scope (that is, the immediate parent
-  // namespace or class in which this decl resides).
-  llvm::Expected getEnclosingScope();
 };
 
 // Info for namespaces.



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


[PATCH] D142569: [WIP][OpenMP] Introduce kernel argument

2023-01-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: llvm/lib/Transforms/IPO/OpenMPOpt.cpp:2544
 
-  ~AAExecutionDomainFunction() {
-delete RPOT;
-  }
+  ~AAExecutionDomainFunction() { delete RPOT; }
 

This will be removed properly later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


[PATCH] D142569: [WIP][OpenMP] Introduce kernel argument

2023-01-25 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 492278.
tianshilei1992 marked 6 inline comments as done.
tianshilei1992 added a comment.

rebase, add more code, fix comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Configuration.h
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/include/State.h
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/Mapping.cpp
  openmp/libomptarget/DeviceRTL/src/State.cpp
  openmp/libomptarget/include/DeviceEnvironment.h
  openmp/libomptarget/include/Environment.h
  openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
  openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
  openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins/cuda/src/rtl.cpp

Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -23,7 +23,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "omptarget.h"
 #include "omptargetplugin.h"
 
Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -37,7 +37,7 @@
 #include "internal.h"
 #include "rt.h"
 
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "get_elf_mach_gfx_name.h"
 #include "omptargetplugin.h"
 #include "print_tracing.h"
Index: openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/generic-elf-64bit/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 #include "omptarget.h"
Index: openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/cuda/src/rtl.cpp
@@ -17,7 +17,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
===
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h
@@ -19,7 +19,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "JIT.h"
 #include "MemoryManager.h"
Index: openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
===
--- openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -21,7 +21,7 @@
 #include 
 
 #include "Debug.h"
-#include "DeviceEnvironment.h"
+#include "Environment.h"
 #include "GlobalHandler.h"
 #include "PluginInterface.h"
 #include "Utilities.h"
@@ -431,7 +431,7 @@
 
   /// Launch the AMDGPU kernel function.
   Error launchImpl(GenericDeviceTy , uint32_t NumThreads,
-   uint64_t NumBlocks, 
+   uint64_t NumBlocks,
KernelArgsTy , void *Args,
AsyncInfoWrapperTy ) const override;
 
Index: openmp/libomptarget/include/Environment.h
===
--- /dev/null
+++ openmp/libomptarget/include/Environment.h
@@ -0,0 +1,53 @@
+//=== Environment.h - OpenMP GPU environments - C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D142459: [clang] Deprecate uses of GlobalObject::getAlignment

2023-01-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:491
   new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+ Var->getAlign().valueOrOne(), I);
   WorkItem.pop_back();

yaxunl wrote:
> efriedma wrote:
> > gchatelet wrote:
> > > barannikov88 wrote:
> > > > barannikov88 wrote:
> > > > > tra wrote:
> > > > > > gchatelet wrote:
> > > > > > > tra wrote:
> > > > > > > > This appears to be a change in behavior. AFAICT, previously 
> > > > > > > > used Var->getAlignment() could return alignment value or 0. Now 
> > > > > > > > it's value or 1.
> > > > > > > > 
> > > > > > > > Is it intentional?
> > > > > > > The previous statement was constructing an `llvm::Align` from a 
> > > > > > > value, and `llvm::Align` [asserts when the provided value is 
> > > > > > > 0](https://github.com/llvm/llvm-project/blob/4ab2246d486ba30c4b2d654323a0c0b97565c0f1/llvm/include/llvm/Support/Alignment.h#L76-L81).
> > > > > > >  This means that it is undefined to pass the value `0`.
> > > > > > > 
> > > > > > > As far as `LoadInst` is concerned it can only accept valid 
> > > > > > > alignments (i.e., powers of two => non zero).
> > > > > > > 
> > > > > > > So you're right that it is not strictly NFC and that 
> > > > > > > `*Var->getAlign()`would be a more rigorous transformation but I 
> > > > > > > //think// that converting the `0` value to `1` moves us from UB 
> > > > > > > to semantically valid code.
> > > > > > > 
> > > > > > > I don't feel strongly about it though and I'm fine changing this 
> > > > > > > to `*Var->getAlign()` to keep this patch NFC. WDYT?
> > > > > > Enforcing alignment of 1 would potentially force us to generate 
> > > > > > overly conservative one byte at a time loads/stores.
> > > > > > I agree that passing 0 is a wrong choice here, but 1 does not seem 
> > > > > > to be correct, either.
> > > > > > Unfortunately LoadInst does not have overloads accepting MaybeAlign 
> > > > > > so we need to use different `LoadInst` overload depending on 
> > > > > > whether alignment is specified.
> > > > > > 
> > > > > > ```
> > > > > > NewV =  Var->getAlign().isAligned() 
> > > > > >   ? llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false, 
> > > > > >  Var->getAlign().value(), I)
> > > > > >   : llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false, 
> > > > > >  I);
> > > > > > ```
> > > > > > 
> > > > > > @yaxunl -- Sam, does it make sense? This seems to be largely 
> > > > > > HIP-specific.
> > > > > I think it should be just `Var->getAlign()` to allow propagating 
> > > > > absent alignment.
> > > > > Curiously, the old code didn't assert because `GlobalVariable` seem 
> > > > > to always(?) have non-empty alignment if the global had an associated 
> > > > > `VarDecl` (set [[ 
> > > > > https://github.com/llvm/llvm-project/blob/6ad0788c332bb2043142954d300c49ac3e537f34/clang/lib/CodeGen/CodeGenModule.cpp#L4442
> > > > >  | here ]], changed(?) by [[ 
> > > > > https://github.com/llvm/llvm-project/commit/c79099e0f44d0f85515fd30c83923d9d9dc1679b
> > > > >  | this patch ]]).
> > > > > 
> > > > > Unfortunately LoadInst does not have overloads accepting MaybeAlign 
> > > > > so we need to use different `LoadInst` overload depending on whether 
> > > > > alignment is specified.
> > > > 
> > > > That's interesting, because `SelectionDAG::getLoad` has many variants 
> > > > with `MaybeAlign`, but only one with `Align`.
> > > > 
> > > [The documentation](https://llvm.org/docs/LangRef.html#load-instruction) 
> > > says that `LoadInst` alignment is optional so indeed it should accept a 
> > > `MaybeAlign` instead of an `Align`.
> > > I'll send a patch to fix this.
> > > 
> > > Then we can indeed simply use `Var->getAlign()`.
> > Alignment is "optional" in textual IR for backward-compatibility/ease of 
> > use... but it's just a shortcut for specifying "use the ABI alignment of 
> > the value type".  It isn't optional in memory.  Maybe LangRef could be 
> > updated to make that a bit more clear.  (See D77454.)
> > 
> > We should consider doing something similar for globals, but at the time, I 
> > ran out of energy to try to deal with that; backend handling for globals 
> > with unspecified alignment is weird.
> > Enforcing alignment of 1 would potentially force us to generate overly 
> > conservative one byte at a time loads/stores.
> > I agree that passing 0 is a wrong choice here, but 1 does not seem to be 
> > correct, either.
> > Unfortunately LoadInst does not have overloads accepting MaybeAlign so we 
> > need to use different `LoadInst` overload depending on whether alignment is 
> > specified.
> > 
> > ```
> > NewV =  Var->getAlign().isAligned() 
> >   ? llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  
> > Var->getAlign().value(), I)
> >   : llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false, 

[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492276.
craig.topper added a comment.

Add back the new files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zcb-invalid.s
  llvm/test/MC/RISCV/rv32zcb-valid.s
  llvm/test/MC/RISCV/rv64zcb-valid.s

Index: llvm/test/MC/RISCV/rv64zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zcb-valid.s
@@ -0,0 +1,22 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV64 %s
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zba' (Address Generation Instructions), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+# CHECK-NO-RV64: error: instruction requires the following: RV64I Base Instruction Set{{$}}
+c.zext.w s0
+
+# CHECK-ASM-AND-OBJ: c.zext.w s0
+# CHECK-ASM: encoding: [0x71,0x9c]
+add.uw s0, s0, zero
Index: llvm/test/MC/RISCV/rv32zcb-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zcb-valid.s
@@ -0,0 +1,140 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,+experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+zbb,+zba,+experimental-zcb < %s \
+# RUN: | llvm-objdump --mattr=+m,+zbb,+zba,experimental-zcb -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefixes=CHECK-ASM-AND-OBJ %s
+#
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+# RUN: not llvm-mc -triple riscv64 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+# CHECK-ASM-AND-OBJ: c.zext.b s0
+# CHECK-ASM: encoding: [0x61,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.b s0
+
+# CHECK-ASM-AND-OBJ: c.sext.b s0
+# CHECK-ASM: encoding: [0x65,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.b s0
+
+# CHECK-ASM-AND-OBJ: c.zext.h s0
+# CHECK-ASM: encoding: [0x69,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.zext.h s0
+
+# CHECK-ASM-AND-OBJ: c.sext.h s0
+# CHECK-ASM: encoding: [0x6d,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.sext.h s0
+
+# CHECK-ASM-AND-OBJ: c.not s0
+# CHECK-ASM: encoding: [0x75,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.not s0
+
+# CHECK-ASM-AND-OBJ: c.mul s0, s1
+# CHECK-ASM: encoding: [0x45,0x9c]
+# CHECK-NO-EXT: error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' (Integer Multiplication), 'Zcb' (Shortened format for basic bit manipulation instructions){{$}}
+c.mul s0, s1
+
+# CHECK-ASM-AND-OBJ: c.lbu a5, 2(a4)
+# CHECK-ASM: encoding: [0x3c,0x83]
+# CHECK-NO-EXT: error: 

[PATCH] D131141: [RISCV] Add MC support of RISCV Zcb Extension

2023-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 492275.
craig.topper edited the summary of this revision.
craig.topper added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131141

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -179,6 +179,9 @@
 .attribute arch, "rv32izca0p70"
 # CHECK: attribute  5, "rv32i2p0_zca0p70"
 
+.attribute arch, "rv32izcb0p70"
+# CHECK: attribute  5, "rv32i2p0_zca0p70_zcb0p70"
+
 .attribute arch, "rv32izawrs1p0"
 # CHECK: attribute  5, "rv32i2p0_zawrs1p0"
 
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -41,6 +41,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+svpbmt %s -o - | FileCheck --check-prefix=RV32SVPBMT %s
 ; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zca %s -o - | FileCheck --check-prefix=RV32ZCA %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zcb %s -o - | FileCheck --check-prefix=RV32ZCB %s
 
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
@@ -87,6 +88,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zca %s -o - | FileCheck --check-prefix=RV64ZCA %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zcb %s -o - | FileCheck --check-prefix=RV64ZCB %s
 
 ; RV32M: .attribute 5, "rv32i2p0_m2p0"
 ; RV32ZMMUL: .attribute 5, "rv32i2p0_zmmul1p0"
@@ -129,6 +131,7 @@
 ; RV32SVPBMT: .attribute 5, "rv32i2p0_svpbmt1p0"
 ; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
 ; RV32ZCA: .attribute 5, "rv32i2p0_zca0p70"
+; RV32ZCB: .attribute 5, "rv32i2p0_zca0p70_zcb0p70"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -175,6 +178,7 @@
 ; RV64XTHEADVDOT: .attribute 5, "rv64i2p0_f2p0_d2p0_v1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_xtheadvdot1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 ; RV64ZCA: .attribute 5, "rv64i2p0_zca0p70"
+; RV64ZCB: .attribute 5, "rv64i2p0_zca0p70_zcb0p70"
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -1853,6 +1853,7 @@
 include "RISCVInstrInfoD.td"
 include "RISCVInstrInfoC.td"
 include "RISCVInstrInfoZb.td"
+include "RISCVInstrInfoZc.td"
 include "RISCVInstrInfoZk.td"
 include "RISCVInstrInfoV.td"
 include "RISCVInstrInfoZfh.td"
Index: llvm/lib/Target/RISCV/RISCVFeatures.td
===
--- llvm/lib/Target/RISCV/RISCVFeatures.td
+++ llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -299,6 +299,14 @@
"'Zca' (part of the C extension, excluding "
"compressed floating point loads/stores)">;
 
+def FeatureExtZcb
+: SubtargetFeature<"experimental-zcb", "HasStdExtZcb", "true",
+   "'Zcb' (Shortened format for basic bit manipulation instructions)", 
+   [FeatureExtZca]>;
+def HasStdExtZcb : Predicate<"Subtarget->hasStdExtZcb()">,
+ AssemblerPredicate<(all_of FeatureExtZcb),
+ "'Zcb' (Shortened format for basic bit manipulation instructions)">;
+
 def FeatureExtZcd
 : SubtargetFeature<"experimental-zcd", "HasStdExtZcd", "true",
"'Zcd' (Compressed Double-Precision Floating-Point Instructions)">;
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -618,6 +618,16 @@
VK == RISCVMCExpr::VK_RISCV_None;
   }
 
+  bool isUImm2Lsb0() const {
+int64_t Imm;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
+if (!isImm())
+  return false;
+bool IsConstantImm = 

[PATCH] D142459: [clang] Deprecate uses of GlobalObject::getAlignment

2023-01-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:491
   new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+ Var->getAlign().valueOrOne(), I);
   WorkItem.pop_back();

efriedma wrote:
> gchatelet wrote:
> > barannikov88 wrote:
> > > barannikov88 wrote:
> > > > tra wrote:
> > > > > gchatelet wrote:
> > > > > > tra wrote:
> > > > > > > This appears to be a change in behavior. AFAICT, previously used 
> > > > > > > Var->getAlignment() could return alignment value or 0. Now it's 
> > > > > > > value or 1.
> > > > > > > 
> > > > > > > Is it intentional?
> > > > > > The previous statement was constructing an `llvm::Align` from a 
> > > > > > value, and `llvm::Align` [asserts when the provided value is 
> > > > > > 0](https://github.com/llvm/llvm-project/blob/4ab2246d486ba30c4b2d654323a0c0b97565c0f1/llvm/include/llvm/Support/Alignment.h#L76-L81).
> > > > > >  This means that it is undefined to pass the value `0`.
> > > > > > 
> > > > > > As far as `LoadInst` is concerned it can only accept valid 
> > > > > > alignments (i.e., powers of two => non zero).
> > > > > > 
> > > > > > So you're right that it is not strictly NFC and that 
> > > > > > `*Var->getAlign()`would be a more rigorous transformation but I 
> > > > > > //think// that converting the `0` value to `1` moves us from UB to 
> > > > > > semantically valid code.
> > > > > > 
> > > > > > I don't feel strongly about it though and I'm fine changing this to 
> > > > > > `*Var->getAlign()` to keep this patch NFC. WDYT?
> > > > > Enforcing alignment of 1 would potentially force us to generate 
> > > > > overly conservative one byte at a time loads/stores.
> > > > > I agree that passing 0 is a wrong choice here, but 1 does not seem to 
> > > > > be correct, either.
> > > > > Unfortunately LoadInst does not have overloads accepting MaybeAlign 
> > > > > so we need to use different `LoadInst` overload depending on whether 
> > > > > alignment is specified.
> > > > > 
> > > > > ```
> > > > > NewV =  Var->getAlign().isAligned() 
> > > > >   ? llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  
> > > > > Var->getAlign().value(), I)
> > > > >   : llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  
> > > > > I);
> > > > > ```
> > > > > 
> > > > > @yaxunl -- Sam, does it make sense? This seems to be largely 
> > > > > HIP-specific.
> > > > I think it should be just `Var->getAlign()` to allow propagating absent 
> > > > alignment.
> > > > Curiously, the old code didn't assert because `GlobalVariable` seem to 
> > > > always(?) have non-empty alignment if the global had an associated 
> > > > `VarDecl` (set [[ 
> > > > https://github.com/llvm/llvm-project/blob/6ad0788c332bb2043142954d300c49ac3e537f34/clang/lib/CodeGen/CodeGenModule.cpp#L4442
> > > >  | here ]], changed(?) by [[ 
> > > > https://github.com/llvm/llvm-project/commit/c79099e0f44d0f85515fd30c83923d9d9dc1679b
> > > >  | this patch ]]).
> > > > 
> > > > Unfortunately LoadInst does not have overloads accepting MaybeAlign so 
> > > > we need to use different `LoadInst` overload depending on whether 
> > > > alignment is specified.
> > > 
> > > That's interesting, because `SelectionDAG::getLoad` has many variants 
> > > with `MaybeAlign`, but only one with `Align`.
> > > 
> > [The documentation](https://llvm.org/docs/LangRef.html#load-instruction) 
> > says that `LoadInst` alignment is optional so indeed it should accept a 
> > `MaybeAlign` instead of an `Align`.
> > I'll send a patch to fix this.
> > 
> > Then we can indeed simply use `Var->getAlign()`.
> Alignment is "optional" in textual IR for backward-compatibility/ease of 
> use... but it's just a shortcut for specifying "use the ABI alignment of the 
> value type".  It isn't optional in memory.  Maybe LangRef could be updated to 
> make that a bit more clear.  (See D77454.)
> 
> We should consider doing something similar for globals, but at the time, I 
> ran out of energy to try to deal with that; backend handling for globals with 
> unspecified alignment is weird.
> Enforcing alignment of 1 would potentially force us to generate overly 
> conservative one byte at a time loads/stores.
> I agree that passing 0 is a wrong choice here, but 1 does not seem to be 
> correct, either.
> Unfortunately LoadInst does not have overloads accepting MaybeAlign so we 
> need to use different `LoadInst` overload depending on whether alignment is 
> specified.
> 
> ```
> NewV =  Var->getAlign().isAligned() 
>   ? llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  
> Var->getAlign().value(), I)
>   : llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  I);
> ```
> 
> @yaxunl -- Sam, does it make sense? This seems to be largely HIP-specific.

Thanks for reminding me about this.

If it is 0 it should have caused an assertion.

We can 

[PATCH] D142564: [clang-doc] Reduce duplicate code with template

2023-01-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 492274.
paulkirth added a comment.

Clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142564

Files:
  clang-tools-extra/clang-doc/Representation.cpp


Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -54,51 +54,16 @@
   return -1;
 }
 
-void reduceChildren(std::vector ,
-std::vector &) {
-  for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
-  Children.push_back(std::move(ChildToMerge));
-  continue;
-}
-Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector ,
-std::vector &) {
-  for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
-  Children.push_back(std::move(ChildToMerge));
-  continue;
-}
-Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector ,
-std::vector &) {
-  for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
-  Children.push_back(std::move(ChildToMerge));
-  continue;
-}
-Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector ,
-std::vector &) {
+template 
+void reduceChildren(std::vector ,
+std::vector &) {
   for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
+int MergeIdx = getChildIndexIfExists(Children, ChildToMerge);
+if (MergeIdx == -1) {
   Children.push_back(std::move(ChildToMerge));
   continue;
 }
-Children[mergeIdx].merge(std::move(ChildToMerge));
+Children[MergeIdx].merge(std::move(ChildToMerge));
   }
 }
 


Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -54,51 +54,16 @@
   return -1;
 }
 
-void reduceChildren(std::vector ,
-std::vector &) {
-  for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
-  Children.push_back(std::move(ChildToMerge));
-  continue;
-}
-Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector ,
-std::vector &) {
-  for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
-  Children.push_back(std::move(ChildToMerge));
-  continue;
-}
-Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector ,
-std::vector &) {
-  for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
-  Children.push_back(std::move(ChildToMerge));
-  continue;
-}
-Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector ,
-std::vector &) {
+template 
+void reduceChildren(std::vector ,
+std::vector &) {
   for (auto  : ChildrenToMerge) {
-int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-if (mergeIdx == -1) {
+int MergeIdx = getChildIndexIfExists(Children, ChildToMerge);
+if (MergeIdx == -1) {
   Children.push_back(std::move(ChildToMerge));
   continue;
 }
-Children[mergeIdx].merge(std::move(ChildToMerge));
+Children[MergeIdx].merge(std::move(ChildToMerge));
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142587: [clang-tidy] Improved too-small-loop-variable with bit-field support

2023-01-25 Thread Piotr Zegar via Phabricator via cfe-commits
ClockMan created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
ClockMan published this revision for review.
ClockMan added a comment.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Ready for review.


Implemented support for bit-field members as a loop variable
or upper limit. Supporting also non bit-field integer members.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142587

Files:
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
@@ -46,6 +46,16 @@
   }
 }
 
+void voidBadForLoop7() {
+struct Int  {
+int value;
+} i;
+
+  for (i.value = 0; i.value < size(); ++i.value) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: loop variable has narrower type 'int' than iteration's upper bound 'long' [bugprone-too-small-loop-variable]
+  }
+}
+
 void voidForLoopUnsignedBound() {
   unsigned size = 3147483647;
   for (int i = 0; i < size; ++i) {
@@ -253,3 +263,113 @@
   for (short i = 0; i < size; ++i) { // no warning
   }
 }
+
+// Should detect proper size of upper bound bitfield
+void voidForLoopWithBitfieldOnUpperBound() {
+  struct StructWithBitField {
+  unsigned bitfield : 5;
+  } value = {};
+
+  for(unsigned char i = 0U; i < value.bitfield; ++i) { // no warning
+  }
+}
+
+// Should detect proper size of loop variable bitfield
+void voidForLoopWithBitfieldOnLoopVar() {
+  struct StructWithBitField {
+  unsigned bitfield : 9;
+  } value = {};
+
+  unsigned char upperLimit = 100U;
+
+  for(value.bitfield = 0U; value.bitfield < upperLimit; ++value.bitfield) {
+  }
+}
+
+// Should detect proper size of loop variable and upper bound
+void voidForLoopWithBitfieldOnLoopVarAndUpperBound() {
+  struct StructWithBitField {
+  unsigned var : 5, limit : 4;
+  } value = {};
+
+  for(value.var = 0U; value.var < value.limit; ++value.var) {
+  }
+}
+
+// Should detect proper size of loop variable and upper bound on integers
+void voidForLoopWithBitfieldOnLoopVarAndUpperBoundOnInt() {
+  struct StructWithBitField {
+  unsigned var : 5;
+  int limit : 6;
+  } value = {};
+
+  for(value.var = 0U; value.var < value.limit; ++value.var) {
+  }
+}
+
+void badForLoopWithBitfieldOnUpperBound() {
+  struct StructWithBitField {
+  unsigned bitfield : 9;
+  } value = {};
+
+  for(unsigned char i = 0U; i < value.bitfield; ++i) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: loop variable has narrower type 'unsigned char' than iteration's upper bound 'unsigned int:9' [bugprone-too-small-loop-variable]
+  }
+}
+
+void badForLoopWithBitfieldOnLoopVar() {
+  struct StructWithBitField {
+  unsigned bitfield : 7;
+  } value = {};
+
+  unsigned char upperLimit = 100U;
+
+  for(value.bitfield = 0U; value.bitfield < upperLimit; ++value.bitfield) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: loop variable has narrower type 'unsigned int:7' than iteration's upper bound 'unsigned char' [bugprone-too-small-loop-variable]
+  }
+}
+
+void badForLoopWithBitfieldOnLoopVarAndUpperBound() {
+  struct StructWithBitField {
+  unsigned var : 5, limit : 6;
+  } value = {};
+
+  for(value.var = 0U; value.var < value.limit; ++value.var) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: loop variable has narrower type 'unsigned int:5' than iteration's upper bound 'unsigned int:6' [bugprone-too-small-loop-variable]
+  }
+}
+
+void badForLoopWithBitfieldOnLoopVarOnIntAndUpperBound() {
+  struct StructWithBitField {
+  int var : 5;
+  unsigned limit : 5;
+  } value = {};
+
+  for(value.var = 0U; value.var < value.limit; ++value.var) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: loop variable has narrower type 'int:5' than iteration's upper bound 'unsigned int:5' [bugprone-too-small-loop-variable]
+  }
+}
+
+void badForLoopWithBitfieldOnLoopVarAndUpperBoundOnInt() {
+  struct StructWithBitField {
+  unsigned var : 5;
+  int limit : 7;
+  } value = {};
+
+  for(value.var = 0U; value.var < value.limit; ++value.var) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: loop variable has narrower type 'unsigned int:5' than iteration's upper bound 'int:7' [bugprone-too-small-loop-variable]
+  }
+}
+
+void badForLoopWithBitfieldOnLoopVarAndUpperBoundOnPtr() {
+  struct StructWithBitField {
+  unsigned var : 5, limit : 6;
+  } value = {};
+
+  StructWithBitField* ptr = 
+
+  for(ptr->var = 0U; ptr->var < ptr->limit; ++ptr->var) {
+  // 

[PATCH] D131137: [clang][misexpect] Add support to clang for profitable annotation diagnostics

2023-01-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 492269.
paulkirth added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131137

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Profile/Inputs/missing-annotation.proftext
  clang/test/Profile/missing-annotation.c

Index: clang/test/Profile/missing-annotation.c
===
--- /dev/null
+++ clang/test/Profile/missing-annotation.c
@@ -0,0 +1,37 @@
+// Test that missing annotation diagnostics are suggested for hot branches
+
+// test diagnostics are issued when profiling data mis-matches annotations
+// RUN: llvm-profdata merge %S/Inputs/missing-annotation.proftext -o %t.profdata
+// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify=exact -fdiagnostics-missing-annotations -debug-info-kind=line-tables-only -Rpass=missing-annotations
+
+
+// foo-no-diagnostics
+
+int foo(int);
+int baz(int);
+int buzz();
+
+const int inner_loop = 100;
+const int outer_loop = 2000;
+int bar() { 
+  int rando = buzz();
+  int x = 0;
+  if (rando % (outer_loop * inner_loop) == 0) { // exact-remark {{Extremely hot condition. Consider adding  llvm.expect intrinsic}}
+x = baz(rando);
+  } else {
+x = foo(50);
+  }
+  return x;
+}
+
+int fizz() {
+  int rando = buzz();
+  int x = 0;
+  if (rando % (outer_loop * inner_loop) == 0) { // exact-remark {{Extremely hot condition. Consider adding  llvm.expect intrinsic}}
+x = baz(rando);
+  } else {
+x = foo(50);
+  }
+  return x;
+}
+
Index: clang/test/Profile/Inputs/missing-annotation.proftext
===
--- /dev/null
+++ clang/test/Profile/Inputs/missing-annotation.proftext
@@ -0,0 +1,18 @@
+bar
+# Func Hash:
+11262309464
+# Num Counters:
+2
+# Counter Values:
+20
+1
+
+fizz
+# Func Hash:
+11262309464
+# Num Counters:
+2
+# Counter Values:
+20
+1
+
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -347,6 +347,10 @@
 Ctx.setMisExpectWarningRequested(true);
   }
 
+  if (CodeGenOpts.MissingAnnotations) {
+Ctx.setAnnotationDiagsRequested(true);
+  }
+
   if (CodeGenOpts.DiagnosticsMisExpectTolerance) {
 Ctx.setDiagnosticsMisExpectTolerance(
 CodeGenOpts.DiagnosticsMisExpectTolerance);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -492,6 +492,7 @@
   Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
   Options.MCOptions.AsSecureLogFile = CodeGenOpts.AsSecureLogFile;
   Options.MisExpect = CodeGenOpts.MisExpect;
+  Options.MissingAnnotations = CodeGenOpts.MissingAnnotations;
 
   return true;
 }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1509,6 +1509,10 @@
 def fdiagnostics_misexpect_tolerance_EQ : Joined<["-"], "fdiagnostics-misexpect-tolerance=">,
 Group, Flags<[CC1Option]>, MetaVarName<"">,
 HelpText<"Prevent misexpect diagnostics from being output if the profile counts are within N% of the expected. ">;
+defm diagnostics_missing_annotations : BoolFOption<"diagnostics-missing-annotations",
+  CodeGenOpts<"MissingAnnotations">, DefaultFalse,
+  PosFlag,
+  NegFlag>;
 defm diagnostics_show_option : BoolFOption<"diagnostics-show-option",
 DiagnosticOpts<"ShowOptionNames">, DefaultTrue,
 NegFlag, PosFlag>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -180,6 +180,7 @@
 CODEGENOPT(NoWarn, 1, 0) ///< Set when -Wa,--no-warn is enabled.
 CODEGENOPT(NoTypeCheck   , 1, 0) ///< Set when -Wa,--no-type-check is enabled.
 CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled
+CODEGENOPT(MissingAnnotations, 1, 0) ///< Set when suggesting missing perf annotations
 CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled.
 CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
  ///< inline line tables.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105584: [MLIR][OpenMP] Distribute Construct Operation

2023-01-25 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added a comment.

In D105584#4081228 , 
@kiranchandramohan wrote:

> Since the plan is to switch to the Canonical Style operation, maybe this can 
> wait till the `omp.canonical_loop` changes are in?

Ok..make sense


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105584

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-01-25 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I'm having a little trouble following what the meaning of an "Address" is with 
this patch.  The `Pointer` member refers to an encoded value, and calling 
getPointer() emits IR to decode it?  Could use a few comments to explain the 
API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142584

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


[PATCH] D142584: [CodeGen] Add a boolean flag to `Address::getPointer` and `Lvalue::getPointer` that indicates whether the pointer is known not to be null

2023-01-25 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: rjmccall, ab, efriedma.
ahatanak added a project: clang.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
ahatanak requested review of this revision.

The flag will be used for the arm64e work we plan to upstream in the future 
(see https://lists.llvm.org/pipermail/llvm-dev/2019-October/136091.html). 
Passing `KnownNonNull_t::True` allows clang to avoid emitting null checks on 
arm64e. Currently the flag has no effect on code generation on other targets.

This is the first patch and there are many more places where 
`KnownNonNull_t::True` can be passed. I plan to fix those places in future 
patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142584

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCXXABI.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGNonTrivialStruct.cpp
  clang/lib/CodeGen/CGValue.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp

Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1639,7 +1639,8 @@
   llvm::Value *Implicit =
   getCXXDestructorImplicitParam(CGF, DD, Type, ForVirtualBase,
 Delegating); // = nullptr
-  CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy,
+  CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(KnownNonNull_t::True),
+ThisTy,
 /*ImplicitParam=*/Implicit,
 /*ImplicitParamTy=*/QualType(), nullptr);
   if (BaseDtorEndBB) {
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1698,8 +1698,8 @@
   else
 Callee = CGCallee::forDirect(CGM.getAddrOfCXXStructor(GD), GD);
 
-  CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy, VTT, VTTTy,
-nullptr);
+  CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(KnownNonNull_t::True),
+ThisTy, VTT, VTTTy, nullptr);
 }
 
 void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables ,
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1171,7 +1171,8 @@
 LValue ThisFieldLValue = EmitLValueForLambdaField(LambdaThisCaptureField);
 if (!LambdaThisCaptureField->getType()->isPointerType()) {
   // If the enclosing object was captured by value, just use its address.
-  CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer();
+  CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer(
+  KnownNonNull_t::True);
 } else {
   // Load the lvalue pointed to by the field, since '*this' was captured
   // by reference.
Index: clang/lib/CodeGen/CGValue.h
===
--- clang/lib/CodeGen/CGValue.h
+++ clang/lib/CodeGen/CGValue.h
@@ -334,7 +334,9 @@
   void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; }
 
   // simple lvalue
-  llvm::Value *getPointer(CodeGenFunction ) const {
+  llvm::Value *
+  getPointer(CodeGenFunction ,
+ KnownNonNull_t KnownNonNull = KnownNonNull_t::False) const {
 assert(isSimple());
 return V;
   }
Index: clang/lib/CodeGen/CGNonTrivialStruct.cpp
===
--- clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -491,8 +491,9 @@
 
 for (unsigned I = 0; I < N; ++I) {
   Alignments[I] = Addrs[I].getAlignment();
-  Ptrs[I] = CallerCGF.Builder.CreateElementBitCast(
-  Addrs[I], CallerCGF.CGM.Int8PtrTy).getPointer();
+  Ptrs[I] = CallerCGF.Builder
+.CreateElementBitCast(Addrs[I], CallerCGF.CGM.Int8PtrTy)
+.getPointer(KnownNonNull_t::True);
 }
 
 if (llvm::Function *F =
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2240,7 +2240,8 @@
   case CK_DerivedToBase: {
 // The EmitPointerWithAlignment path does this fine; just discard
 // the alignment.
-return 

[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana planned changes to this revision.
iana added a comment.

In D140250#4081133 , @iana wrote:

> In D140250#4081119 , @rsmith wrote:
>
>> In D140250#4081102 , @rsmith wrote:
>>
>>> Our builtin header `stddef.h` shouldn't be built as a module. It 
>>> fundamentally needs to be treated as a textual header, because it consumes 
>>> macros defined by the includer. The module map that we provide with our 
>>> builtin headers does not cover `stddef.h` for that reason.
>>
>> That said... the ` __has_feature(modules)` checks throughout `stddef.h` look 
>> pretty wrong to me. They're probably working around the infelicities of the 
>> `-fno-modules-local-submodule-visibility` mode; maybe we can disable them 
>> when not in that mode?
>
> It ends up being covered by `Darwin.C.stddef` on Apple platforms (due to some 
> builtin shenanigans elsewhere in clang). Maybe we could make stddef.h be a 
> `textual` header in a `_Builtin_stddef` module in clang and that would do the 
> trick instead of splitting it into a bunch of different files.

This seems to work in initial testing. I'll probably drop this diff and make a 
new one to make stddef.h be a `textual` header in a new `_Builtin_stddef` 
module in clang when I do some more testing then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D142583: [SPIR-V] Add support for __arithmetic_fence builtin for SYCL targets.

2023-01-25 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

"[SPIR-V] Add support for __arithmetic_fence builtin for SYCL targets." -> 
"[SPIR] Add support for __arithmetic_fence builtin for SPIR target."




Comment at: clang/test/CodeGen/arithmetic-fence-builtin.c:16
+// Test with fast math on spir target
+// RUN: %clang_cc1 -triple spir64  -emit-llvm -fsycl-is-device \
+// RUN: -mreassociate -o - %s \





Comment at: clang/test/CodeGen/arithmetic-fence-builtin.c:74
 int subit(float a, float b, float *fp) {
-  // CHECKFAST: define {{.*}}@subit(float noundef %a, float noundef %b{{.*}}
+  // CHECKPRECISE: define {{.*}}@subit(float noundef %a, float noundef %b{{.*}}
   *fp = __arithmetic_fence(a - b);

What is different for SPIR target here?



Comment at: clang/test/Sema/arithmetic-fence-builtin.c:5
 // RUN:-fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
+// RUN: %clang_cc1 -triple spir64  -emit-llvm -fsycl-is-device \
+// RUN: -o - -verify -x c++ %s




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142583

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


[clang] 11656f2 - [CUDA] Fix output from `ptxas` being removes as a temporary file

2023-01-25 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-01-25T16:24:30-06:00
New Revision: 11656f204aa5fd972564e76641c00ca058ba8c0d

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

LOG: [CUDA] Fix output from `ptxas` being removes as a temporary file

Summary:
The logic here is to add the `.cubin` temporary file if we had to create
a new filename to handle it. Unfortuantely the logic was wrong because
we compare `const char *` values here. This logic seems to have been
wrong for some time, but was never noticed since we never used the
relocatable output.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Cuda.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 484c8c0702643..9a231c06a0749 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -443,7 +443,7 @@ void NVPTX::Assembler::ConstructJob(Compilation , const 
JobAction ,
   CmdArgs.push_back("--gpu-name");
   CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
   CmdArgs.push_back("--output-file");
-  const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output));
+  std::string OutputFileName = TC.getInputFilename(Output);
 
   // If we are invoking `nvlink` internally we need to output a `.cubin` file.
   // Checking if the output is a temporary is the cleanest way to determine
@@ -455,12 +455,12 @@ void NVPTX::Assembler::ConstructJob(Compilation , const 
JobAction ,
   C.getTempFiles().end()) {
 SmallString<256> Filename(Output.getFilename());
 llvm::sys::path::replace_extension(Filename, "cubin");
-OutputFileName = Args.MakeArgString(Filename);
+OutputFileName = Filename.str();
   }
   if (Output.isFilename() && OutputFileName != Output.getFilename())
-C.addTempFile(OutputFileName);
+C.addTempFile(Args.MakeArgString(OutputFileName));
 
-  CmdArgs.push_back(OutputFileName);
+  CmdArgs.push_back(Args.MakeArgString(OutputFileName));
   for (const auto  : Inputs)
 CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
 



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


[PATCH] D142583: [SPIR-V] Add support for __arithmetic_fence builtin for SYCL targets.

2023-01-25 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam created this revision.
zahiraam added reviewers: bader, andrew.w.kaylor.
Herald added subscribers: Naghasan, Anastasia, ebevhan, yaxunl.
Herald added a project: All.
zahiraam requested review of this revision.
Herald added a project: clang.

__arithmetic_fence enforces ordering on expression evaluation when fast math is 
enabled.
In fast math mode some floating-point optimizations are performed such as 
reassociation and distribution.

For example, the compiler may transform (a+b)+c into a+(b+c). Although these 
two expressions are
equivalent in integer arithmetic, they may not be in floating-point arithmetic. 
The builtin tells the compiler that
the expression in parenthesis can’t be re-associated or distributed.
__arithmetic_fence(a+b)+c is not equivalent to a+(b+c).

This patch adds the support of the builtin to SPIR-V.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142583

Files:
  clang/lib/Basic/Targets/SPIR.h
  clang/test/CodeGen/arithmetic-fence-builtin.c
  clang/test/Sema/arithmetic-fence-builtin.c


Index: clang/test/Sema/arithmetic-fence-builtin.c
===
--- clang/test/Sema/arithmetic-fence-builtin.c
+++ clang/test/Sema/arithmetic-fence-builtin.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s
 // RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s \
 // RUN:-fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
+// RUN: %clang_cc1 -triple spir64  -emit-llvm -fsycl-is-device \
+// RUN: -o - -verify -x c++ %s
 #ifndef PPC
 int v;
 template  T addT(T a, T b) {
Index: clang/test/CodeGen/arithmetic-fence-builtin.c
===
--- clang/test/CodeGen/arithmetic-fence-builtin.c
+++ clang/test/CodeGen/arithmetic-fence-builtin.c
@@ -1,17 +1,23 @@
 // Test with fast math
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -DFAST \
-// RUN: -mreassociate \
-// RUN: -o - %s | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKNP %s
+// RUN: -mreassociate -o - %s \
+// RUN: | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKPRECISE,CHECKNP %s
 //
 // Test with fast math and fprotect-parens
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -DFAST \
-// RUN: -mreassociate -fprotect-parens -ffp-contract=on\
-// RUN: -o - %s | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKPP %s
+// RUN: -mreassociate -fprotect-parens -ffp-contract=on -o - %s \
+// RUN: | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKPRECISE,CHECKPP %s
 //
 // Test without fast math: llvm intrinsic not created
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -fprotect-parens\
 // RUN: -o - %s | FileCheck --implicit-check-not="llvm.arithmetic.fence" %s
 //
+// Test with fast math on spir target
+// RUN: %clang_cc1 -triple spir64  -emit-llvm -fsycl-is-device \
+// RUN: -mreassociate -o - %s \
+// RUN: | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKNP %s
+//
+
 int v;
 int addit(float a, float b) {
   // CHECK: define {{.*}}@addit(float noundef %a, float noundef %b) #0 {
@@ -65,7 +71,7 @@
 #ifdef FAST
 #pragma float_control(precise, on)
 int subit(float a, float b, float *fp) {
-  // CHECKFAST: define {{.*}}@subit(float noundef %a, float noundef %b{{.*}}
+  // CHECKPRECISE: define {{.*}}@subit(float noundef %a, float noundef %b{{.*}}
   *fp = __arithmetic_fence(a - b);
   *fp = (a + b);
   // CHECK-NOT: call{{.*}} float @llvm.arithmetic.fence.f32(float noundef %add)
Index: clang/lib/Basic/Targets/SPIR.h
===
--- clang/lib/Basic/Targets/SPIR.h
+++ clang/lib/Basic/Targets/SPIR.h
@@ -191,6 +191,8 @@
   bool hasFeature(StringRef Feature) const override {
 return Feature == "spir";
   }
+
+  bool checkArithmeticFenceSupported() const override { return true; }
 };
 
 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {


Index: clang/test/Sema/arithmetic-fence-builtin.c
===
--- clang/test/Sema/arithmetic-fence-builtin.c
+++ clang/test/Sema/arithmetic-fence-builtin.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s
 // RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s \
 // RUN:-fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
+// RUN: %clang_cc1 -triple spir64  -emit-llvm -fsycl-is-device \
+// RUN: -o - -verify -x c++ %s
 #ifndef PPC
 int v;
 template  T addT(T a, T b) {
Index: clang/test/CodeGen/arithmetic-fence-builtin.c
===
--- clang/test/CodeGen/arithmetic-fence-builtin.c
+++ clang/test/CodeGen/arithmetic-fence-builtin.c
@@ -1,17 +1,23 @@
 // Test with fast math
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -DFAST \
-// RUN: -mreassociate \
-// RUN: -o - %s | FileCheck --check-prefixes 

[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-25 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

I don't know sphinx enough to know if the trailing underscore is needed in 
links, but there's about 5 links that don't have the underscore (Search for

  >`)

)




Comment at: clang/docs/ReleaseNotes.rst:577
+  potential false positives, this diagnostic will not diagnose use of the
+  ``true`` macro (from ``>``) in C language mode despite the macro
+  being defined to expand to ``1``. (`#53253 
`_)





Comment at: clang/docs/ReleaseNotes.rst:587
 
-C2x Feature Support

-- Implemented `WG14 N2662 
`_,
-  so the [[maybe_unused]] attribute may be applied to a label to silence an
-  ``-Wunused-label`` warning.
-- Implemented `WG14 N2508 
`_,
-  so labels can placed everywhere inside a compound statement.
-- Implemented `WG14 N2927 
`_,
-  the Not-so-magic ``typeof`` operator. Also implemented
-  `WG14 N2930 `_,
-  renaming ``remove_quals``, so the ``typeof_unqual`` operator is also
-  supported. Both of these operators are supported only in C2x mode. The
-  ``typeof`` operator specifies the type of the given parenthesized expression
-  operand or type name, including all qualifiers. The ``typeof_unqual``
-  operator is similar to ``typeof`` except that all qualifiers are removed,
-  including atomic type qualification and type attributes which behave like a
-  qualifier, such as an address space attribute.
+- Correctly diagnose a future keyword if it exist as a keyword in the higher
+  language version and specifies in which version it will be a keyword. This





Comment at: clang/docs/ReleaseNotes.rst:589
+  language version and specifies in which version it will be a keyword. This
+  supports both c and c++ language.
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142578

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


[PATCH] D105584: [MLIR][OpenMP] Distribute Construct Operation

2023-01-25 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.
Herald added a subscriber: thopre.

Since the plan is to switch to the Canonical Style operation, may be this can 
wait till the `omp.canonical_loop` changes are in?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105584

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


[PATCH] D142459: [clang] Deprecate uses of GlobalObject::getAlignment

2023-01-25 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:491
   new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
- llvm::Align(Var->getAlignment()), I);
+ Var->getAlign().valueOrOne(), I);
   WorkItem.pop_back();

gchatelet wrote:
> barannikov88 wrote:
> > barannikov88 wrote:
> > > tra wrote:
> > > > gchatelet wrote:
> > > > > tra wrote:
> > > > > > This appears to be a change in behavior. AFAICT, previously used 
> > > > > > Var->getAlignment() could return alignment value or 0. Now it's 
> > > > > > value or 1.
> > > > > > 
> > > > > > Is it intentional?
> > > > > The previous statement was constructing an `llvm::Align` from a 
> > > > > value, and `llvm::Align` [asserts when the provided value is 
> > > > > 0](https://github.com/llvm/llvm-project/blob/4ab2246d486ba30c4b2d654323a0c0b97565c0f1/llvm/include/llvm/Support/Alignment.h#L76-L81).
> > > > >  This means that it is undefined to pass the value `0`.
> > > > > 
> > > > > As far as `LoadInst` is concerned it can only accept valid alignments 
> > > > > (i.e., powers of two => non zero).
> > > > > 
> > > > > So you're right that it is not strictly NFC and that 
> > > > > `*Var->getAlign()`would be a more rigorous transformation but I 
> > > > > //think// that converting the `0` value to `1` moves us from UB to 
> > > > > semantically valid code.
> > > > > 
> > > > > I don't feel strongly about it though and I'm fine changing this to 
> > > > > `*Var->getAlign()` to keep this patch NFC. WDYT?
> > > > Enforcing alignment of 1 would potentially force us to generate overly 
> > > > conservative one byte at a time loads/stores.
> > > > I agree that passing 0 is a wrong choice here, but 1 does not seem to 
> > > > be correct, either.
> > > > Unfortunately LoadInst does not have overloads accepting MaybeAlign so 
> > > > we need to use different `LoadInst` overload depending on whether 
> > > > alignment is specified.
> > > > 
> > > > ```
> > > > NewV =  Var->getAlign().isAligned() 
> > > >   ? llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  
> > > > Var->getAlign().value(), I)
> > > >   : llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,  I);
> > > > ```
> > > > 
> > > > @yaxunl -- Sam, does it make sense? This seems to be largely 
> > > > HIP-specific.
> > > I think it should be just `Var->getAlign()` to allow propagating absent 
> > > alignment.
> > > Curiously, the old code didn't assert because `GlobalVariable` seem to 
> > > always(?) have non-empty alignment if the global had an associated 
> > > `VarDecl` (set [[ 
> > > https://github.com/llvm/llvm-project/blob/6ad0788c332bb2043142954d300c49ac3e537f34/clang/lib/CodeGen/CodeGenModule.cpp#L4442
> > >  | here ]], changed(?) by [[ 
> > > https://github.com/llvm/llvm-project/commit/c79099e0f44d0f85515fd30c83923d9d9dc1679b
> > >  | this patch ]]).
> > > 
> > > Unfortunately LoadInst does not have overloads accepting MaybeAlign so we 
> > > need to use different `LoadInst` overload depending on whether alignment 
> > > is specified.
> > 
> > That's interesting, because `SelectionDAG::getLoad` has many variants with 
> > `MaybeAlign`, but only one with `Align`.
> > 
> [The documentation](https://llvm.org/docs/LangRef.html#load-instruction) says 
> that `LoadInst` alignment is optional so indeed it should accept a 
> `MaybeAlign` instead of an `Align`.
> I'll send a patch to fix this.
> 
> Then we can indeed simply use `Var->getAlign()`.
Alignment is "optional" in textual IR for backward-compatibility/ease of use... 
but it's just a shortcut for specifying "use the ABI alignment of the value 
type".  It isn't optional in memory.  Maybe LangRef could be updated to make 
that a bit more clear.  (See D77454.)

We should consider doing something similar for globals, but at the time, I ran 
out of energy to try to deal with that; backend handling for globals with 
unspecified alignment is weird.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142459

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


[PATCH] D129951: adds `__disable_adl` attribute

2023-01-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:542
 If a statement is marked ``nomerge`` and contains call expressions, those call
-expressions inside the statement will not be merged during optimization. This 
+expressions inside the statement will not be merged during optimization. This
 attribute can be used to prevent the optimizer from obscuring the source

A lot of these look like unrelated changes.



Comment at: clang/lib/Parse/ParseDecl.cpp:3788-3789
+  SourceLocation AttrNameLoc = Tok.getLocation();
+  DS.getAttributes().addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc,
+nullptr, 0, ParsedAttr::AS_Keyword);
+  break;





Comment at: clang/lib/Sema/SemaOverload.cpp:6514
 ND = SpecInfo->getTemplate();
-  
   if (ND->getFormalLinkage() == Linkage::InternalLinkage) {

Unrelated change?



Comment at: clang/lib/Sema/SemaOverload.cpp:13019
CandidateSet, PartialOverloading,
-   /*KnownValid*/ true);
+   /*KnownValid*/ true, ULE);
 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129951

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


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D140250#4081119 , @rsmith wrote:

> In D140250#4081102 , @rsmith wrote:
>
>> Our builtin header `stddef.h` shouldn't be built as a module. It 
>> fundamentally needs to be treated as a textual header, because it consumes 
>> macros defined by the includer. The module map that we provide with our 
>> builtin headers does not cover `stddef.h` for that reason.
>
> That said... the ` __has_feature(modules)` checks throughout `stddef.h` look 
> pretty wrong to me. They're probably working around the infelicities of the 
> `-fno-modules-local-submodule-visibility` mode; maybe we can disable them 
> when not in that mode?

It ends up being covered by `Darwin.C.stddef` on Apple platforms (due to some 
builtin shenanigans elsewhere in clang). Maybe we could make stddef.h be a 
`textual` header in a `_Builtin_stddef` module in clang and that would do the 
trick instead of splitting it into a bunch of different files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D131306: [llvm][misexpect] Track provenance of branch weights

2023-01-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 492246.
paulkirth added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131306

Files:
  clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
  clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
  llvm/include/llvm/IR/MDBuilder.h
  llvm/include/llvm/IR/ProfDataUtils.h
  llvm/lib/Analysis/BranchProbabilityInfo.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/MDBuilder.cpp
  llvm/lib/IR/ProfDataUtils.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/lib/Transforms/Utils/MisExpect.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
  llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
  llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
  llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
  llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
  llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
  llvm/test/Transforms/LowerExpectIntrinsic/phi_unexpect.ll

Index: llvm/test/Transforms/LowerExpectIntrinsic/phi_unexpect.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/phi_unexpect.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/phi_unexpect.ll
@@ -235,5 +235,5 @@
   ret void
 }
 
-; CHECK: !0 = !{!"branch_weights", i32 2147483647, i32 1}
-; CHECK: !1 = !{!"branch_weights", i32 1, i32 2147483647}
+; CHECK: !0 = !{!"branch_weights", !"expected", i32 2147483647, i32 1}
+; CHECK: !1 = !{!"branch_weights", !"expected", i32 1, i32 2147483647}
Index: llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
@@ -53,4 +53,4 @@
 
 !0 = !{!"clang version 5.0.0 (trunk 302965)"}
 
-; CHECK: [[WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}
+; CHECK: [[WEIGHT]] = !{!"branch_weights", !"expected", i32 1, i32 2000}
Index: llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
@@ -99,5 +99,5 @@
 
 
 !0 = !{!"clang version 5.0.0 (trunk 302965)"}
-; CHECK: [[WEIGHT]] = !{!"branch_weights", i32 2000, i32 1}
-; CHECK: [[WEIGHT2]] = !{!"branch_weights", i32 1, i32 2000}
+; CHECK: [[WEIGHT]] = !{!"branch_weights", !"expected", i32 2000, i32 1}
+; CHECK: [[WEIGHT2]] = !{!"branch_weights", !"expected", i32 1, i32 2000}
Index: llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
@@ -352,5 +352,5 @@
 !llvm.ident = !{!0}
 
 !0 = !{!"clang version 5.0.0 (trunk 302965)"}
-; CHECK: [[WEIGHT]] = !{!"branch_weights", i32 2000, i32 1}
-; CHECK: [[WEIGHT2]] = !{!"branch_weights", i32 1, i32 2000}
+; CHECK: [[WEIGHT]] = !{!"branch_weights", !"expected", i32 2000, i32 1}
+; CHECK: [[WEIGHT2]] = !{!"branch_weights", !"expected", i32 1, i32 2000}
Index: llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
@@ -99,6 +99,6 @@
 
 !0 = !{i32 1, !"wchar_size", i32 4}
 !1 = !{!"clang version 5.0.0 (trunk 304373)"}
-; CHECK: [[LIKELY]] = !{!"branch_weights", i32 2000, i32 1}
-; CHECK: [[UNLIKELY]] = !{!"branch_weights", i32 1, i32 2000}
+; CHECK: [[LIKELY]] = !{!"branch_weights", !"expected", i32 2000, i32 1}
+; CHECK: [[UNLIKELY]] = !{!"branch_weights", !"expected", i32 1, i32 2000}
 
Index: llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
@@ -284,7 +284,7 @@
 
 declare i1 @llvm.expect.with.probability.i1(i1, i1, double) nounwind readnone
 
-; CHECK: !0 = !{!"branch_weights", i32 1717986918, i32 429496731}
-; CHECK: !1 = !{!"branch_weights", i32 429496731, i32 1717986918}
-; CHECK: !2 = !{!"branch_weights", i32 214748366, i32 214748366, i32 1717986918}
-; CHECK: !3 = !{!"branch_weights", i32 1717986918, i32 214748366, i32 214748366}
+; CHECK: !0 = !{!"branch_weights", !"expected", i32 1717986918, i32 429496731}
+; CHECK: !1 = !{!"branch_weights", !"expected", i32 429496731, i32 1717986918}
+; CHECK: !2 = !{!"branch_weights", 

[clang] bfe4514 - [amdgpuarch] Delete stray hsa #include line

2023-01-25 Thread Jon Chesterfield via cfe-commits

Author: Jon Chesterfield
Date: 2023-01-25T21:40:35Z
New Revision: bfe4514add5b7ab7e1f06248983a7162d734cffb

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

LOG: [amdgpuarch] Delete stray hsa #include line

Added: 


Modified: 
clang/tools/amdgpu-arch/AMDGPUArch.cpp

Removed: 




diff  --git a/clang/tools/amdgpu-arch/AMDGPUArch.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArch.cpp
index 2fdd398c9c673..fbb084a2a1231 100644
--- a/clang/tools/amdgpu-arch/AMDGPUArch.cpp
+++ b/clang/tools/amdgpu-arch/AMDGPUArch.cpp
@@ -75,7 +75,6 @@ llvm::Error loadHSA() {
 #elif __has_include("hsa.h")
 #include "hsa.h"
 #endif
-#include "hsa/hsa.h"
 #endif
 
 llvm::Error loadHSA() { return llvm::Error::success(); }



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


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D140250#4081102 , @rsmith wrote:

> Our builtin header `stddef.h` shouldn't be built as a module. It 
> fundamentally needs to be treated as a textual header, because it consumes 
> macros defined by the includer. The module map that we provide with our 
> builtin headers does not cover `stddef.h` for that reason.

That said... the ` __has_feature(modules)` checks throughout `stddef.h` look 
pretty wrong to me. They're probably working around the infelicities of the 
`-fno-modules-local-submodule-visibility` mode; maybe we can disable them when 
not in that mode?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D140250#4081009 , @iana wrote:

> In D140250#4080990 , @rsmith wrote:
>
>> Wait a second... if an OS wants only `NULL`, we already have a supported way 
>> of achieving that, which is compatible with GCC and glibc and other POSIX 
>> compilers -- define `__need_NULL` before including the header.
>>
>> We shouldn't be providing internal headers with `__mangled_names` for OSes 
>> to include, those should be implementation details.
>
> You can't do that with modules though, `#define __need_NULL #include 
> ` doesn't work.

Our builtin header `stddef.h` shouldn't be built as a module. It fundamentally 
needs to be treated as a textual header, because it consumers macros defined by 
the includer. The module map that we provide with our builtin headers does not 
cover `stddef.h` for that reason.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D139395: Add CFI integer types normalization

2023-01-25 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a reviewer: samitolvanen.
samitolvanen accepted this revision.
samitolvanen added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM. @pcc, does this version look fine to you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139395

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


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D140250#4081044 , @aaron.ballman 
wrote:

> In D140250#4081009 , @iana wrote:
>
>> In D140250#4080990 , @rsmith wrote:
>>
>>> Wait a second... if an OS wants only `NULL`, we already have a supported 
>>> way of achieving that, which is compatible with GCC and glibc and other 
>>> POSIX compilers -- define `__need_NULL` before including the header.
>>>
>>> We shouldn't be providing internal headers with `__mangled_names` for OSes 
>>> to include, those should be implementation details.
>>
>> You can't do that with modules though, `#define __need_NULL #include 
>> ` doesn't work.
>
> Also, from the patch summary: ` i.e. in POSIX headers that are required to 
> define NULL but not the rest of stddef.h.` -- I don't think `__need_NULL` 
> works for this because it gets you `NULL` but it also gets you the rest of 
> the stddef.h header, right?

Once you set one of the `__need` macros, then stddef.h will //only// give you 
those definitions. (Or I'm interpreting the file gravely wrong... it's kind of 
a weird header and its customizations don't really work with modules either.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D142578: [Clang][Doc] Edit the Clang release notes

2023-01-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added subscribers: s.egerton, mstorsjo, simoncook, dschuff.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, sstefan1, aheejin.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Do a large edit of the Clang release notes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142578

Files:
  clang/docs/ReleaseNotes.rst

Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -23,9 +23,9 @@
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
 general LLVM release notes, see `the LLVM
-documentation `_. All LLVM
-releases may be downloaded from the `LLVM releases web
-site `_.
+documentation `_. For the libc++ release notes,
+see `this page `_. All LLVM releases
+may be downloaded from the `LLVM releases web site `_.
 
 For more information about Clang or LLVM, including information about the
 latest release, please see the `Clang Web Site `_ or the
@@ -42,24 +42,18 @@
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
-- Clang will now correctly diagnose as ill-formed a constant expression where an
-  enum without a fixed underlying type is set to a value outside the range of
-  the enumeration's values.
-
-  .. code-block:: c++
+- Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of ``gnu++14``.
+  This means Clang will by default accept code using features from C++17 and
+  conforming GNU extensions. Projects incompatible with C++17 can add
+  ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 
-enum E { Zero, One, Two, Three, Four };
-constexpr E Val1 = (E)3;  // Ok
-constexpr E Val2 = (E)7;  // Ok
-constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
-constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]
+- The ``-fexperimental-new-pass-manager`` and ``-fno-legacy-pass-manager``
+  flags have been removed. These have been no-ops since 15.0.0.
 
-  Due to the extended period of time this bug was present in major C++
-  implementations (including Clang), this error has the ability to be
-  downgraded into a warning (via: ``-Wno-error=enum-constexpr-conversion``) to
-  provide a transition period for users. This diagnostic is expected to turn
-  into an error-only diagnostic in the next Clang release. Fixes
-  `Issue 50055 `_.
+- Clang's resource dir used to include the full clang version. It will now
+  include only the major version. The new resource directory is
+  ``$prefix/lib/clang/$CLANG_MAJOR_VERSION`` and can be queried using
+  ``clang -print-resource-dir``, just like before.
 
 - The ``-Wimplicit-function-declaration`` and ``-Wimplicit-int`` warnings
   now default to an error in C99, C11, and C17. As of C2x,
@@ -89,6 +83,14 @@
   void (*fp)(int *) = func; // Previously a warning, now a downgradable error.
 }
 
+- To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
+  ``__powerpc64__`` instead.
+
+- ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
+  to an ``-Wunused-command-line-argument`` warning in previous releases.
+
+C/C++ Language Potentially Breaking Changes
+---
 - Clang now disallows types whose sizes aren't a multiple of their alignments
   to be used as the element type of arrays.
 
@@ -99,7 +101,7 @@
 
 - When compiling for Windows in MSVC compatibility mode (for example by using
   clang-cl), the compiler will now propagate dllimport/export declspecs in
-  explicit specializations of class template member functions (`Issue 54717
+  explicit specializations of class template member functions (`#54717
   `_):
 
   .. code-block:: c++
@@ -143,8 +145,8 @@
 - Clang now diagnoses use of a bit-field as an instruction operand in Microsoft
   style inline asm blocks as an error. Previously, a bit-field operand yielded
   the address of the allocation unit the bit-field was stored within; reads or
-  writes therefore had the potential to read or write nearby bit-fields. This
-  change fixes `issue 57791 `_.
+  writes therefore had the potential to read or write nearby bit-fields.
+  (`#57791 `_)
 
   .. code-block:: c++
 
@@ -158,8 +160,35 @@
   }
 }
 
-- The ``-fexperimental-new-pass-manager`` and 

[PATCH] D139774: [libclang] Add API to set temporary directory location

2023-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D139774#4079249 , @vedgy wrote:

> Now that a consensus has been reached that this revision is to be discarded, 
> can we please resume the discussion of which alternative should be 
> implemented in the replacement revision?

Based on the discussion here, I think the preference is to modify 
`FileSystemOptions` to store an override for the temp directory, and updating 
APIs so that the temp directory can be specified by a new CIndex constructor 
function. (If anyone disagrees with that as the approach we'd like to take, 
please speak up!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139774

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


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D140250#4081009 , @iana wrote:

> In D140250#4080990 , @rsmith wrote:
>
>> Wait a second... if an OS wants only `NULL`, we already have a supported way 
>> of achieving that, which is compatible with GCC and glibc and other POSIX 
>> compilers -- define `__need_NULL` before including the header.
>>
>> We shouldn't be providing internal headers with `__mangled_names` for OSes 
>> to include, those should be implementation details.
>
> You can't do that with modules though, `#define __need_NULL #include 
> ` doesn't work.

Also, from the patch summary: ` i.e. in POSIX headers that are required to 
define NULL but not the rest of stddef.h.` -- I don't think `__need_NULL` works 
for this because it gets you `NULL` but it also gets you the rest of the 
stddef.h header, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[clang-tools-extra] 90f7db8 - Fix clang-tools-extra Sphinx build

2023-01-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-01-25T15:52:49-05:00
New Revision: 90f7db87936d967998f90c8b430e5243872223b3

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

LOG: Fix clang-tools-extra Sphinx build

This addresses the issue found in:
https://lab.llvm.org/buildbot/#/builders/115/builds/41077

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
index 80805bafddd5..8dc60464fe2f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
@@ -31,6 +31,7 @@ A call to ``clear()`` would appropriately clear the contents 
of the range:
   v.clear();
 
 Limitations:
-- Doesn't warn if ``empty()`` is defined and used with the ignore result in the
+
+* Doesn't warn if ``empty()`` is defined and used with the ignore result in the
   class template definition (for example in the library implementation). These
   error cases can be caught with ``[[nodiscard]]`` attribute.



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


[PATCH] D141375: [SYCL][OpenMP] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for the reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141375

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


[PATCH] D141375: [SYCL][OpenMP] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf81d529f8955: [Clang] Fix compilation errors for unsupported 
__bf16 intrinsics (authored by eandrews).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141375

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaSYCL/bf16.cpp


Index: clang/test/SemaSYCL/bf16.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu 
-fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type 
support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1518,9 +1518,10 @@
 break;
   case DeclSpec::TST_half:Result = Context.HalfTy; break;
   case DeclSpec::TST_BFloat16:
-if (!S.Context.getTargetInfo().hasBFloat16Type())
-  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
-<< "__bf16";
+if (!S.Context.getTargetInfo().hasBFloat16Type() &&
+!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
+!S.getLangOpts().SYCLIsDevice)
+  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
 Result = Context.BFloat16Ty;
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1975,6 +1975,8 @@
 (Ty->isIbm128Type() && !Context.getTargetInfo().hasIbm128Type()) ||
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Context.getTargetInfo().hasInt128Type()) ||
+(Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type() &&
+ !LangOpts.CUDAIsDevice) ||
 LongDoubleMismatched) {
   PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
   if (D)
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -3051,7 +3051,11 @@
 break;
   }
   case BuiltinType::BFloat16: {
-const TargetInfo *TI = ().getTargetInfo();
+const TargetInfo *TI = ((getASTContext().getLangOpts().OpenMP &&
+ getASTContext().getLangOpts().OpenMPIsDevice) ||
+getASTContext().getLangOpts().SYCLIsDevice)
+   ? getASTContext().getAuxTargetInfo()
+   : ().getTargetInfo();
 Out << TI->getBFloat16Mangling();
 break;
   }
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2140,6 +2140,11 @@
   if (Target->hasBFloat16Type()) {
 Width = Target->getBFloat16Width();
 Align = Target->getBFloat16Align();
+  } else if ((getLangOpts().SYCLIsDevice ||
+  (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)) &&
+ AuxTarget->hasBFloat16Type()) {
+Width = AuxTarget->getBFloat16Width();
+Align = AuxTarget->getBFloat16Align();
   }
   break;
 case BuiltinType::Float16:


Index: clang/test/SemaSYCL/bf16.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu -fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1518,9 +1518,10 @@
 break;
   case 

[clang] f81d529 - [Clang] Fix compilation errors for unsupported __bf16 intrinsics

2023-01-25 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-01-25T12:43:36-08:00
New Revision: f81d529f8955dbdf64d429c27dee994257b4ee99

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

LOG: [Clang] Fix compilation errors for unsupported __bf16 intrinsics

This patch uses existing deferred diagnostics framework to emit error
for unsupported type __bf16 in device code. Error is not emitted in
host code.

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

Added: 
clang/test/SemaSYCL/bf16.cpp

Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2884fe6604228..3ba8b90898b30 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2140,6 +2140,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
   if (Target->hasBFloat16Type()) {
 Width = Target->getBFloat16Width();
 Align = Target->getBFloat16Align();
+  } else if ((getLangOpts().SYCLIsDevice ||
+  (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)) &&
+ AuxTarget->hasBFloat16Type()) {
+Width = AuxTarget->getBFloat16Width();
+Align = AuxTarget->getBFloat16Align();
   }
   break;
 case BuiltinType::Float16:

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b23bc5f8d8816..88549c7344506 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3051,7 +3051,11 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 break;
   }
   case BuiltinType::BFloat16: {
-const TargetInfo *TI = ().getTargetInfo();
+const TargetInfo *TI = ((getASTContext().getLangOpts().OpenMP &&
+ getASTContext().getLangOpts().OpenMPIsDevice) ||
+getASTContext().getLangOpts().SYCLIsDevice)
+   ? getASTContext().getAuxTargetInfo()
+   : ().getTargetInfo();
 Out << TI->getBFloat16Mangling();
 break;
   }

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 0f03054224545..f983c477ac18e 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1975,6 +1975,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 (Ty->isIbm128Type() && !Context.getTargetInfo().hasIbm128Type()) ||
 (Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
  !Context.getTargetInfo().hasInt128Type()) ||
+(Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type() &&
+ !LangOpts.CUDAIsDevice) ||
 LongDoubleMismatched) {
   PartialDiagnostic PD = PDiag(diag::err_target_unsupported_type);
   if (D)

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 89d819a77dcbb..505b3b922d33d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1518,9 +1518,10 @@ static QualType 
ConvertDeclSpecToType(TypeProcessingState ) {
 break;
   case DeclSpec::TST_half:Result = Context.HalfTy; break;
   case DeclSpec::TST_BFloat16:
-if (!S.Context.getTargetInfo().hasBFloat16Type())
-  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
-<< "__bf16";
+if (!S.Context.getTargetInfo().hasBFloat16Type() &&
+!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
+!S.getLangOpts().SYCLIsDevice)
+  S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
 Result = Context.BFloat16Ty;
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;

diff  --git a/clang/test/SemaSYCL/bf16.cpp b/clang/test/SemaSYCL/bf16.cpp
new file mode 100644
index 0..06ae263fbcfe5
--- /dev/null
+++ b/clang/test/SemaSYCL/bf16.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu 
-fsycl-is-device -verify -fsyntax-only %s
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  kernelFunc(); // expected-note {{called by 'kernel}}
+}
+
+void host_ok(void) {
+  __bf16 A;
+}
+
+int main()
+{  host_ok();
+  __bf16 var; // expected-note {{'var' defined here}}
+  kernel([=]() {
+(void)var; // expected-error {{'var' requires 16 bit size '__bf16' type 
support, but target 'spir64' does not support it}}
+int B = sizeof(__bf16);
+  });
+
+  return 0;
+}
+



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


[PATCH] D141381: [codegen] Store address of indirect arguments on the stack

2023-01-25 Thread Felipe de Azevedo Piovezan via Phabricator via cfe-commits
fdeazeve added a comment.

https://reviews.llvm.org/D142160

Should address the incorrect handling of Mem2Reg, this is not the full picture 
though, as at the MIR level we handle these two differently:

  DEBUG_VALUE  !DIExpression ()  indirect// this what dbg.declare gets 
lowered to
  DEBUG_VALUE  !DIExpression (OP_deref)  // this is what dbg.value + 
deref gets lowered to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141381

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


[PATCH] D129951: adds `__disable_adl` attribute

2023-01-25 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:12934-12936
+// else if (!CandidateSet.empty() && 
CandidateSet.begin()->FoundDecl->hasAttr()) {
+//   return;
+// }

This and below need to be deleted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129951

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


[PATCH] D129951: adds `__disable_adl` attribute

2023-01-25 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 492234.
cjdb retitled this revision from "[clang] teaches Clang the special ADL rules 
for functions in std::ranges" to "adds `__disable_adl` attribute".
cjdb edited the summary of this revision.
cjdb added a comment.

- updates patch so that it meets what Aaron and I want, also meets most of 
Richard's feedback
- updates commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129951

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/disable-adl.cpp

Index: clang/test/SemaCXX/disable-adl.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/disable-adl.cpp
@@ -0,0 +1,179 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++2b
+
+namespace NS1 {
+  struct S1 {};
+  S1 inhibited(S1); // expected-note 2 {{candidate function}}
+
+  namespace NNS1 {
+struct S2 {};
+__disable_adl void hidden(S2);   // expected-note{{declared here}}
+__disable_adl int inhibited(S1); // expected-note 4 {{candidate function}}
+  }
+}
+
+namespace NS2 {
+  __disable_adl void inhibited(NS1::S1); // expected-note 2 {{candidate function}}
+}
+
+void test_functions() {
+  hidden(NS1::NNS1::S2{}); // expected-error{{use of undeclared identifier 'hidden'; did you mean 'NS1::NNS1::hidden'?}}
+  {
+NS1::S1 x = inhibited(NS1::S1{}); // no error
+  }
+  {
+using namespace NS1::NNS1;
+int x = inhibited(NS1::S1{}); // no error
+
+using namespace NS1;
+S1 y = inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+  {
+using NS1::NNS1::inhibited;
+int x = inhibited(NS1::S1{}); // no error
+
+using NS1::inhibited;
+NS1::S1 y = inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+  {
+using namespace NS2;
+inhibited(NS1::S1{}); // no error
+
+using namespace NS1::NNS1;
+inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+  {
+using NS2::inhibited;
+inhibited(NS1::S1{}); // no error
+
+using NS1::NNS1::inhibited;
+inhibited(NS1::S1{}); // expected-error{{call to 'inhibited' is ambiguous}}
+  }
+}
+
+namespace NS1 {
+  template
+  S1 inhibited_template(T); // expected-note 2 {{candidate function}}
+
+  namespace NNS1 {
+template
+__disable_adl void hidden_template(T); // expected-note{{declared here}}
+
+template
+__disable_adl int inhibited_template(T); // expected-note 4 {{candidate function}}
+  }
+}
+
+namespace NS2 {
+  template
+  __disable_adl int inhibited_template(T); // expected-note 2 {{candidate function}}
+}
+
+void test_function_templates() {
+  hidden_template(NS1::NNS1::S2{}); // expected-error{{use of undeclared identifier 'hidden_template'; did you mean 'NS1::NNS1::hidden_template'?}}
+
+  {
+NS1::S1 x = inhibited_template(NS1::S1{}); // no error
+  }
+  {
+using namespace NS1::NNS1;
+int x = inhibited_template(NS1::S1{}); // no error
+
+using namespace NS1;
+S1 y = inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+  {
+using NS1::NNS1::inhibited_template;
+int x = inhibited_template(NS1::S1{}); // no error
+
+using NS1::inhibited_template;
+NS1::S1 y = inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+  {
+using namespace NS2;
+inhibited_template(NS1::S1{}); // no error
+
+using namespace NS1::NNS1;
+inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+  {
+using NS2::inhibited_template;
+inhibited_template(NS1::S1{}); // no error
+
+using NS1::NNS1::inhibited_template;
+inhibited_template(NS1::S1{}); // expected-error{{call to 'inhibited_template' is ambiguous}}
+  }
+}
+
+namespace NS1 {
+  S1 inhibited_mixed(S1);
+
+  namespace NNS1 {
+template
+__disable_adl int inhibited_mixed(T);
+  }
+}
+
+void test_mixed() {
+  using namespace NS1::NNS1;
+  int x = inhibited_mixed(NS1::S1{}); // no error
+}
+
+// Should be covered by the hidden functions checks, but just to be sure.
+void test_NNS1_hidden() {
+  {
+NS1::S1 a = inhibited(NS1::S1{});
+NS1::S1 b = inhibited_template(NS1::S1{});
+NS1::S1 c = inhibited_mixed(NS1::S1{});
+  }
+  {
+using namespace NS1;
+NS1::S1 a = inhibited(NS1::S1{});
+NS1::S1 b = inhibited_template(NS1::S1{});
+NS1::S1 c = inhibited_mixed(NS1::S1{});
+  }
+}
+
+namespace NS1 {
+  namespace NNS1 {
+__disable_adl void operator-(S2); // 

[PATCH] D137753: [Clang][AIX][p]Enable -p Functionality

2023-01-25 Thread David Tenty via Phabricator via cfe-commits
daltenty accepted this revision.
daltenty added a comment.
This revision is now accepted and ready to land.

LGTM, with small nit to address before commit




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6287-6292
 if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) {
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
+if (TC.getTriple().isOSAIX())
+  CmdArgs.push_back("-pg");

nit: we can save our selves a query and clarify by writing this as if-elseif


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137753

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


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D140250#4080990 , @rsmith wrote:

> Wait a second... if an OS wants only `NULL`, we already have a supported way 
> of achieving that, which is compatible with GCC and glibc and other POSIX 
> compilers -- define `__need_NULL` before including the header.
>
> We shouldn't be providing internal headers with `__mangled_names` for OSes to 
> include, those should be implementation details.

You can't do that with modules though, `#define __need_NULL #include 
` doesn't work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Wait a second... if an OS wants only `NULL`, we already have a supported way of 
achieving that, which is compatible with GCC and glibc and other POSIX 
compilers -- define `__need_NULL` before including the header.

We shouldn't be providing internal headers with `__mangled_names` for OSes to 
include, those should be implementation details.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D142577: [clang-doc] Removed unused method in the Info class

2023-01-25 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth created this revision.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142577

Files:
  clang-tools-extra/clang-doc/Representation.h


Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -290,10 +290,6 @@
 
   /// Returns the basename that should be used for this Info.
   llvm::SmallString<16> getFileBaseName() const;
-
-  // Returns a reference to the parent scope (that is, the immediate parent
-  // namespace or class in which this decl resides).
-  llvm::Expected getEnclosingScope();
 };
 
 // Info for namespaces.


Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -290,10 +290,6 @@
 
   /// Returns the basename that should be used for this Info.
   llvm::SmallString<16> getFileBaseName() const;
-
-  // Returns a reference to the parent scope (that is, the immediate parent
-  // namespace or class in which this decl resides).
-  llvm::Expected getEnclosingScope();
 };
 
 // Info for namespaces.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Please be sure to add a release note when landing the changes, btw.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D140250: Define NULL in its own header

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140250

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


[PATCH] D142423: [clang-tidy] Fix segfault in bugprone-standalone-empty

2023-01-25 Thread Christopher Di Bella via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG716469b6139a: [clang-tidy] Fix segfault in 
bugprone-standalone-empty (authored by denik, committed by cjdb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142423

Files:
  clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
@@ -80,6 +80,10 @@
 void empty(T &&);
 } // namespace test
 
+namespace test_no_args {
+bool empty();
+} // namespace test_no_args
+
 namespace base {
 template 
 struct base_vector {
@@ -306,6 +310,9 @@
 
 test::empty(v);
 // no-warning
+
+test_no_args::empty();
+// no-warning
   }
 
   {
@@ -876,3 +883,24 @@
 // no-warning
   }
 }
+
+namespace user_lib {
+template 
+struct vector {
+  bool empty();
+  bool test_empty_inside_impl() {
+empty();
+// no-warning
+return empty();
+// no-warning
+  }
+};
+} // namespace user_lib
+
+bool test_template_empty_outside_impl() {
+  user_lib::vector v;
+  v.empty();
+  // CHECK-MESSAGES: :[[#@LINE-1]]:3: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+  return v.empty();
+  // no-warning
+}
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
@@ -3,8 +3,8 @@
 bugprone-standalone-empty
 =
 
-Warns when `empty()` is used on a range and the result is ignored. Suggests 
-`clear()` if it is an existing member function.
+Warns when ``empty()`` is used on a range and the result is ignored. Suggests
+``clear()`` if it is an existing member function.
 
 The ``empty()`` method on several common ranges returns a Boolean indicating
 whether or not the range is empty, but is often mistakenly interpreted as
@@ -29,3 +29,8 @@
   std::vector v;
   ...
   v.clear();
+
+Limitations:
+- Doesn't warn if ``empty()`` is defined and used with the ignore result in the
+  class template definition (for example in the library implementation). These
+  error cases can be caught with ``[[nodiscard]]`` attribute.
Index: clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
@@ -29,10 +29,12 @@
 using ast_matchers::BoundNodes;
 using ast_matchers::callee;
 using ast_matchers::callExpr;
+using ast_matchers::classTemplateDecl;
 using ast_matchers::cxxMemberCallExpr;
 using ast_matchers::cxxMethodDecl;
 using ast_matchers::expr;
 using ast_matchers::functionDecl;
+using ast_matchers::hasAncestor;
 using ast_matchers::hasName;
 using ast_matchers::hasParent;
 using ast_matchers::ignoringImplicit;
@@ -70,10 +72,13 @@
 }
 
 void StandaloneEmptyCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
+  // Ignore empty calls in a template definition which fall under callExpr
+  // non-member matcher even if they are methods.
   const auto NonMemberMatcher = expr(ignoringImplicit(ignoringParenImpCasts(
   callExpr(
   hasParent(stmt(optionally(hasParent(stmtExpr().bind("stexpr"
 .bind("parent")),
+  unless(hasAncestor(classTemplateDecl())),
   callee(functionDecl(hasName("empty"), unless(returns(voidType())
   .bind("empty";
   const auto MemberMatcher =
@@ -154,6 +159,8 @@
   return;
 if (ParentReturnStmt)
   return;
+if (NonMemberCall->getNumArgs() != 1)
+  return;
 
 SourceLocation NonMemberLoc = NonMemberCall->getExprLoc();
 SourceLocation NonMemberEndLoc = NonMemberCall->getEndLoc();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 716469b - [clang-tidy] Fix segfault in bugprone-standalone-empty

2023-01-25 Thread Christopher Di Bella via cfe-commits

Author: Denis Nikitin
Date: 2023-01-25T20:06:41Z
New Revision: 716469b6139ab5ec5c5b5dac32891300260db8eb

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

LOG: [clang-tidy] Fix segfault in bugprone-standalone-empty

The check incorrectly identified empty() method call in the template
class definition as a stand-alone function call.
This led to a crash because the checker did not expect empty() function
calls without arguments.

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

Reviewed By: cjdb

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
index 67d8e3693fb56..a66f838f1c8fa 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
@@ -29,10 +29,12 @@ namespace clang::tidy::bugprone {
 using ast_matchers::BoundNodes;
 using ast_matchers::callee;
 using ast_matchers::callExpr;
+using ast_matchers::classTemplateDecl;
 using ast_matchers::cxxMemberCallExpr;
 using ast_matchers::cxxMethodDecl;
 using ast_matchers::expr;
 using ast_matchers::functionDecl;
+using ast_matchers::hasAncestor;
 using ast_matchers::hasName;
 using ast_matchers::hasParent;
 using ast_matchers::ignoringImplicit;
@@ -70,10 +72,13 @@ const Expr *getCondition(const BoundNodes , const 
StringRef NodeId) {
 }
 
 void StandaloneEmptyCheck::registerMatchers(ast_matchers::MatchFinder *Finder) 
{
+  // Ignore empty calls in a template definition which fall under callExpr
+  // non-member matcher even if they are methods.
   const auto NonMemberMatcher = expr(ignoringImplicit(ignoringParenImpCasts(
   callExpr(
   hasParent(stmt(optionally(hasParent(stmtExpr().bind("stexpr"
 .bind("parent")),
+  unless(hasAncestor(classTemplateDecl())),
   callee(functionDecl(hasName("empty"), unless(returns(voidType())
   .bind("empty";
   const auto MemberMatcher =
@@ -154,6 +159,8 @@ void StandaloneEmptyCheck::check(const 
MatchFinder::MatchResult ) {
   return;
 if (ParentReturnStmt)
   return;
+if (NonMemberCall->getNumArgs() != 1)
+  return;
 
 SourceLocation NonMemberLoc = NonMemberCall->getExprLoc();
 SourceLocation NonMemberEndLoc = NonMemberCall->getEndLoc();

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
index 049698a8b0f7a..80805bafddd50 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
@@ -3,8 +3,8 @@
 bugprone-standalone-empty
 =
 
-Warns when `empty()` is used on a range and the result is ignored. Suggests 
-`clear()` if it is an existing member function.
+Warns when ``empty()`` is used on a range and the result is ignored. Suggests
+``clear()`` if it is an existing member function.
 
 The ``empty()`` method on several common ranges returns a Boolean indicating
 whether or not the range is empty, but is often mistakenly interpreted as
@@ -29,3 +29,8 @@ A call to ``clear()`` would appropriately clear the contents 
of the range:
   std::vector v;
   ...
   v.clear();
+
+Limitations:
+- Doesn't warn if ``empty()`` is defined and used with the ignore result in the
+  class template definition (for example in the library implementation). These
+  error cases can be caught with ``[[nodiscard]]`` attribute.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
index d7615fdbbe922..53c651879f84b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
@@ -80,6 +80,10 @@ template 
 void empty(T &&);
 } // namespace test
 
+namespace test_no_args {
+bool empty();
+} // namespace test_no_args
+
 namespace base {
 template 
 struct base_vector {
@@ -306,6 +310,9 @@ bool test_qualified_empty() {
 
 test::empty(v);
 // no-warning
+
+test_no_args::empty();
+// no-warning
   }
 
   {
@@ -876,3 +883,24 @@ bool test_clear_with_qualifiers() {
 // no-warning
   }
 }
+
+namespace user_lib {
+template 
+struct vector {
+  bool empty();
+  bool test_empty_inside_impl() {
+   

[PATCH] D142569: [WIP][OpenMP] Introduce kernel argument

2023-01-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Link the old review too. Pre-commit, w/o review, the file rename and include 
changes.




Comment at: llvm/lib/Transforms/IPO/OpenMPOpt.cpp:246
+  GET_KERNEL_ENVIRONMENT_MEMBER(Configuration, DL, StructC)),  
\
+  V))
+

Do we need the offset parts? I think we should only work with field numbers not 
offsets.



Comment at: openmp/libomptarget/DeviceRTL/include/Configuration.h:19
 
+#pragma omp begin declare target device_type(nohost)
+

Precommit.



Comment at: openmp/libomptarget/DeviceRTL/include/Configuration.h:24
 
+extern ConfigurationEnvironmentTy *ConfigurationEnvironment;
+

Unused for now.



Comment at: openmp/libomptarget/DeviceRTL/src/Configuration.cpp:26
 extern uint32_t __omp_rtl_assume_no_thread_state;
-extern uint32_t __omp_rtl_assume_no_nested_parallelism;
 

Keep it for now. Makes the transition easier. Use an `||` below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


[PATCH] D135495: [clang-tidy] handle exceptions properly `ExceptionAnalyzer`

2023-01-25 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs updated this revision to Diff 492215.

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

https://reviews.llvm.org/D135495

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

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -101,6 +101,126 @@
   }
 }
 
+void throw_catch_pointer_c() noexcept {
+  try {
+int a = 1;
+throw 
+  } catch(const int *) {}
+}
+
+void throw_catch_pointer_v() noexcept {
+  try {
+int a = 1;
+throw 
+  } catch(volatile int *) {}
+}
+
+void throw_catch_pointer_cv() noexcept {
+  try {
+int a = 1;
+throw 
+  } catch(const volatile int *) {}
+}
+
+void throw_catch_multi_ptr_1() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_multi_ptr_1' which should not throw exceptions
+  try {
+char **p = 0;
+throw p;
+  } catch (const char **) {
+  }
+}
+
+void throw_catch_multi_ptr_2() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (const char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_3() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_4() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile const char *const *) {
+  }
+}
+
+// FIXME: In this case 'a' is convertible to the handler and should be caught
+// but in reality it's thrown. Note that clang doesn't report a warning for 
+// this either.
+void throw_catch_multi_ptr_5() noexcept {
+  try {
+double *a[2][3];
+throw a;
+  } catch (double *(*)[3]) {
+  }
+}
+
+
+void throw_c_catch_pointer() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer' which should not throw exceptions
+  try {
+int a = 1;
+const int *p = 
+throw p;
+  } catch(int *) {}
+}
+
+void throw_c_catch_pointer_v() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer_v' which should not throw exceptions
+  try {
+int a = 1;
+const int *p = 
+throw p;
+  } catch(volatile int *) {}
+}
+
+void throw_v_catch_pointer() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_v_catch_pointer' which should not throw exceptions
+  try {
+int a = 1;
+volatile int *p = 
+throw p;
+  } catch(int *) {}
+}
+
+void throw_v_catch_pointer_c() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_v_catch_pointer_c' which should not throw exceptions
+  try {
+int a = 1;
+volatile int *p = 
+throw p;
+  } catch(const int *) {}
+}
+
+void throw_cv_catch_pointer_c() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_cv_catch_pointer_c' which should not throw exceptions
+  try {
+int a = 1;
+const volatile int *p = 
+throw p;
+  } catch(const int *) {}
+}
+
+void throw_cv_catch_pointer_v() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_cv_catch_pointer_v' which should not throw exceptions
+  try {
+int a = 1;
+const volatile int *p = 
+throw p;
+  } catch(volatile int *) {}
+}
+
 class base {};
 class derived: public base {};
 
@@ -112,6 +232,84 @@
   }
 }
 
+void throw_derived_catch_base_ptr_c() noexcept {
+  try {
+derived d;
+throw  
+  } catch(const base *) {
+  }
+}
+
+void throw_derived_catch_base_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ptr' which should not throw exceptions
+  try {
+derived d;
+const derived *p = 
+throw p; 
+  } catch(base *) {
+  }
+}
+
+class A {};
+class B : A {};
+class C : protected A {};
+class D : public A {};
+class E : public A, public D {};
+
+void throw_derived_catch_base_private() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
+  try {
+B b;
+throw b; 
+  } catch(A) {
+  }
+}
+
+void throw_derived_catch_base_private_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private_ptr' which should not throw exceptions
+  try {
+B b;
+throw  
+  } catch(A *) {
+  }
+}
+
+void throw_derived_catch_base_protected() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 

[PATCH] D135495: [clang-tidy] handle exceptions properly `ExceptionAnalyzer`

2023-01-25 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs updated this revision to Diff 492214.
isuckatcs added a comment.

applied clang-format


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

https://reviews.llvm.org/D135495

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

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -102,7 +102,6 @@
 }
 
 void throw_catch_pointer_c() noexcept {
-  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_pointer_c' which should not throw exceptions
   try {
 int a = 1;
 throw 
@@ -110,7 +109,6 @@
 }
 
 void throw_catch_pointer_v() noexcept {
-  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_pointer_v' which should not throw exceptions
   try {
 int a = 1;
 throw 
@@ -118,13 +116,57 @@
 }
 
 void throw_catch_pointer_cv() noexcept {
-  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_pointer_cv' which should not throw exceptions
   try {
 int a = 1;
 throw 
   } catch(const volatile int *) {}
 }
 
+void throw_catch_multi_ptr_1() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_multi_ptr_1' which should not throw exceptions
+  try {
+char **p = 0;
+throw p;
+  } catch (const char **) {
+  }
+}
+
+void throw_catch_multi_ptr_2() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (const char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_3() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_4() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile const char *const *) {
+  }
+}
+
+// FIXME: In this case 'a' is convertible to the handler and should be caught
+// but in reality it's thrown. Note that clang doesn't report a warning for 
+// this either.
+void throw_catch_multi_ptr_5() noexcept {
+  try {
+double *a[2][3];
+throw a;
+  } catch (double *(*)[3]) {
+  }
+}
+
+
 void throw_c_catch_pointer() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer' which should not throw exceptions
   try {
@@ -191,7 +233,6 @@
 }
 
 void throw_derived_catch_base_ptr_c() noexcept {
-  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ptr_c' which should not throw exceptions
   try {
 derived d;
 throw  
@@ -209,6 +250,66 @@
   }
 }
 
+class A {};
+class B : A {};
+class C : protected A {};
+class D : public A {};
+class E : public A, public D {};
+
+void throw_derived_catch_base_private() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
+  try {
+B b;
+throw b; 
+  } catch(A) {
+  }
+}
+
+void throw_derived_catch_base_private_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private_ptr' which should not throw exceptions
+  try {
+B b;
+throw  
+  } catch(A *) {
+  }
+}
+
+void throw_derived_catch_base_protected() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected' which should not throw exceptions
+  try {
+C c;
+throw c; 
+  } catch(A) {
+  }
+}
+
+void throw_derived_catch_base_protected_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected_ptr' which should not throw exceptions
+  try {
+C c;
+throw  
+  } catch(A *) {
+  }
+}
+
+void throw_derived_catch_base_ambiguous() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous' which should not throw exceptions
+  try {
+E e;
+throw e; 
+  } catch(A) {
+  }
+}
+
+void throw_derived_catch_base_ambiguous_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous_ptr' which should not throw exceptions
+  try {
+E e;
+throw e; 
+  } catch(A) {
+  }
+}
+
 void try_nested_try(int n) noexcept {
   // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'try_nested_try' which should not throw exceptions
   try {
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h

[PATCH] D142570: [nvptx-arch] Remove `find_package(CUDA)` as it has been deprecated.

2023-01-25 Thread Joseph Huber 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 rG759dec253695: [nvptx-arch] Remove `find_package(CUDA)` as it 
has been deprecated. (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142570

Files:
  clang/tools/nvptx-arch/CMakeLists.txt


Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- clang/tools/nvptx-arch/CMakeLists.txt
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -9,18 +9,11 @@
 set(LLVM_LINK_COMPONENTS Support)
 add_clang_tool(nvptx-arch NVPTXArch.cpp)
 
-# TODO: This is deprecated. Since CMake 3.17 we can use FindCUDAToolkit 
instead.
-find_package(CUDA QUIET)
-find_library(cuda-library NAMES cuda PATHS /lib64)
-if (NOT cuda-library AND CUDA_FOUND)
-  get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
-  find_library(cuda-library NAMES cuda HINTS "${CUDA_LIBDIR}/stubs")
-endif()
+find_package(CUDAToolkit QUIET)
 
 # If we found the CUDA library directly we just dynamically link against it.
-if (CUDA_FOUND AND cuda-library)
-  target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
-  target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
+if (CUDAToolkit_FOUND)
+  target_link_libraries(nvptx-arch PRIVATE CUDA::cuda_driver)
 else()
   target_compile_definitions(nvptx-arch PRIVATE "DYNAMIC_CUDA")
 endif()


Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- clang/tools/nvptx-arch/CMakeLists.txt
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -9,18 +9,11 @@
 set(LLVM_LINK_COMPONENTS Support)
 add_clang_tool(nvptx-arch NVPTXArch.cpp)
 
-# TODO: This is deprecated. Since CMake 3.17 we can use FindCUDAToolkit instead.
-find_package(CUDA QUIET)
-find_library(cuda-library NAMES cuda PATHS /lib64)
-if (NOT cuda-library AND CUDA_FOUND)
-  get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
-  find_library(cuda-library NAMES cuda HINTS "${CUDA_LIBDIR}/stubs")
-endif()
+find_package(CUDAToolkit QUIET)
 
 # If we found the CUDA library directly we just dynamically link against it.
-if (CUDA_FOUND AND cuda-library)
-  target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
-  target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
+if (CUDAToolkit_FOUND)
+  target_link_libraries(nvptx-arch PRIVATE CUDA::cuda_driver)
 else()
   target_compile_definitions(nvptx-arch PRIVATE "DYNAMIC_CUDA")
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >