[llvm-branch-commits] [llvm] Bump version to 18.1.7 (PR #93723)

2024-06-03 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/93723
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 1ce2d26 - Bump version to 18.1.7 (#93723)

2024-06-03 Thread via llvm-branch-commits

Author: Tom Stellard
Date: 2024-06-03T17:50:36-07:00
New Revision: 1ce2d26cd2e912bb168e78ccc049b70a81dab03a

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

LOG: Bump version to 18.1.7 (#93723)

Added: 


Modified: 
llvm/CMakeLists.txt
llvm/utils/lit/lit/__init__.py

Removed: 




diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 26b7b01bb1f8d..51278943847aa 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -22,7 +22,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
   set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
-  set(LLVM_VERSION_PATCH 6)
+  set(LLVM_VERSION_PATCH 7)
 endif()
 if(NOT DEFINED LLVM_VERSION_SUFFIX)
   set(LLVM_VERSION_SUFFIX)

diff  --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py
index d8b0e3bd1c69e..5003d78ce5218 100644
--- a/llvm/utils/lit/lit/__init__.py
+++ b/llvm/utils/lit/lit/__init__.py
@@ -2,7 +2,7 @@
 
 __author__ = "Daniel Dunbar"
 __email__ = "dan...@minormatter.com"
-__versioninfo__ = (18, 1, 6)
+__versioninfo__ = (18, 1, 7)
 __version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
 
 __all__ = []



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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits


@@ -557,6 +557,36 @@
 ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
 prefetch  [ %i1 + %i2 ], #one_read
 
+! V8:  error: malformed ASI tag, must be a constant integer 
expression

s-barannikov wrote:

With the above suggestion it should now yield an "unexpected token" error.
If you wish to get "unavailable in V8" error, you need to pass 
ParseForAllFeatures == true to MatchOperandParserImpl so that parsePrefetchTag 
is called in V8 mode too. This will probably result in many test changes and 
should be done separately.


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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits


@@ -557,6 +557,36 @@
 ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
 prefetch  [ %i1 + %i2 ], #one_read
 
+! V8:  error: malformed ASI tag, must be a constant integer 
expression

s-barannikov wrote:

It is because parseAbsoluteExpression fails. When it fails, we're no longer 
allowed to return NoMatch as the method consumes tokens. It should not be 
called at all if the tokens to be parsed do not look like an expression.
I can suggest two ways to overcome this:
* Restrict numerical tags to be integer literals and do not use 
parseAbsoluteExpression. I recall you saying that the numerical tag can indeed 
be an expression, so this might not be the way to go.
* Check that the next token can be a start of an expression before calling 
parseAbsoluteExpression. Those should be Identifier, Integer, Plus, Minus, 
LParen, and possibly Tilde and Exclaim. Such kind of check is performed in, 
e.g., parseCallTarget and parseSparcAsmOperand.


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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread via llvm-branch-commits


@@ -557,6 +557,36 @@
 ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
 prefetch  [ %i1 + %i2 ], #one_read
 
+! V8:  error: malformed ASI tag, must be a constant integer 
expression

koachan wrote:

Changing them to return a NoMatch results in the error changing into `unknown 
token in expression`, but still doesn't catch that `prefetcha` is unavailable 
in V8...

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


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits


@@ -1088,6 +1115,34 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector 
) {
   return ParseStatus::Success;
 }
 
+ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector ) {
+  SMLoc S = Parser.getTok().getLoc();
+  SMLoc E = Parser.getTok().getEndLoc();
+  int64_t PrefetchVal = 0;
+
+  if (getLexer().getKind() == AsmToken::Hash) {
+SMLoc TagStart = getLexer().peekTok(false).getLoc();
+Parser.Lex(); // Eat the '#'.
+auto PrefetchName = Parser.getTok().getString();
+auto PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);

s-barannikov wrote:

Yes, please. This will make clang-tidy a little bit happier.


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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Eli Friedman via llvm-branch-commits


@@ -354,6 +354,23 @@ Given that ``signedPointer`` matches the layout for signed 
pointers signed with
 the given key, extract the raw pointer from it.  This operation does not trap
 and cannot fail, even if the pointer is not validly signed.
 
+``ptrauth_sign_constant``
+^
+
+.. code-block:: c
+
+  ptrauth_sign_constant(pointer, key, discriminator)
+
+Return a signed pointer for a constant address in a manner which guarantees
+a non-attackable sequence.
+
+``pointer`` must be a constant expression of pointer type which evaluates to
+a non-null pointer.  The result will have the same type as ``discriminator``.
+
+Calls to this are constant expressions if the discriminator is a null-pointer
+constant expression or an integer constant expression. Implementations may
+allow other pointer expressions as well.

efriedma-quic wrote:

This seems to imply that if you don't need a constant expression, the 
discriminator can be a variable.  This doesn't seem to match the 
implementation, though: it requires a constant discriminator in a specific form.

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


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread via llvm-branch-commits


@@ -1088,6 +1115,34 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector 
) {
   return ParseStatus::Success;
 }
 
+ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector ) {
+  SMLoc S = Parser.getTok().getLoc();
+  SMLoc E = Parser.getTok().getEndLoc();
+  int64_t PrefetchVal = 0;
+
+  if (getLexer().getKind() == AsmToken::Hash) {
+SMLoc TagStart = getLexer().peekTok(false).getLoc();
+Parser.Lex(); // Eat the '#'.
+auto PrefetchName = Parser.getTok().getString();
+auto PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);

koachan wrote:

Here I am following the code from the [ASI tag 
handling](https://github.com/llvm/llvm-project/pull/94249/files/2b16c922835eda4759b3372da362293efcc9c0f4#diff-e6d91775e25820bb2665f18e0bf771e71fd8351ae05a8895d25b9b43007a0c4eR1093-R1094)
Should I change it?

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Ahmed Bougacha via llvm-branch-commits


@@ -2126,14 +2219,16 @@ static ExprResult PointerAuthSignGenericData(Sema , 
CallExpr *Call) {
 }
 
 static ExprResult PointerAuthSignOrAuth(Sema , CallExpr *Call,
-PointerAuthOpKind OpKind) {
+PointerAuthOpKind OpKind,
+bool RequireConstant) {
   if (S.checkArgCount(Call, 3))
 return ExprError();
   if (checkPointerAuthEnabled(S, Call))
 return ExprError();
-  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind) ||
+  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind, RequireConstant) ||

ahmedbougacha wrote:

This one is actually interesting: we can't do that as-is, because the helper 
functions take an `Expr *&`, to do type conversion and placeholder expansion 
in-place;  see e.g., `convertArgumentToType`.
Another existing user makes the modification explicit using a local and 
`setArg`, but we have a lot of these calls in the checking code here.

We can rename the helper to something explicit though, perhaps 
`checkAndConvertPointerAuthValue`, and pass the call expr and arg index 
separately (same for key etc.)

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93904

>From 1a23a99f23714ba6a83b354e3b9afd056b263a02 Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Thu, 30 May 2024 17:33:04 -0700
Subject: [PATCH 1/3] [clang] Define ptrauth_sign_constant builtin.

This is constant-expression equivalent to __builtin_ptrauth_sign,
allowing its usage in global initializers, but requiring constant
pointers and discriminators.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/CodeGen/CodeGenABITypes.h |   6 +
 clang/lib/AST/ExprConstant.cpp|   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |   3 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  62 +
 clang/lib/CodeGen/CGPointerAuth.cpp   |  77 +++
 clang/lib/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/lib/Headers/ptrauth.h   |  25 
 clang/lib/Sema/SemaChecking.cpp   | 128 --
 .../CodeGen/ptrauth-intrinsic-sign-constant.c |  20 +++
 clang/test/Sema/ptrauth-intrinsics-macro.c|   4 +
 clang/test/Sema/ptrauth.c |  29 
 14 files changed, 360 insertions(+), 14 deletions(-)
 create mode 100644 clang/lib/CodeGen/CGPointerAuth.cpp
 create mode 100644 clang/test/CodeGen/ptrauth-intrinsic-sign-constant.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 836697632a3bc..557b70172fc08 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4393,6 +4393,12 @@ def PtrauthSignUnauthenticated : Builtin {
   let Prototype = "void*(void*,int,void*)";
 }
 
+def PtrauthSignConstant : Builtin {
+  let Spellings = ["__builtin_ptrauth_sign_constant"];
+  let Attributes = [CustomTypeChecking, NoThrow, Const, Constexpr];
+  let Prototype = "void*(void*,int,void*)";
+}
+
 def PtrauthSignGenericData : Builtin {
   let Spellings = ["__builtin_ptrauth_sign_generic_data"];
   let Attributes = [CustomTypeChecking, NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64add46248c69..753e775ce0968 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -922,6 +922,13 @@ def err_ptrauth_value_bad_type :
   Error<"%select{signed value|extra discriminator|blended pointer|blended "
 "integer}0 must have %select{pointer|integer|pointer or integer}1 "
 "type; type here is %2">;
+def err_ptrauth_bad_constant_pointer :
+  Error<"argument to ptrauth_sign_constant must refer to a global variable "
+"or function">;
+def err_ptrauth_bad_constant_discriminator :
+  Error<"discriminator argument to ptrauth_sign_constant must be a constant "
+"integer, the address of the global variable where the result "
+"will be stored, or a blend of the two">;
 def warn_ptrauth_sign_null_pointer :
   Warning<"signing a null pointer will yield a non-null pointer">,
   InGroup;
diff --git a/clang/include/clang/CodeGen/CodeGenABITypes.h 
b/clang/include/clang/CodeGen/CodeGenABITypes.h
index fda0855dc8683..8c62d8597ecbe 100644
--- a/clang/include/clang/CodeGen/CodeGenABITypes.h
+++ b/clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -104,6 +104,12 @@ llvm::Type *convertTypeForMemory(CodeGenModule , 
QualType T);
 unsigned getLLVMFieldNumber(CodeGenModule ,
 const RecordDecl *RD, const FieldDecl *FD);
 
+/// Return a signed constant pointer.
+llvm::Constant *getConstantSignedPointer(CodeGenModule ,
+ llvm::Constant *pointer,
+ unsigned key,
+ llvm::Constant *storageAddress,
+ llvm::Constant *otherDiscriminator);
 /// Given the language and code-generation options that Clang was configured
 /// with, set the default LLVM IR attributes for a function definition.
 /// The attributes set here are mostly global target-configuration and
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index eafecfb5fe5b1..b1cb3c323074b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2042,6 +2042,7 @@ static bool IsNoOpCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+  Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
   Builtin == Builtin::BI__builtin_function_start);
 }
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a3c6510503324..b2e3b6fa64284 100644
--- 

[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Ahmed Bougacha via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {

ahmedbougacha wrote:

Clang originally had different conventions;  it usually gets (has gotten) 
updated over time for older code, I suppose now's the time for these changes.

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93903

>From 61be7a922397d66773a8f4a6e476ea321f52f00c Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Thu, 30 May 2024 17:22:29 -0700
Subject: [PATCH 1/4] [clang] Define ptrauth_string_discriminator builtin.

This exposes the ABI-stable hash function that allows computing a 16-bit
discriminator from a constant string.

This allows manually matching the implicit string discriminators
computed in the ABI (e.g., from mangled names for vtable pointer/entry
signing), as well as enabling the use of interesting discriminators when
manually annotating specific pointers with the __ptrauth qualifier.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/Builtins.td |  6 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/AST/ExprConstant.cpp|  7 +++
 clang/lib/Headers/ptrauth.h   | 17 
 clang/lib/Sema/SemaChecking.cpp   | 20 +++
 clang/test/CodeGen/ptrauth-intrinsics.c   | 13 
 clang/test/Sema/ptrauth-intrinsics-macro.c|  5 +
 7 files changed, 70 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 11982af3fa609..836697632a3bc 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4411,6 +4411,12 @@ def PtrauthAuth : Builtin {
   let Prototype = "void*(void*,int,void*)";
 }
 
+def PtrauthStringDiscriminator : Builtin {
+  let Spellings = ["__builtin_ptrauth_string_discriminator"];
+  let Attributes = [NoThrow, Const, Constexpr];
+  let Prototype = "size_t(char const*)";
+}
+
 // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
 // We need the generic prototype, since the packet type could be anything.
 def ReadPipe : OCLPipeLangBuiltin {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f15cba63624ea..64add46248c69 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -928,6 +928,8 @@ def warn_ptrauth_sign_null_pointer :
 def warn_ptrauth_auth_null_pointer :
   Warning<"authenticating a null pointer will almost certainly trap">,
   InGroup;
+def err_ptrauth_string_not_literal : Error<
+  "argument must be a string literal%select{| of char type}0">;
 
 /// main()
 // static main() is not an error in C, just in C++.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..eafecfb5fe5b1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -58,6 +58,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
+#include "llvm/Support/SipHash.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -12583,6 +12584,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_expect_with_probability:
 return Visit(E->getArg(0));
 
+  case Builtin::BI__builtin_ptrauth_string_discriminator: {
+auto literal = cast(E->getArg(0)->IgnoreParenImpCasts());
+auto result = getPointerAuthStableSipHash16(literal->getString());
+return Success(result, E);
+  }
+
   case Builtin::BI__builtin_ffs:
   case Builtin::BI__builtin_ffsl:
   case Builtin::BI__builtin_ffsll: {
diff --git a/clang/lib/Headers/ptrauth.h b/clang/lib/Headers/ptrauth.h
index 036665d75a91b..3e58af1802084 100644
--- a/clang/lib/Headers/ptrauth.h
+++ b/clang/lib/Headers/ptrauth.h
@@ -135,6 +135,17 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
 #define ptrauth_auth_data(__value, __old_key, __old_data)  
\
   __builtin_ptrauth_auth(__value, __old_key, __old_data)
 
+/* Compute a constant discriminator from the given string.
+
+   The result can be used as the second argument to
+   ptrauth_blend_discriminator or the third argument to the
+   __ptrauth qualifier.  It has type size_t.
+
+   The argument must be a string literal.
+   A call to this function is an integer constant expression. */
+#define ptrauth_string_discriminator(__string) 
\
+  __builtin_ptrauth_string_discriminator(__string)
+
 /* Compute a signature for the given pair of pointer-sized values.
The order of the arguments is significant.
 
@@ -196,6 +207,12 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
 __value;   
\
   })
 
+#define ptrauth_string_discriminator(__string) 
\
+  ({   
\
+(void)__string;
\
+((ptrauth_extra_data_t)0); 
\
+  })
+
 #define 

[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93903

>From 61be7a922397d66773a8f4a6e476ea321f52f00c Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Thu, 30 May 2024 17:22:29 -0700
Subject: [PATCH 1/3] [clang] Define ptrauth_string_discriminator builtin.

This exposes the ABI-stable hash function that allows computing a 16-bit
discriminator from a constant string.

This allows manually matching the implicit string discriminators
computed in the ABI (e.g., from mangled names for vtable pointer/entry
signing), as well as enabling the use of interesting discriminators when
manually annotating specific pointers with the __ptrauth qualifier.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/Builtins.td |  6 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/AST/ExprConstant.cpp|  7 +++
 clang/lib/Headers/ptrauth.h   | 17 
 clang/lib/Sema/SemaChecking.cpp   | 20 +++
 clang/test/CodeGen/ptrauth-intrinsics.c   | 13 
 clang/test/Sema/ptrauth-intrinsics-macro.c|  5 +
 7 files changed, 70 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 11982af3fa609..836697632a3bc 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4411,6 +4411,12 @@ def PtrauthAuth : Builtin {
   let Prototype = "void*(void*,int,void*)";
 }
 
+def PtrauthStringDiscriminator : Builtin {
+  let Spellings = ["__builtin_ptrauth_string_discriminator"];
+  let Attributes = [NoThrow, Const, Constexpr];
+  let Prototype = "size_t(char const*)";
+}
+
 // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
 // We need the generic prototype, since the packet type could be anything.
 def ReadPipe : OCLPipeLangBuiltin {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f15cba63624ea..64add46248c69 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -928,6 +928,8 @@ def warn_ptrauth_sign_null_pointer :
 def warn_ptrauth_auth_null_pointer :
   Warning<"authenticating a null pointer will almost certainly trap">,
   InGroup;
+def err_ptrauth_string_not_literal : Error<
+  "argument must be a string literal%select{| of char type}0">;
 
 /// main()
 // static main() is not an error in C, just in C++.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..eafecfb5fe5b1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -58,6 +58,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
+#include "llvm/Support/SipHash.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -12583,6 +12584,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_expect_with_probability:
 return Visit(E->getArg(0));
 
+  case Builtin::BI__builtin_ptrauth_string_discriminator: {
+auto literal = cast(E->getArg(0)->IgnoreParenImpCasts());
+auto result = getPointerAuthStableSipHash16(literal->getString());
+return Success(result, E);
+  }
+
   case Builtin::BI__builtin_ffs:
   case Builtin::BI__builtin_ffsl:
   case Builtin::BI__builtin_ffsll: {
diff --git a/clang/lib/Headers/ptrauth.h b/clang/lib/Headers/ptrauth.h
index 036665d75a91b..3e58af1802084 100644
--- a/clang/lib/Headers/ptrauth.h
+++ b/clang/lib/Headers/ptrauth.h
@@ -135,6 +135,17 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
 #define ptrauth_auth_data(__value, __old_key, __old_data)  
\
   __builtin_ptrauth_auth(__value, __old_key, __old_data)
 
+/* Compute a constant discriminator from the given string.
+
+   The result can be used as the second argument to
+   ptrauth_blend_discriminator or the third argument to the
+   __ptrauth qualifier.  It has type size_t.
+
+   The argument must be a string literal.
+   A call to this function is an integer constant expression. */
+#define ptrauth_string_discriminator(__string) 
\
+  __builtin_ptrauth_string_discriminator(__string)
+
 /* Compute a signature for the given pair of pointer-sized values.
The order of the arguments is significant.
 
@@ -196,6 +207,12 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
 __value;   
\
   })
 
+#define ptrauth_string_discriminator(__string) 
\
+  ({   
\
+(void)__string;
\
+((ptrauth_extra_data_t)0); 
\
+  })
+
 #define 

[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93904

>From 1a23a99f23714ba6a83b354e3b9afd056b263a02 Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Thu, 30 May 2024 17:33:04 -0700
Subject: [PATCH 1/2] [clang] Define ptrauth_sign_constant builtin.

This is constant-expression equivalent to __builtin_ptrauth_sign,
allowing its usage in global initializers, but requiring constant
pointers and discriminators.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/CodeGen/CodeGenABITypes.h |   6 +
 clang/lib/AST/ExprConstant.cpp|   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |   3 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  62 +
 clang/lib/CodeGen/CGPointerAuth.cpp   |  77 +++
 clang/lib/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/lib/Headers/ptrauth.h   |  25 
 clang/lib/Sema/SemaChecking.cpp   | 128 --
 .../CodeGen/ptrauth-intrinsic-sign-constant.c |  20 +++
 clang/test/Sema/ptrauth-intrinsics-macro.c|   4 +
 clang/test/Sema/ptrauth.c |  29 
 14 files changed, 360 insertions(+), 14 deletions(-)
 create mode 100644 clang/lib/CodeGen/CGPointerAuth.cpp
 create mode 100644 clang/test/CodeGen/ptrauth-intrinsic-sign-constant.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 836697632a3bc..557b70172fc08 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4393,6 +4393,12 @@ def PtrauthSignUnauthenticated : Builtin {
   let Prototype = "void*(void*,int,void*)";
 }
 
+def PtrauthSignConstant : Builtin {
+  let Spellings = ["__builtin_ptrauth_sign_constant"];
+  let Attributes = [CustomTypeChecking, NoThrow, Const, Constexpr];
+  let Prototype = "void*(void*,int,void*)";
+}
+
 def PtrauthSignGenericData : Builtin {
   let Spellings = ["__builtin_ptrauth_sign_generic_data"];
   let Attributes = [CustomTypeChecking, NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64add46248c69..753e775ce0968 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -922,6 +922,13 @@ def err_ptrauth_value_bad_type :
   Error<"%select{signed value|extra discriminator|blended pointer|blended "
 "integer}0 must have %select{pointer|integer|pointer or integer}1 "
 "type; type here is %2">;
+def err_ptrauth_bad_constant_pointer :
+  Error<"argument to ptrauth_sign_constant must refer to a global variable "
+"or function">;
+def err_ptrauth_bad_constant_discriminator :
+  Error<"discriminator argument to ptrauth_sign_constant must be a constant "
+"integer, the address of the global variable where the result "
+"will be stored, or a blend of the two">;
 def warn_ptrauth_sign_null_pointer :
   Warning<"signing a null pointer will yield a non-null pointer">,
   InGroup;
diff --git a/clang/include/clang/CodeGen/CodeGenABITypes.h 
b/clang/include/clang/CodeGen/CodeGenABITypes.h
index fda0855dc8683..8c62d8597ecbe 100644
--- a/clang/include/clang/CodeGen/CodeGenABITypes.h
+++ b/clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -104,6 +104,12 @@ llvm::Type *convertTypeForMemory(CodeGenModule , 
QualType T);
 unsigned getLLVMFieldNumber(CodeGenModule ,
 const RecordDecl *RD, const FieldDecl *FD);
 
+/// Return a signed constant pointer.
+llvm::Constant *getConstantSignedPointer(CodeGenModule ,
+ llvm::Constant *pointer,
+ unsigned key,
+ llvm::Constant *storageAddress,
+ llvm::Constant *otherDiscriminator);
 /// Given the language and code-generation options that Clang was configured
 /// with, set the default LLVM IR attributes for a function definition.
 /// The attributes set here are mostly global target-configuration and
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index eafecfb5fe5b1..b1cb3c323074b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2042,6 +2042,7 @@ static bool IsNoOpCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+  Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
   Builtin == Builtin::BI__builtin_function_start);
 }
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a3c6510503324..b2e3b6fa64284 100644
--- 

[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93903

>From 61be7a922397d66773a8f4a6e476ea321f52f00c Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Thu, 30 May 2024 17:22:29 -0700
Subject: [PATCH 1/2] [clang] Define ptrauth_string_discriminator builtin.

This exposes the ABI-stable hash function that allows computing a 16-bit
discriminator from a constant string.

This allows manually matching the implicit string discriminators
computed in the ABI (e.g., from mangled names for vtable pointer/entry
signing), as well as enabling the use of interesting discriminators when
manually annotating specific pointers with the __ptrauth qualifier.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/Builtins.td |  6 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/AST/ExprConstant.cpp|  7 +++
 clang/lib/Headers/ptrauth.h   | 17 
 clang/lib/Sema/SemaChecking.cpp   | 20 +++
 clang/test/CodeGen/ptrauth-intrinsics.c   | 13 
 clang/test/Sema/ptrauth-intrinsics-macro.c|  5 +
 7 files changed, 70 insertions(+)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 11982af3fa609..836697632a3bc 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4411,6 +4411,12 @@ def PtrauthAuth : Builtin {
   let Prototype = "void*(void*,int,void*)";
 }
 
+def PtrauthStringDiscriminator : Builtin {
+  let Spellings = ["__builtin_ptrauth_string_discriminator"];
+  let Attributes = [NoThrow, Const, Constexpr];
+  let Prototype = "size_t(char const*)";
+}
+
 // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
 // We need the generic prototype, since the packet type could be anything.
 def ReadPipe : OCLPipeLangBuiltin {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f15cba63624ea..64add46248c69 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -928,6 +928,8 @@ def warn_ptrauth_sign_null_pointer :
 def warn_ptrauth_auth_null_pointer :
   Warning<"authenticating a null pointer will almost certainly trap">,
   InGroup;
+def err_ptrauth_string_not_literal : Error<
+  "argument must be a string literal%select{| of char type}0">;
 
 /// main()
 // static main() is not an error in C, just in C++.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e1..eafecfb5fe5b1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -58,6 +58,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
+#include "llvm/Support/SipHash.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -12583,6 +12584,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_expect_with_probability:
 return Visit(E->getArg(0));
 
+  case Builtin::BI__builtin_ptrauth_string_discriminator: {
+auto literal = cast(E->getArg(0)->IgnoreParenImpCasts());
+auto result = getPointerAuthStableSipHash16(literal->getString());
+return Success(result, E);
+  }
+
   case Builtin::BI__builtin_ffs:
   case Builtin::BI__builtin_ffsl:
   case Builtin::BI__builtin_ffsll: {
diff --git a/clang/lib/Headers/ptrauth.h b/clang/lib/Headers/ptrauth.h
index 036665d75a91b..3e58af1802084 100644
--- a/clang/lib/Headers/ptrauth.h
+++ b/clang/lib/Headers/ptrauth.h
@@ -135,6 +135,17 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
 #define ptrauth_auth_data(__value, __old_key, __old_data)  
\
   __builtin_ptrauth_auth(__value, __old_key, __old_data)
 
+/* Compute a constant discriminator from the given string.
+
+   The result can be used as the second argument to
+   ptrauth_blend_discriminator or the third argument to the
+   __ptrauth qualifier.  It has type size_t.
+
+   The argument must be a string literal.
+   A call to this function is an integer constant expression. */
+#define ptrauth_string_discriminator(__string) 
\
+  __builtin_ptrauth_string_discriminator(__string)
+
 /* Compute a signature for the given pair of pointer-sized values.
The order of the arguments is significant.
 
@@ -196,6 +207,12 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
 __value;   
\
   })
 
+#define ptrauth_string_discriminator(__string) 
\
+  ({   
\
+(void)__string;
\
+((ptrauth_extra_data_t)0); 
\
+  })
+
 #define 

[llvm-branch-commits] [SPARC][IAS] Handle the case of non-4-byte aligned writeNopData (PR #94251)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits

https://github.com/s-barannikov approved this pull request.


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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits




kovdan01 wrote:

It would be nice to also add a run line against `aarch64` or `aarch64-elf` 
generic triple in this and other tests (see code below). The logic tested is 
not apple-specific. The test would need a slight change since IR for ELF has 
functions marked as `dso_local` - you might probably want to use smth like `// 
CHECK-LABEL: define {{.*}}void @test_auth()` to match both MachO and ELF or, 
alternatively, use different check prefixes for function labels on MachO and 
ELF to avoid regex in match lines.

```
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s
// RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s
```

This is probably a subject for another tiny PR since the RUN line is not 
touched here and the test already existed.

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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits


@@ -557,6 +557,36 @@
 ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
 prefetch  [ %i1 + %i2 ], #one_read
 
+! V8:  error: malformed ASI tag, must be a constant integer 
expression

s-barannikov wrote:

The error message is wrong.
I guess parseASITag / parsePrefetchTag should return NoMatch on no match rather 
than issue an error.


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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);

kovdan01 wrote:

```suggestion
  const auto *Literal = dyn_cast(arg);
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {
+S.Diag(arg->getExprLoc(), diag::err_ptrauth_string_not_literal)

kovdan01 wrote:

This error message looks untested

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits

https://github.com/kovdan01 requested changes to this pull request.

The changes themself in terms of functionality look OK to me - but I want 
someone else with deeper understanding of the context to take a look before 
this gets merged.

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits

https://github.com/kovdan01 edited 
https://github.com/llvm/llvm-project/pull/93903
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -12583,6 +12584,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_expect_with_probability:
 return Visit(E->getArg(0));
 
+  case Builtin::BI__builtin_ptrauth_string_discriminator: {
+auto literal = cast(E->getArg(0)->IgnoreParenImpCasts());

kovdan01 wrote:

```suggestion
const auto *Literal = 
cast(E->getArg(0)->IgnoreParenImpCasts());
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {

kovdan01 wrote:

Naming style of variables all over the function (use `PascalCase` 
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();

kovdan01 wrote:

```suggestion
  const Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -12583,6 +12584,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_expect_with_probability:
 return Visit(E->getArg(0));
 
+  case Builtin::BI__builtin_ptrauth_string_discriminator: {
+auto literal = cast(E->getArg(0)->IgnoreParenImpCasts());
+auto result = getPointerAuthStableSipHash16(literal->getString());

kovdan01 wrote:

Does `auto` increase readability here? `uint64_t Result` IMHO looks better - at 
least, with `auto` it's not obvious which type the variable has.

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


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits


@@ -1088,6 +1115,34 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector 
) {
   return ParseStatus::Success;
 }
 
+ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector ) {
+  SMLoc S = Parser.getTok().getLoc();
+  SMLoc E = Parser.getTok().getEndLoc();
+  int64_t PrefetchVal = 0;
+
+  if (getLexer().getKind() == AsmToken::Hash) {
+SMLoc TagStart = getLexer().peekTok(false).getLoc();
+Parser.Lex(); // Eat the '#'.
+auto PrefetchName = Parser.getTok().getString();
+auto PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);

s-barannikov wrote:

```suggestion
auto *PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
```
Or even better do not use auto.


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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/93904
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2126,14 +2219,16 @@ static ExprResult PointerAuthSignGenericData(Sema , 
CallExpr *Call) {
 }
 
 static ExprResult PointerAuthSignOrAuth(Sema , CallExpr *Call,
-PointerAuthOpKind OpKind) {
+PointerAuthOpKind OpKind,
+bool RequireConstant) {
   if (S.checkArgCount(Call, 3))
 return ExprError();
   if (checkPointerAuthEnabled(S, Call))
 return ExprError();
-  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind) ||
+  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind, RequireConstant) ||

asl wrote:

Can we check code like `Call->getArgs()[N]` to `Call->getArg(N)` while here? 
Certainly not everywhere, but on changed lines?

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {
+S.Diag(arg->getExprLoc(), diag::err_ptrauth_string_not_literal)
+  << (literal ? 1 : 0)
+  << arg->getSourceRange();
+return ExprError();
+  }
+
+  return call;

asl wrote:

```suggestion
  return Call;
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);

asl wrote:

```suggestion
  const auto *Literal = dyn_cast(Arg);
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {

asl wrote:

```suggestion
  if (!Literal || Literal->getCharByteWidth() != 1) {
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();

asl wrote:

```suggestion
  if (checkPointerAuthEnabled(S, Call)) return ExprError();
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {
+S.Diag(arg->getExprLoc(), diag::err_ptrauth_string_not_literal)
+  << (literal ? 1 : 0)
+  << arg->getSourceRange();

asl wrote:

```suggestion
  << Arg->getSourceRange();
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();
+
+  // Operand must be an ordinary or UTF-8 string literal.
+  auto literal = dyn_cast(arg);
+  if (!literal || literal->getCharByteWidth() != 1) {
+S.Diag(arg->getExprLoc(), diag::err_ptrauth_string_not_literal)
+  << (literal ? 1 : 0)

asl wrote:

```suggestion
  << (Literal ? 1 : 0)
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {

asl wrote:

```suggestion
static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *Call) {
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -2156,6 +2156,24 @@ static ExprResult PointerAuthAuthAndResign(Sema , 
CallExpr *Call) {
   return Call;
 }
 
+static ExprResult PointerAuthStringDiscriminator(Sema , CallExpr *call) {
+  if (checkPointerAuthEnabled(S, call)) return ExprError();
+
+  // We've already performed normal call type-checking.
+  Expr *arg = call->getArgs()[0]->IgnoreParenImpCasts();

asl wrote:

```suggestion
  Expr *Arg = Call->getArg(0)->IgnoreParenImpCasts();
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl commented:

See mostly code style nits above

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_string_discriminator builtin. (PR #93903)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits

https://github.com/asl edited https://github.com/llvm/llvm-project/pull/93903
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits


@@ -537,16 +537,26 @@
 ! V9: stxa %g0, [%g2+%i5] #ASI_SNF   ! encoding: [0xc0,0xf0,0x90,0x7d]
 stxa %g0, [%g2 + %i5] #ASI_SNF
 
-! V8:  error: instruction requires a CPU feature not currently 
enabled
+! V8:  error: invalid operand for instruction

s-barannikov wrote:

Why is this difference?


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


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits

https://github.com/s-barannikov commented:

Please add testcases for the remaining tags


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


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits

https://github.com/s-barannikov edited 
https://github.com/llvm/llvm-project/pull/94249
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s

kovdan01 wrote:

> @kovdan01 If you're having a RUN line locally, can you just suggest a change 
> here?

Updated the comment, thanks

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits

https://github.com/kovdan01 edited 
https://github.com/llvm/llvm-project/pull/93904
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [SPARC][IAS] Add aliases for %asr20-21 as defined in JPS1 (PR #94247)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits

https://github.com/s-barannikov approved this pull request.


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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s

asl wrote:

@kovdan01 If you're having a RUN line locally, can you just suggest a change 
here?

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits

https://github.com/kovdan01 edited 
https://github.com/llvm/llvm-project/pull/93904
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [SPARC][IAS] Add support for %uhi and %ulo extensions (PR #94246)

2024-06-03 Thread Sergei Barannikov via llvm-branch-commits

https://github.com/s-barannikov approved this pull request.


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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2061,6 +2071,58 @@ ConstantLValueEmitter::VisitCallExpr(const CallExpr *E) {
   }
 }
 
+ConstantLValue
+ConstantLValueEmitter::emitPointerAuthSignConstant(const CallExpr *E) {
+  auto unsignedPointer = emitPointerAuthPointer(E->getArg(0));
+  auto key = emitPointerAuthKey(E->getArg(1));
+  llvm::Constant *storageAddress;
+  llvm::Constant *otherDiscriminator;
+  std::tie(storageAddress, otherDiscriminator) =
+emitPointerAuthDiscriminator(E->getArg(2));
+
+  auto signedPointer =
+CGM.getConstantSignedPointer(unsignedPointer, key, storageAddress,
+ otherDiscriminator);
+  return signedPointer;
+}
+
+llvm::Constant *ConstantLValueEmitter::emitPointerAuthPointer(const Expr *E) {
+  Expr::EvalResult result;
+  bool succeeded = E->EvaluateAsRValue(result, CGM.getContext());
+  assert(succeeded); (void) succeeded;
+
+  // The assertions here are all checked by Sema.
+  assert(result.Val.isLValue());
+  return ConstantEmitter(CGM, Emitter.CGF)
+   .emitAbstract(E->getExprLoc(), result.Val, E->getType());
+}
+
+unsigned ConstantLValueEmitter::emitPointerAuthKey(const Expr *E) {
+  return E->EvaluateKnownConstInt(CGM.getContext()).getZExtValue();
+}
+
+std::pair
+ConstantLValueEmitter::emitPointerAuthDiscriminator(const Expr *E) {
+  E = E->IgnoreParens();
+
+  if (auto call = dyn_cast(E)) {

kovdan01 wrote:

For `call`, `pointer`, `extra`, `result`: `auto` -> `auto *`

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s

kovdan01 wrote:

It would be nice to also add a run line against `aarch64` or `aarch64-elf` 
generic triple in this and other tests. The logic tested is not apple-specific 
and locally I've ensured that adding this run line does not break tests.

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits

https://github.com/kovdan01 requested changes to this pull request.

The changes themself in terms of functionality look OK to me - but I want 
someone else with deeper understanding of the context to take a look before 
this gets merged.

In terms of style, here are some of the categories of minor issues:
- unneeded includes
- wrong case for variables (need `PascalCase`, the surrounding code also uses 
that, so no need for not following the global convention 
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)
- missing `const` qualifiers and `auto` -> `auto *`


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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2030,8 +2030,26 @@ bool Sema::checkConstantPointerAuthKey(Expr *Arg, 
unsigned ) {
   return false;
 }
 
+static std::pair
+findConstantBaseAndOffset(Sema , Expr *E) {

kovdan01 wrote:

Naming style of variables

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -0,0 +1,77 @@
+//===--- CGPointerAuth.cpp - IR generation for pointer authentication 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file contains common routines relating to the emission of
+// pointer authentication operations.
+//
+//===--===//
+
+#include "CGCXXABI.h"
+#include "CGCall.h"
+#include "CodeGenFunction.h"
+#include "CodeGenModule.h"
+#include "clang/AST/Attr.h"
+#include "clang/Basic/PointerAuthOptions.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
+#include "clang/CodeGen/ConstantInitBuilder.h"
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/IR/ValueMap.h"
+#include "llvm/Analysis/ValueTracking.h"
+#include 
+
+using namespace clang;
+using namespace CodeGen;
+
+/// Build a signed-pointer "ptrauth" constant.
+static llvm::ConstantPtrAuth *
+buildConstantAddress(CodeGenModule , llvm::Constant *pointer, unsigned key,

kovdan01 wrote:

Naming style of variables here and all over the file

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2061,6 +2071,58 @@ ConstantLValueEmitter::VisitCallExpr(const CallExpr *E) {
   }
 }
 
+ConstantLValue
+ConstantLValueEmitter::emitPointerAuthSignConstant(const CallExpr *E) {
+  auto unsignedPointer = emitPointerAuthPointer(E->getArg(0));
+  auto key = emitPointerAuthKey(E->getArg(1));
+  llvm::Constant *storageAddress;
+  llvm::Constant *otherDiscriminator;
+  std::tie(storageAddress, otherDiscriminator) =
+emitPointerAuthDiscriminator(E->getArg(2));
+
+  auto signedPointer =
+CGM.getConstantSignedPointer(unsignedPointer, key, storageAddress,
+ otherDiscriminator);
+  return signedPointer;
+}
+
+llvm::Constant *ConstantLValueEmitter::emitPointerAuthPointer(const Expr *E) {

kovdan01 wrote:

Names to fix: `result`, `succeeded`

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -0,0 +1,77 @@
+//===--- CGPointerAuth.cpp - IR generation for pointer authentication 
-===//
+//
+// 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
+//
+//===--===//
+//
+// This file contains common routines relating to the emission of
+// pointer authentication operations.
+//
+//===--===//
+
+#include "CGCXXABI.h"

kovdan01 wrote:

It looks like that only two includes are needed: CodeGenModule.h and 
clang/CodeGen/CodeGenABITypes.h. Maybe some other includes would become needed 
in future, but let's add them in corresponding PRs, not here.

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2061,6 +2071,58 @@ ConstantLValueEmitter::VisitCallExpr(const CallExpr *E) {
   }
 }
 
+ConstantLValue
+ConstantLValueEmitter::emitPointerAuthSignConstant(const CallExpr *E) {
+  auto unsignedPointer = emitPointerAuthPointer(E->getArg(0));
+  auto key = emitPointerAuthKey(E->getArg(1));
+  llvm::Constant *storageAddress;
+  llvm::Constant *otherDiscriminator;
+  std::tie(storageAddress, otherDiscriminator) =
+emitPointerAuthDiscriminator(E->getArg(2));
+
+  auto signedPointer =
+CGM.getConstantSignedPointer(unsignedPointer, key, storageAddress,
+ otherDiscriminator);
+  return signedPointer;
+}
+
+llvm::Constant *ConstantLValueEmitter::emitPointerAuthPointer(const Expr *E) {
+  Expr::EvalResult result;
+  bool succeeded = E->EvaluateAsRValue(result, CGM.getContext());
+  assert(succeeded); (void) succeeded;
+
+  // The assertions here are all checked by Sema.
+  assert(result.Val.isLValue());
+  return ConstantEmitter(CGM, Emitter.CGF)
+   .emitAbstract(E->getExprLoc(), result.Val, E->getType());
+}
+
+unsigned ConstantLValueEmitter::emitPointerAuthKey(const Expr *E) {
+  return E->EvaluateKnownConstInt(CGM.getContext()).getZExtValue();
+}
+
+std::pair
+ConstantLValueEmitter::emitPointerAuthDiscriminator(const Expr *E) {

kovdan01 wrote:

Names to fix: `call`, `pointer`, `extra`, `result`

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2061,6 +2071,58 @@ ConstantLValueEmitter::VisitCallExpr(const CallExpr *E) {
   }
 }
 
+ConstantLValue
+ConstantLValueEmitter::emitPointerAuthSignConstant(const CallExpr *E) {
+  auto unsignedPointer = emitPointerAuthPointer(E->getArg(0));

kovdan01 wrote:

For `unsignedPointer`, `key`, `signedPointer`: `auto` -> `auto *`

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2074,16 +2092,91 @@ static bool checkPointerAuthValue(Sema , Expr *,
   if (convertArgumentToType(S, Arg, ExpectedTy))
 return true;
 
-  // Warn about null pointers for non-generic sign and auth operations.
-  if ((OpKind == PAO_Sign || OpKind == PAO_Auth) &&
-  Arg->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNull)) {
-S.Diag(Arg->getExprLoc(), OpKind == PAO_Sign
-  ? diag::warn_ptrauth_sign_null_pointer
-  : diag::warn_ptrauth_auth_null_pointer)
-<< Arg->getSourceRange();
+  if (!RequireConstant) {
+// Warn about null pointers for non-generic sign and auth operations.
+if ((OpKind == PAO_Sign || OpKind == PAO_Auth) &&
+Arg->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNull)) 
{
+  S.Diag(Arg->getExprLoc(), OpKind == PAO_Sign
+? diag::warn_ptrauth_sign_null_pointer
+: diag::warn_ptrauth_auth_null_pointer)
+  << Arg->getSourceRange();
+}
+
+return false;
   }
 
-  return false;
+  // Perform special checking on the arguments to ptrauth_sign_constant.
+
+  // The main argument.
+  if (OpKind == PAO_Sign) {
+// Require the value we're signing to have a special form.
+auto result = findConstantBaseAndOffset(S, Arg);
+bool invalid;
+
+// Must be rooted in a declaration reference.
+if (!result.first) {
+  invalid = true;
+
+// If it's a function declaration, we can't have an offset.
+} else if (isa(result.first)) {
+  invalid = !result.second.isZero();
+
+// Otherwise we're fine.
+} else {
+  invalid = false;
+}
+
+if (invalid) {
+  S.Diag(Arg->getExprLoc(), diag::err_ptrauth_bad_constant_pointer);
+}
+return invalid;
+  }
+
+  // The discriminator argument.
+  assert(OpKind == PAO_Discriminator);
+
+  // Must be a pointer or integer or blend thereof.
+  Expr *pointer = nullptr;
+  Expr *integer = nullptr;
+  if (auto call = dyn_cast(Arg->IgnoreParens())) {

kovdan01 wrote:

```suggestion
  if (auto *Call = dyn_cast(Arg->IgnoreParens())) {
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -938,6 +938,11 @@ class CodeGenModule : public CodeGenTypeCache {
   // Return the function body address of the given function.
   llvm::Constant *GetFunctionStart(const ValueDecl *Decl);
 
+  llvm::Constant *getConstantSignedPointer(llvm::Constant *pointer,

kovdan01 wrote:

Naming style of variables

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2030,8 +2030,26 @@ bool Sema::checkConstantPointerAuthKey(Expr *Arg, 
unsigned ) {
   return false;
 }
 
+static std::pair
+findConstantBaseAndOffset(Sema , Expr *E) {
+  // Must evaluate as a pointer.
+  Expr::EvalResult result;
+  if (!E->EvaluateAsRValue(result, S.Context) ||
+  !result.Val.isLValue())
+return std::make_pair(nullptr, CharUnits());
+
+  // Base must be a declaration and can't be weakly imported.
+  auto baseDecl =

kovdan01 wrote:

```suggestion
  const auto *BaseDecl =
```

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


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits

https://github.com/kovdan01 edited 
https://github.com/llvm/llvm-project/pull/93904
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-03 Thread Daniil Kovalev via llvm-branch-commits


@@ -2061,6 +2071,58 @@ ConstantLValueEmitter::VisitCallExpr(const CallExpr *E) {
   }
 }
 
+ConstantLValue
+ConstantLValueEmitter::emitPointerAuthSignConstant(const CallExpr *E) {

kovdan01 wrote:

Names to fix: `unsignedPointer`, `key`, `storageAddress`, `otherDiscriminator`, 
`signedPointer`

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


[llvm-branch-commits] [clang] [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (PR #94056)

2024-06-03 Thread Anton Korobeynikov via llvm-branch-commits


@@ -1261,6 +1262,10 @@ class ASTContext : public RefCountedBase {
   /// space.
   QualType removeAddrSpaceQualType(QualType T) const;
 
+  /// Return the "other" type-specific discriminator for the given type.

asl wrote:

The comment here looks a bit misleading without knowing what function is doing. 
Could it be reformulated in some better way?

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


[llvm-branch-commits] [clang] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Ahmed Bougacha (ahmedbougacha)


Changes

The functions are currently always signed/authenticated with zero discriminator.

Co-Authored-By: John McCall rjmccall@apple.com

---

Patch is 37.62 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/93906.diff


24 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.h (+4) 
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) 
- (modified) clang/include/clang/Basic/LangOptions.h (+2) 
- (modified) clang/include/clang/Basic/PointerAuthOptions.h (+136) 
- (modified) clang/include/clang/Frontend/CompilerInvocation.h (+10) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+3) 
- (modified) clang/lib/CodeGen/CGCall.h (+22-6) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+9-8) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+18-1) 
- (modified) clang/lib/CodeGen/CGPointerAuth.cpp (+51) 
- (added) clang/lib/CodeGen/CGPointerAuthInfo.h (+96) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+22) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+7) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+34) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+36) 
- (modified) clang/lib/Headers/ptrauth.h (+34) 
- (added) clang/test/CodeGen/ptrauth-function-attributes.c (+13) 
- (added) clang/test/CodeGen/ptrauth-function-init-fail.c (+5) 
- (added) clang/test/CodeGen/ptrauth-function-init.c (+31) 
- (added) clang/test/CodeGen/ptrauth-function-lvalue-cast.c (+23) 
- (added) clang/test/CodeGen/ptrauth-function.c (+28) 
- (added) clang/test/CodeGen/ptrauth-weak_import.c (+10) 
- (added) clang/test/CodeGenCXX/ptrauth.cpp (+24) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb..502722a6ec4eb 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 
+#include "clang/Basic/PointerAuthOptions.h"
 #include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/XRayInstr.h"
 #include "llvm/ADT/FloatingPointMode.h"
@@ -388,6 +389,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   std::vector Reciprocals;
 
+  /// Configuration for pointer-signing.
+  PointerAuthOptions PointerAuth;
+
   /// The preferred width for auto-vectorization transforms. This is intended 
to
   /// override default transforms based on the width of the architected vector
   /// registers.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 773b234cd68fe..6cbb0c8401c15 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -351,6 +351,9 @@ def err_drv_omp_host_ir_file_not_found : Error<
   "target regions but cannot be found">;
 def err_drv_omp_host_target_not_supported : Error<
   "target '%0' is not a supported OpenMP host target">;
+def err_drv_ptrauth_not_supported : Error<
+  "target '%0' does not support native pointer authentication">;
+
 def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
   "'-fopenmp-targets' must be used in conjunction with a '-fopenmp' option "
   "compatible with offloading; e.g., '-fopenmp=libomp' or 
'-fopenmp=libiomp5'">;
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 75e88afbd9705..5216822e45b1b 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -346,6 +346,8 @@ class LangOptionsBase {
 BKey
   };
 
+  using PointerAuthenticationMode = ::clang::PointerAuthenticationMode;
+
   enum class ThreadModelKind {
 /// POSIX Threads.
 POSIX,
diff --git a/clang/include/clang/Basic/PointerAuthOptions.h 
b/clang/include/clang/Basic/PointerAuthOptions.h
index e5cdcc31ebfb7..32b179e3f9460 100644
--- a/clang/include/clang/Basic/PointerAuthOptions.h
+++ b/clang/include/clang/Basic/PointerAuthOptions.h
@@ -14,10 +14,146 @@
 #ifndef LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 #define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Target/TargetOptions.h"
+#include 
+#include 
+#include 
+#include 
+
 namespace clang {
 
 constexpr unsigned PointerAuthKeyNone = -1;
 
+class PointerAuthSchema {
+public:
+  enum class Kind : unsigned {
+None,
+ARM8_3,
+  };
+
+  /// Hardware pointer-signing keys in ARM8.3.
+  ///
+  /// These values are the same used in ptrauth.h.
+  enum class ARM8_3Key : unsigned {
+ASIA = 0,
+ASIB = 1,
+ASDA = 2,
+ASDB = 3
+  };
+
+  /// Forms of extra discrimination.
+  enum class Discrimination : unsigned {
+/// No additional discrimination.
+

[llvm-branch-commits] [clang] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Ahmed Bougacha (ahmedbougacha)


Changes

The functions are currently always signed/authenticated with zero discriminator.

Co-Authored-By: John McCall rjmccall@apple.com

---

Patch is 37.62 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/93906.diff


24 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.h (+4) 
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) 
- (modified) clang/include/clang/Basic/LangOptions.h (+2) 
- (modified) clang/include/clang/Basic/PointerAuthOptions.h (+136) 
- (modified) clang/include/clang/Frontend/CompilerInvocation.h (+10) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+3) 
- (modified) clang/lib/CodeGen/CGCall.h (+22-6) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+9-8) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+18-1) 
- (modified) clang/lib/CodeGen/CGPointerAuth.cpp (+51) 
- (added) clang/lib/CodeGen/CGPointerAuthInfo.h (+96) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+22) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+7) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+34) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+36) 
- (modified) clang/lib/Headers/ptrauth.h (+34) 
- (added) clang/test/CodeGen/ptrauth-function-attributes.c (+13) 
- (added) clang/test/CodeGen/ptrauth-function-init-fail.c (+5) 
- (added) clang/test/CodeGen/ptrauth-function-init.c (+31) 
- (added) clang/test/CodeGen/ptrauth-function-lvalue-cast.c (+23) 
- (added) clang/test/CodeGen/ptrauth-function.c (+28) 
- (added) clang/test/CodeGen/ptrauth-weak_import.c (+10) 
- (added) clang/test/CodeGenCXX/ptrauth.cpp (+24) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb..502722a6ec4eb 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 
+#include "clang/Basic/PointerAuthOptions.h"
 #include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/XRayInstr.h"
 #include "llvm/ADT/FloatingPointMode.h"
@@ -388,6 +389,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   std::vector Reciprocals;
 
+  /// Configuration for pointer-signing.
+  PointerAuthOptions PointerAuth;
+
   /// The preferred width for auto-vectorization transforms. This is intended 
to
   /// override default transforms based on the width of the architected vector
   /// registers.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 773b234cd68fe..6cbb0c8401c15 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -351,6 +351,9 @@ def err_drv_omp_host_ir_file_not_found : Error<
   "target regions but cannot be found">;
 def err_drv_omp_host_target_not_supported : Error<
   "target '%0' is not a supported OpenMP host target">;
+def err_drv_ptrauth_not_supported : Error<
+  "target '%0' does not support native pointer authentication">;
+
 def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
   "'-fopenmp-targets' must be used in conjunction with a '-fopenmp' option "
   "compatible with offloading; e.g., '-fopenmp=libomp' or 
'-fopenmp=libiomp5'">;
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 75e88afbd9705..5216822e45b1b 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -346,6 +346,8 @@ class LangOptionsBase {
 BKey
   };
 
+  using PointerAuthenticationMode = ::clang::PointerAuthenticationMode;
+
   enum class ThreadModelKind {
 /// POSIX Threads.
 POSIX,
diff --git a/clang/include/clang/Basic/PointerAuthOptions.h 
b/clang/include/clang/Basic/PointerAuthOptions.h
index e5cdcc31ebfb7..32b179e3f9460 100644
--- a/clang/include/clang/Basic/PointerAuthOptions.h
+++ b/clang/include/clang/Basic/PointerAuthOptions.h
@@ -14,10 +14,146 @@
 #ifndef LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 #define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Target/TargetOptions.h"
+#include 
+#include 
+#include 
+#include 
+
 namespace clang {
 
 constexpr unsigned PointerAuthKeyNone = -1;
 
+class PointerAuthSchema {
+public:
+  enum class Kind : unsigned {
+None,
+ARM8_3,
+  };
+
+  /// Hardware pointer-signing keys in ARM8.3.
+  ///
+  /// These values are the same used in ptrauth.h.
+  enum class ARM8_3Key : unsigned {
+ASIA = 0,
+ASIB = 1,
+ASDA = 2,
+ASDB = 3
+  };
+
+  /// Forms of extra discrimination.
+  enum class Discrimination : unsigned {
+/// No additional discrimination.
+  

[llvm-branch-commits] [clang] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-03 Thread Akira Hatanaka via llvm-branch-commits

https://github.com/ahatanak ready_for_review 
https://github.com/llvm/llvm-project/pull/93906
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-03 Thread Akira Hatanaka via llvm-branch-commits

https://github.com/ahatanak edited 
https://github.com/llvm/llvm-project/pull/93906
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-03 Thread Akira Hatanaka via llvm-branch-commits

https://github.com/ahatanak edited 
https://github.com/llvm/llvm-project/pull/93906
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Implement function pointer signing. (PR #93906)

2024-06-03 Thread Akira Hatanaka via llvm-branch-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/93906

>From 0e85001f6d53e63beca77a76eaba1875ec84000d Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Fri, 24 May 2024 20:23:36 -0700
Subject: [PATCH 1/2] [clang] Implement function pointer signing.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/CodeGenOptions.h|   4 +
 .../clang/Basic/DiagnosticDriverKinds.td  |   3 +
 clang/include/clang/Basic/LangOptions.h   |   2 +
 .../include/clang/Basic/PointerAuthOptions.h  | 136 ++
 .../clang/Frontend/CompilerInvocation.h   |  10 ++
 clang/lib/CodeGen/CGBuiltin.cpp   |   3 +-
 clang/lib/CodeGen/CGCall.cpp  |   3 +
 clang/lib/CodeGen/CGCall.h|  28 +++-
 clang/lib/CodeGen/CGExpr.cpp  |  17 +--
 clang/lib/CodeGen/CGExprConstant.cpp  |  19 ++-
 clang/lib/CodeGen/CGPointerAuth.cpp   |  51 +++
 clang/lib/CodeGen/CGPointerAuthInfo.h |  96 +
 clang/lib/CodeGen/CodeGenFunction.cpp |  58 
 clang/lib/CodeGen/CodeGenFunction.h   |  10 ++
 clang/lib/CodeGen/CodeGenModule.h |  34 +
 clang/lib/Frontend/CompilerInvocation.cpp |  36 +
 clang/lib/Headers/ptrauth.h   |  34 +
 .../CodeGen/ptrauth-function-attributes.c |  13 ++
 .../test/CodeGen/ptrauth-function-init-fail.c |   5 +
 clang/test/CodeGen/ptrauth-function-init.c|  31 
 .../CodeGen/ptrauth-function-lvalue-cast.c|  23 +++
 clang/test/CodeGen/ptrauth-weak_import.c  |  10 ++
 clang/test/CodeGenCXX/ptrauth.cpp |  24 
 23 files changed, 633 insertions(+), 17 deletions(-)
 create mode 100644 clang/lib/CodeGen/CGPointerAuthInfo.h
 create mode 100644 clang/test/CodeGen/ptrauth-function-attributes.c
 create mode 100644 clang/test/CodeGen/ptrauth-function-init-fail.c
 create mode 100644 clang/test/CodeGen/ptrauth-function-init.c
 create mode 100644 clang/test/CodeGen/ptrauth-function-lvalue-cast.c
 create mode 100644 clang/test/CodeGen/ptrauth-weak_import.c
 create mode 100644 clang/test/CodeGenCXX/ptrauth.cpp

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb..502722a6ec4eb 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 
+#include "clang/Basic/PointerAuthOptions.h"
 #include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/XRayInstr.h"
 #include "llvm/ADT/FloatingPointMode.h"
@@ -388,6 +389,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   std::vector Reciprocals;
 
+  /// Configuration for pointer-signing.
+  PointerAuthOptions PointerAuth;
+
   /// The preferred width for auto-vectorization transforms. This is intended 
to
   /// override default transforms based on the width of the architected vector
   /// registers.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 773b234cd68fe..6cbb0c8401c15 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -351,6 +351,9 @@ def err_drv_omp_host_ir_file_not_found : Error<
   "target regions but cannot be found">;
 def err_drv_omp_host_target_not_supported : Error<
   "target '%0' is not a supported OpenMP host target">;
+def err_drv_ptrauth_not_supported : Error<
+  "target '%0' does not support native pointer authentication">;
+
 def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
   "'-fopenmp-targets' must be used in conjunction with a '-fopenmp' option "
   "compatible with offloading; e.g., '-fopenmp=libomp' or 
'-fopenmp=libiomp5'">;
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 75e88afbd9705..5216822e45b1b 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -346,6 +346,8 @@ class LangOptionsBase {
 BKey
   };
 
+  using PointerAuthenticationMode = ::clang::PointerAuthenticationMode;
+
   enum class ThreadModelKind {
 /// POSIX Threads.
 POSIX,
diff --git a/clang/include/clang/Basic/PointerAuthOptions.h 
b/clang/include/clang/Basic/PointerAuthOptions.h
index e5cdcc31ebfb7..32b179e3f9460 100644
--- a/clang/include/clang/Basic/PointerAuthOptions.h
+++ b/clang/include/clang/Basic/PointerAuthOptions.h
@@ -14,10 +14,146 @@
 #ifndef LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 #define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
 
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Target/TargetOptions.h"
+#include 
+#include 
+#include 
+#include 
+
 namespace clang {
 
 constexpr unsigned PointerAuthKeyNone = -1;
 
+class PointerAuthSchema {
+public:
+  enum class Kind : unsigned {
+

[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/94244

>From 615f30ba7db2bb13d20b4c2a8c0d405a8419ecae Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp  | 2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h| 7 +--
 clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 9 +++--
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index aed6a6408adc9..dd98fbdce3945 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e981299531574..ad2f5f355621c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap  = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ada3be287ed59..6bb402caa4d6d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5641,7 +5641,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5850,16 +5849,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher ,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;

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


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/94248
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [SPARC][IAS] Add movr(n)e alias for movr(n)z (PR #94252)

2024-06-03 Thread via llvm-branch-commits

koachan wrote:

Note: this PR was created by `spr`, please do not hand-merge this.

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


[llvm-branch-commits] [SPARC][IAS] Handle the case of non-4-byte aligned writeNopData (PR #94251)

2024-06-03 Thread via llvm-branch-commits

koachan wrote:

Note: this PR was created by `spr`, please do not hand-merge this.

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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread via llvm-branch-commits

koachan wrote:

Note: this PR was created by `spr`, please do not hand-merge this.

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


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread via llvm-branch-commits

koachan wrote:

Note: this PR was created by `spr`, please do not hand-merge this.

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


[llvm-branch-commits] [SPARC][IAS] Add aliases for %asr20-21 as defined in JPS1 (PR #94247)

2024-06-03 Thread via llvm-branch-commits

koachan wrote:

Note: this PR was created by `spr`, please do not hand-merge this.

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


[llvm-branch-commits] [SPARC][IAS] Add support for %uhi and %ulo extensions (PR #94246)

2024-06-03 Thread via llvm-branch-commits

koachan wrote:

Note: this PR was created by `spr`, please do not hand-merge this.

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


[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

5chmidti wrote:

CC @llvm/pr-subscribers-clang-tidy as stake-holders in matchers

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


[llvm-branch-commits] [SPARC][IAS] Handle the case of non-4-byte aligned writeNopData (PR #94251)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

If the Count passed into writeNopData is not a multiple of four,
add a little amount of zeros before writing the NOP stream.
This makes it match the behavior of GNU binutils.


---
Full diff: https://github.com/llvm/llvm-project/pull/94251.diff


1 Files Affected:

- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp (+5-3) 


``diff
diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp 
b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
index 240f5396855c8..cb7414fddd29f 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
@@ -323,9 +323,11 @@ namespace {
 
 bool writeNopData(raw_ostream , uint64_t Count,
   const MCSubtargetInfo *STI) const override {
-  // Cannot emit NOP with size not multiple of 32 bits.
-  if (Count % 4 != 0)
-return false;
+
+  // If the count is not 4-byte aligned, we must be writing data into the
+  // text section (otherwise we have unaligned instructions, and thus have
+  // far bigger problems), so just write zeros instead.
+  OS.write_zeros(Count % 4);
 
   uint64_t NumNops = Count / 4;
   for (uint64_t i = 0; i != NumNops; ++i)

``




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


[llvm-branch-commits] [SPARC][IAS] Add movr(n)e alias for movr(n)z (PR #94252)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Koakuma (koachan)


Changes

This adds the alternate mnemonics for movrz and movrnz.


---
Full diff: https://github.com/llvm/llvm-project/pull/94252.diff


2 Files Affected:

- (modified) llvm/lib/Target/Sparc/SparcInstrAliases.td (+2) 
- (modified) llvm/test/MC/Sparc/sparc64-ctrl-instructions.s (+8) 


``diff
diff --git a/llvm/lib/Target/Sparc/SparcInstrAliases.td 
b/llvm/lib/Target/Sparc/SparcInstrAliases.td
index 2b9244519f154..eedad25737f65 100644
--- a/llvm/lib/Target/Sparc/SparcInstrAliases.td
+++ b/llvm/lib/Target/Sparc/SparcInstrAliases.td
@@ -400,9 +400,11 @@ defm : cp_cond_alias<"012",   0b>;
 let EmitPriority = 0 in defm : cp_cond_alias<"",  0b1000>; // same as a; 
gnu asm, not in manual
 
 defm : reg_cond_alias<"z",0b001>;
+defm : reg_cond_alias<"e",0b001>;
 defm : reg_cond_alias<"lez",  0b010>;
 defm : reg_cond_alias<"lz",   0b011>;
 defm : reg_cond_alias<"nz",   0b101>;
+defm : reg_cond_alias<"ne",   0b101>;
 defm : reg_cond_alias<"gz",   0b110>;
 defm : reg_cond_alias<"gez",  0b111>;
 
diff --git a/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s 
b/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s
index a21b17552eb15..188947314f4b7 100644
--- a/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s
+++ b/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s
@@ -1190,29 +1190,37 @@
 ! CHECK-NEXT: !   fixup A - offset: 0, 
value: .BB0, kind: fixup_sparc_br16
 brz,a,pn   %g1, .BB0
 
+! CHECK: movrz   %g1, %g2, %g3 ! encoding: [0x87,0x78,0x44,0x02]
 ! CHECK: movrz   %g1, %g2, %g3 ! encoding: [0x87,0x78,0x44,0x02]
 ! CHECK: movrlez %g1, %g2, %g3 ! encoding: [0x87,0x78,0x48,0x02]
 ! CHECK: movrlz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x4c,0x02]
 ! CHECK: movrnz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x54,0x02]
+! CHECK: movrnz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x54,0x02]
 ! CHECK: movrgz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x58,0x02]
 ! CHECK: movrgez %g1, %g2, %g3 ! encoding: [0x87,0x78,0x5c,0x02]
 movrz   %g1, %g2, %g3
+movre   %g1, %g2, %g3
 movrlez %g1, %g2, %g3
 movrlz  %g1, %g2, %g3
 movrnz  %g1, %g2, %g3
+movrne  %g1, %g2, %g3
 movrgz  %g1, %g2, %g3
 movrgez %g1, %g2, %g3
 
+! CHECK: movrz   %g1, 2, %g3 ! encoding: [0x87,0x78,0x64,0x02]
 ! CHECK: movrz   %g1, 2, %g3 ! encoding: [0x87,0x78,0x64,0x02]
 ! CHECK: movrlez %g1, 2, %g3 ! encoding: [0x87,0x78,0x68,0x02]
 ! CHECK: movrlz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x6c,0x02]
 ! CHECK: movrnz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x74,0x02]
+! CHECK: movrnz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x74,0x02]
 ! CHECK: movrgz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x78,0x02]
 ! CHECK: movrgez %g1, 2, %g3 ! encoding: [0x87,0x78,0x7c,0x02]
 movrz   %g1, 2, %g3
+movre   %g1, 2, %g3
 movrlez %g1, 2, %g3
 movrlz  %g1, 2, %g3
 movrnz  %g1, 2, %g3
+movrne  %g1, 2, %g3
 movrgz  %g1, 2, %g3
 movrgez %g1, 2, %g3
 

``




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


[llvm-branch-commits] [SPARC][IAS] Add movr(n)e alias for movr(n)z (PR #94252)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

This adds the alternate mnemonics for movrz and movrnz.


---
Full diff: https://github.com/llvm/llvm-project/pull/94252.diff


2 Files Affected:

- (modified) llvm/lib/Target/Sparc/SparcInstrAliases.td (+2) 
- (modified) llvm/test/MC/Sparc/sparc64-ctrl-instructions.s (+8) 


``diff
diff --git a/llvm/lib/Target/Sparc/SparcInstrAliases.td 
b/llvm/lib/Target/Sparc/SparcInstrAliases.td
index 2b9244519f154..eedad25737f65 100644
--- a/llvm/lib/Target/Sparc/SparcInstrAliases.td
+++ b/llvm/lib/Target/Sparc/SparcInstrAliases.td
@@ -400,9 +400,11 @@ defm : cp_cond_alias<"012",   0b>;
 let EmitPriority = 0 in defm : cp_cond_alias<"",  0b1000>; // same as a; 
gnu asm, not in manual
 
 defm : reg_cond_alias<"z",0b001>;
+defm : reg_cond_alias<"e",0b001>;
 defm : reg_cond_alias<"lez",  0b010>;
 defm : reg_cond_alias<"lz",   0b011>;
 defm : reg_cond_alias<"nz",   0b101>;
+defm : reg_cond_alias<"ne",   0b101>;
 defm : reg_cond_alias<"gz",   0b110>;
 defm : reg_cond_alias<"gez",  0b111>;
 
diff --git a/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s 
b/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s
index a21b17552eb15..188947314f4b7 100644
--- a/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s
+++ b/llvm/test/MC/Sparc/sparc64-ctrl-instructions.s
@@ -1190,29 +1190,37 @@
 ! CHECK-NEXT: !   fixup A - offset: 0, 
value: .BB0, kind: fixup_sparc_br16
 brz,a,pn   %g1, .BB0
 
+! CHECK: movrz   %g1, %g2, %g3 ! encoding: [0x87,0x78,0x44,0x02]
 ! CHECK: movrz   %g1, %g2, %g3 ! encoding: [0x87,0x78,0x44,0x02]
 ! CHECK: movrlez %g1, %g2, %g3 ! encoding: [0x87,0x78,0x48,0x02]
 ! CHECK: movrlz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x4c,0x02]
 ! CHECK: movrnz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x54,0x02]
+! CHECK: movrnz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x54,0x02]
 ! CHECK: movrgz  %g1, %g2, %g3 ! encoding: [0x87,0x78,0x58,0x02]
 ! CHECK: movrgez %g1, %g2, %g3 ! encoding: [0x87,0x78,0x5c,0x02]
 movrz   %g1, %g2, %g3
+movre   %g1, %g2, %g3
 movrlez %g1, %g2, %g3
 movrlz  %g1, %g2, %g3
 movrnz  %g1, %g2, %g3
+movrne  %g1, %g2, %g3
 movrgz  %g1, %g2, %g3
 movrgez %g1, %g2, %g3
 
+! CHECK: movrz   %g1, 2, %g3 ! encoding: [0x87,0x78,0x64,0x02]
 ! CHECK: movrz   %g1, 2, %g3 ! encoding: [0x87,0x78,0x64,0x02]
 ! CHECK: movrlez %g1, 2, %g3 ! encoding: [0x87,0x78,0x68,0x02]
 ! CHECK: movrlz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x6c,0x02]
 ! CHECK: movrnz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x74,0x02]
+! CHECK: movrnz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x74,0x02]
 ! CHECK: movrgz  %g1, 2, %g3 ! encoding: [0x87,0x78,0x78,0x02]
 ! CHECK: movrgez %g1, 2, %g3 ! encoding: [0x87,0x78,0x7c,0x02]
 movrz   %g1, 2, %g3
+movre   %g1, 2, %g3
 movrlez %g1, 2, %g3
 movrlz  %g1, 2, %g3
 movrnz  %g1, 2, %g3
+movrne  %g1, 2, %g3
 movrgz  %g1, 2, %g3
 movrgez %g1, 2, %g3
 

``




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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Koakuma (koachan)


Changes

This adds support for `prefetcha` instruction for prefetching from
alternate address spaces.


---
Full diff: https://github.com/llvm/llvm-project/pull/94250.diff


3 Files Affected:

- (modified) llvm/lib/Target/Sparc/SparcInstrInfo.td (+7) 
- (modified) llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt (+5) 
- (modified) llvm/test/MC/Sparc/sparcv9-instructions.s (+30) 


``diff
diff --git a/llvm/lib/Target/Sparc/SparcInstrInfo.td 
b/llvm/lib/Target/Sparc/SparcInstrInfo.td
index f1778f2162f8c..cac96a1398721 100644
--- a/llvm/lib/Target/Sparc/SparcInstrInfo.td
+++ b/llvm/lib/Target/Sparc/SparcInstrInfo.td
@@ -1782,6 +1782,13 @@ let Predicates = [HasV9] in {
   def PREFETCHi : F3_2<3, 0b101101,
(outs), (ins (MEMri $rs1, $simm13):$addr, PrefetchTag:$rd),
"prefetch [$addr], $rd", []>;
+  def PREFETCHAr : F3_1_asi<3, 0b01, (outs),
+(ins (MEMrr $rs1, $rs2):$addr, ASITag:$asi, 
PrefetchTag:$rd),
+"prefetcha [$addr] $asi, $rd", []>;
+  let Uses = [ASR3] in
+  def PREFETCHAi : F3_2<3, 0b01, (outs),
+(ins (MEMri $rs1, $simm13):$addr, PrefetchTag:$rd),
+"prefetcha [$addr] %asi, $rd", []>;
 }
 
 
diff --git a/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt 
b/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt
index 9286814552cf5..1d1fdb667fafa 100644
--- a/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt
+++ b/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt
@@ -32,3 +32,8 @@
 0xd5 0xf6 0x11 0x56
 # V9: casxa [%i0] #ASI_SNF_L, %l6, %o2
 0xd5 0xf6 0x11 0x76
+
+# V9: prefetcha  [%i1+3968] %asi, #one_read
+0xc3 0xee 0x6f 0x80
+# V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read
+0xc3 0xee 0x50 0x7a
diff --git a/llvm/test/MC/Sparc/sparcv9-instructions.s 
b/llvm/test/MC/Sparc/sparcv9-instructions.s
index f0348eb70f1c5..ae8646f8bc560 100644
--- a/llvm/test/MC/Sparc/sparcv9-instructions.s
+++ b/llvm/test/MC/Sparc/sparcv9-instructions.s
@@ -557,6 +557,36 @@
 ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
 prefetch  [ %i1 + %i2 ], #one_read
 
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + 0xf80 ] %asi, 1
+! V9: prefetcha [%i1+3968] %asi, #one_read! encoding: 
[0xc3,0xee,0x6f,0x80]
+prefetcha  [ %i1 + 0xf80 ] %asi, 1
+
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + 0xf80 ] %asi, #one_read
+! V9: prefetcha [%i1+3968] %asi, #one_read! encoding: 
[0xc3,0xee,0x6f,0x80]
+prefetcha  [ %i1 + 0xf80 ] %asi, #one_read
+
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] #ASI_SNF, 1
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] #ASI_SNF, 1
+
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] #ASI_SNF, #one_read
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] #ASI_SNF, #one_read
+
+! V8:  error: invalid operand for instruction
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] 131, 1
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] 131, 1
+
+! V8:  error: unexpected token
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] 131, #one_read
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] 131, #one_read
+
 ! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: done
 ! V9: done  ! encoding: [0x81,0xf0,0x00,0x00]

``




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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

This adds support for `prefetcha` instruction for prefetching from
alternate address spaces.


---
Full diff: https://github.com/llvm/llvm-project/pull/94250.diff


3 Files Affected:

- (modified) llvm/lib/Target/Sparc/SparcInstrInfo.td (+7) 
- (modified) llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt (+5) 
- (modified) llvm/test/MC/Sparc/sparcv9-instructions.s (+30) 


``diff
diff --git a/llvm/lib/Target/Sparc/SparcInstrInfo.td 
b/llvm/lib/Target/Sparc/SparcInstrInfo.td
index f1778f2162f8c..cac96a1398721 100644
--- a/llvm/lib/Target/Sparc/SparcInstrInfo.td
+++ b/llvm/lib/Target/Sparc/SparcInstrInfo.td
@@ -1782,6 +1782,13 @@ let Predicates = [HasV9] in {
   def PREFETCHi : F3_2<3, 0b101101,
(outs), (ins (MEMri $rs1, $simm13):$addr, PrefetchTag:$rd),
"prefetch [$addr], $rd", []>;
+  def PREFETCHAr : F3_1_asi<3, 0b01, (outs),
+(ins (MEMrr $rs1, $rs2):$addr, ASITag:$asi, 
PrefetchTag:$rd),
+"prefetcha [$addr] $asi, $rd", []>;
+  let Uses = [ASR3] in
+  def PREFETCHAi : F3_2<3, 0b01, (outs),
+(ins (MEMri $rs1, $simm13):$addr, PrefetchTag:$rd),
+"prefetcha [$addr] %asi, $rd", []>;
 }
 
 
diff --git a/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt 
b/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt
index 9286814552cf5..1d1fdb667fafa 100644
--- a/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt
+++ b/llvm/test/MC/Disassembler/Sparc/sparc-v9-asi.txt
@@ -32,3 +32,8 @@
 0xd5 0xf6 0x11 0x56
 # V9: casxa [%i0] #ASI_SNF_L, %l6, %o2
 0xd5 0xf6 0x11 0x76
+
+# V9: prefetcha  [%i1+3968] %asi, #one_read
+0xc3 0xee 0x6f 0x80
+# V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read
+0xc3 0xee 0x50 0x7a
diff --git a/llvm/test/MC/Sparc/sparcv9-instructions.s 
b/llvm/test/MC/Sparc/sparcv9-instructions.s
index f0348eb70f1c5..ae8646f8bc560 100644
--- a/llvm/test/MC/Sparc/sparcv9-instructions.s
+++ b/llvm/test/MC/Sparc/sparcv9-instructions.s
@@ -557,6 +557,36 @@
 ! V9: prefetch  [%i1+%i2], #one_read  ! encoding: [0xc3,0x6e,0x40,0x1a]
 prefetch  [ %i1 + %i2 ], #one_read
 
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + 0xf80 ] %asi, 1
+! V9: prefetcha [%i1+3968] %asi, #one_read! encoding: 
[0xc3,0xee,0x6f,0x80]
+prefetcha  [ %i1 + 0xf80 ] %asi, 1
+
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + 0xf80 ] %asi, #one_read
+! V9: prefetcha [%i1+3968] %asi, #one_read! encoding: 
[0xc3,0xee,0x6f,0x80]
+prefetcha  [ %i1 + 0xf80 ] %asi, #one_read
+
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] #ASI_SNF, 1
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] #ASI_SNF, 1
+
+! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] #ASI_SNF, #one_read
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] #ASI_SNF, #one_read
+
+! V8:  error: invalid operand for instruction
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] 131, 1
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] 131, 1
+
+! V8:  error: unexpected token
+! V8-NEXT: prefetcha  [ %i1 + %i2 ] 131, #one_read
+! V9: prefetcha [%i1+%i2] #ASI_SNF, #one_read ! encoding: 
[0xc3,0xee,0x50,0x7a]
+prefetcha  [ %i1 + %i2 ] 131, #one_read
+
 ! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: done
 ! V9: done  ! encoding: [0x81,0xf0,0x00,0x00]

``




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


[llvm-branch-commits] [SPARC][IAS] Add movr(n)e alias for movr(n)z (PR #94252)

2024-06-03 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/94252

This adds the alternate mnemonics for movrz and movrnz.



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


[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

This adds named tag constants (such as `#one_write` and `#one_read`)
for the prefetch instruction.


---
Full diff: https://github.com/llvm/llvm-project/pull/94249.diff


11 Files Affected:

- (modified) llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (+56-1) 
- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp (+11) 
- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h (+2) 
- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp (+5) 
- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.h (+11) 
- (modified) llvm/lib/Target/Sparc/Sparc.td (+2) 
- (modified) llvm/lib/Target/Sparc/SparcASITags.td (-2) 
- (modified) llvm/lib/Target/Sparc/SparcInstrInfo.td (+12-2) 
- (added) llvm/lib/Target/Sparc/SparcPrefetchTags.td (+41) 
- (modified) llvm/test/MC/Disassembler/Sparc/sparc-v9.txt (+2-2) 
- (modified) llvm/test/MC/Sparc/sparcv9-instructions.s (+14-4) 


``diff
diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp 
b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index e4f5c64f9d00e..a0dec24e3200a 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -91,6 +91,8 @@ class SparcAsmParser : public MCTargetAsmParser {
 
   ParseStatus parseASITag(OperandVector );
 
+  ParseStatus parsePrefetchTag(OperandVector );
+
   template 
   ParseStatus parseTailRelocSym(OperandVector );
 
@@ -209,7 +211,8 @@ class SparcOperand : public MCParsedAsmOperand {
 k_Immediate,
 k_MemoryReg,
 k_MemoryImm,
-k_ASITag
+k_ASITag,
+k_PrefetchTag,
   } Kind;
 
   SMLoc StartLoc, EndLoc;
@@ -240,6 +243,7 @@ class SparcOperand : public MCParsedAsmOperand {
 struct ImmOp Imm;
 struct MemOp Mem;
 unsigned ASI;
+unsigned Prefetch;
   };
 
 public:
@@ -253,6 +257,7 @@ class SparcOperand : public MCParsedAsmOperand {
   bool isMEMri() const { return Kind == k_MemoryImm; }
   bool isMembarTag() const { return Kind == k_Immediate; }
   bool isASITag() const { return Kind == k_ASITag; }
+  bool isPrefetchTag() const { return Kind == k_PrefetchTag; }
   bool isTailRelocSym() const { return Kind == k_Immediate; }
 
   bool isCallTarget() const {
@@ -337,6 +342,11 @@ class SparcOperand : public MCParsedAsmOperand {
 return ASI;
   }
 
+  unsigned getPrefetchTag() const {
+assert((Kind == k_PrefetchTag) && "Invalid access!");
+return Prefetch;
+  }
+
   /// getStartLoc - Get the location of the first token of this operand.
   SMLoc getStartLoc() const override {
 return StartLoc;
@@ -360,6 +370,9 @@ class SparcOperand : public MCParsedAsmOperand {
 case k_ASITag:
   OS << "ASI tag: " << getASITag() << "\n";
   break;
+case k_PrefetchTag:
+  OS << "Prefetch tag: " << getPrefetchTag() << "\n";
+  break;
 }
   }
 
@@ -416,6 +429,11 @@ class SparcOperand : public MCParsedAsmOperand {
 Inst.addOperand(MCOperand::createImm(getASITag()));
   }
 
+  void addPrefetchTagOperands(MCInst , unsigned N) const {
+assert(N == 1 && "Invalid number of operands!");
+Inst.addOperand(MCOperand::createImm(getPrefetchTag()));
+  }
+
   void addMembarTagOperands(MCInst , unsigned N) const {
 assert(N == 1 && "Invalid number of operands!");
 const MCExpr *Expr = getImm();
@@ -469,6 +487,15 @@ class SparcOperand : public MCParsedAsmOperand {
 return Op;
   }
 
+  static std::unique_ptr CreatePrefetchTag(unsigned Val, SMLoc S,
+ SMLoc E) {
+auto Op = std::make_unique(k_PrefetchTag);
+Op->Prefetch = Val;
+Op->StartLoc = S;
+Op->EndLoc = E;
+return Op;
+  }
+
   static bool MorphToIntPairReg(SparcOperand ) {
 unsigned Reg = Op.getReg();
 assert(Op.Reg.Kind == rk_IntReg);
@@ -1088,6 +1115,34 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector 
) {
   return ParseStatus::Success;
 }
 
+ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector ) {
+  SMLoc S = Parser.getTok().getLoc();
+  SMLoc E = Parser.getTok().getEndLoc();
+  int64_t PrefetchVal = 0;
+
+  if (getLexer().getKind() == AsmToken::Hash) {
+SMLoc TagStart = getLexer().peekTok(false).getLoc();
+Parser.Lex(); // Eat the '#'.
+auto PrefetchName = Parser.getTok().getString();
+auto PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
+Parser.Lex(); // Eat the identifier token.
+
+if (!PrefetchTag)
+  return Error(TagStart, "unknown prefetch tag");
+
+PrefetchVal = PrefetchTag->Encoding;
+  } else if (!getParser().parseAbsoluteExpression(PrefetchVal)) {
+if (!isUInt<5>(PrefetchVal))
+  return Error(S, "invalid prefetch number, must be between 0 and 31");
+  } else {
+return Error(S, "malformed prefetch tag, must be a constant integer "
+"expression, or a named tag");
+  }
+
+  

[llvm-branch-commits] [clang] [clang][test] add testing for the AST matcher reference (PR #94248)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Julian Schmidt (5chmidti)


Changes

Previously, the examples in the AST matcher reference, which gets generated by 
the doxygen comments in `ASTMatchers.h`, were untested and best effort.
Some of the matchers had no or wrong examples of how to use the matcher.

This patch introduces a simple DSL around doxygen commands to enable testing 
the AST matcher documentation in a way that should be relatively easy.
In `ASTMatchers.h`, most matchers are documented with a doxygen comment. Most 
of these also have a code example that aims to show what the matcher will 
match, given a matcher somewhere in the documentation text. The way that 
testing the documentation is done, is by using doxygens alias feature to 
declare custom aliases. These aliases forward to `tttext/tt` 
(which is what doxygens \c does, but for multiple words). Using the doxygen 
aliases was the obvious choice, because there are (now) four consumers:
 - people reading the header/using signature help
 - the doxygen generated documentation
 - the generated html AST matcher reference
 - (new) the generated matcher tests

This patch rewrites/extends the documentation such that all matchers have a 
documented example.
The new `generate_ast_matcher_doc_tests.py` script will warn on any 
undocumented matchers (but not on matchers without a doxygen comment) and 
provides diagnostics and statistics about the matchers. Below is a file-level 
comment from the test generation script that describes how documenting matchers 
to be tested works on a slightly more technical level. In general, the new 
comments can be used as a reference for how to implement a tested documentation.

The current statistics emitted by the parser are:

```text
Statistics:
doxygen_blocks:   519
missing_tests :10
skipped_objc  :42
code_snippets :   503
matches   :   820
matchers  :   580
tested_matchers   :   574
none_type_matchers: 6
```

The tests are generated during building and the script will only print 
something if it found an issue (compile failure, parsing issues, the expected 
and actual number of failures differs).

DSL for generating the tests from documentation.

TLDR:
The order for a single code snippet example is:

  \header{a.h}
  \endheader - zero or more header

  \code
int a = 42;
  \endcode
  \compile_args{-std=c++,c23-or-later} - optional, supports std ranges and
  whole languages

  \matcher{expr()} - one or more matchers in succession
  \match{42}   - one or more matches in succession

  \matcher{varDecl()} - new matcher resets the context, the above
 \match will not count for this new
 matcher(-group)
  \match{int a  = 42} - only applies to the previous matcher (no the
 previous case)

The above block can be repeated inside a doxygen command for multiple code 
examples.

Language Grammar:
  [] denotes an optional, and  denotes user-input

  compile_args j:= \compile_args{[compile_arg;]compile_arg}
  matcher_tag_key ::= type
  match_tag_key ::= type || std || count
  matcher_tags ::= [matcher_tag_key=value;]matcher_tag_key=value
  match_tags ::= [match_tag_key=value;]match_tag_key=value
  matcher ::= \matcher{[matcher_tags$]matcher}
  matchers ::= [matcher] matcher
  match ::= \match{[match_tags$]match}
  matches ::= [match] match
  case ::= matchers matches
  cases ::= [case] case
  header-block ::= \header{name} code \endheader
  code-block ::= \code code \endcode
  testcase ::= code-block [compile_args] cases

The 'std' tag and '\compile_args' support specifying a specific language 
version, a whole language and all of its versions, and thresholds (implies 
ranges). Multiple arguments are passed with a ',' separator. For a language and 
version to execute a tested matcher, it has to match the specified 
'\compile_args' for the code, and the 'std' tag for the matcher. Predicates for 
the 'std' compiler flag are used with disjunction between languages (e.g. 'c || 
c++') and conjunction for all predicates specific to each language (e.g. 
'c++11-or-later  c++23-or-earlier').

Examples:
 - call available versions of C
 - c++11only C++11
 - c++11-or-later   C++11 or later
 - c++11-or-earlier C++11 or earlier
 - c++11-or-later,c++23-or-earlier,call of C and C++ between 11 and
  23 (inclusive)
 - c++11-23,c same as above

Tags:

  Type:
  Match types are used to select where the string that is used to check if
  a node matches comes from.
  Available: code, name, typestr, typeofstr.
  The default is 'code'.

  

[llvm-branch-commits] [SPARC][IAS] Add aliases for %asr20-21 as defined in JPS1 (PR #94247)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

This adds %set_softint and %clear_softint alias for %asr20 and %asr21
as defined in JPS1.


---
Full diff: https://github.com/llvm/llvm-project/pull/94247.diff


2 Files Affected:

- (modified) llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (+9-2) 
- (modified) llvm/test/MC/Sparc/sparcv9-instructions.s (+4) 


``diff
diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp 
b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index 185b2fe90c6cb..e4f5c64f9d00e 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -1384,12 +1384,11 @@ MCRegister SparcAsmParser::matchRegisterName(const 
AsmToken ,
   }
 
   // JPS1 extension - aliases for ASRs
-  // Section A.51 - Read State Register
+  // Section 5.2.11 - Ancillary State Registers (ASRs)
   if (Name == "pcr") {
 RegKind = SparcOperand::rk_Special;
 return SP::ASR16;
   }
-
   if (Name == "pic") {
 RegKind = SparcOperand::rk_Special;
 return SP::ASR17;
@@ -1402,6 +1401,14 @@ MCRegister SparcAsmParser::matchRegisterName(const 
AsmToken ,
 RegKind = SparcOperand::rk_Special;
 return SP::ASR19;
   }
+  if (Name == "set_softint") {
+RegKind = SparcOperand::rk_Special;
+return SP::ASR20;
+  }
+  if (Name == "clear_softint") {
+RegKind = SparcOperand::rk_Special;
+return SP::ASR21;
+  }
   if (Name == "softint") {
 RegKind = SparcOperand::rk_Special;
 return SP::ASR22;
diff --git a/llvm/test/MC/Sparc/sparcv9-instructions.s 
b/llvm/test/MC/Sparc/sparcv9-instructions.s
index b947243f8258f..d461c82467471 100644
--- a/llvm/test/MC/Sparc/sparcv9-instructions.s
+++ b/llvm/test/MC/Sparc/sparcv9-instructions.s
@@ -502,6 +502,10 @@
 wr %i0, %i1, %ccr
 ! V9: wr %i0, 1, %ccr   ! encoding: [0x85,0x86,0x20,0x01]
 wr %i0, 1, %ccr
+! V9: wr %i0, 1, %asr20 ! encoding: [0xa9,0x86,0x20,0x01]
+wr %i0, 1, %set_softint
+! V9: wr %i0, 1, %asr21 ! encoding: [0xab,0x86,0x20,0x01]
+wr %i0, 1, %clear_softint
 
 ! V9: st %o1, [%o0] ! encoding: [0xd2,0x22,0x00,0x00]
 stw %o1, [%o0]

``




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


[llvm-branch-commits] [SPARC][IAS] Handle the case of non-4-byte aligned writeNopData (PR #94251)

2024-06-03 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/94251

If the Count passed into writeNopData is not a multiple of four,
add a little amount of zeros before writing the NOP stream.
This makes it match the behavior of GNU binutils.



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


[llvm-branch-commits] [SPARC][IAS] Add support for `prefetcha` instruction (PR #94250)

2024-06-03 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/94250

This adds support for `prefetcha` instruction for prefetching from
alternate address spaces.



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


[llvm-branch-commits] [SPARC][IAS] Add support for %uhi and %ulo extensions (PR #94246)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

This adds support for GNU %uhi and %ulo extensions.
Those resolve to the same relocations as %hh and %hm.


---
Full diff: https://github.com/llvm/llvm-project/pull/94246.diff


2 Files Affected:

- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp (+40-38) 
- (modified) llvm/test/MC/Sparc/sparc-relocations.s (+10) 


``diff
diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp 
b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
index 522a8877a1c60..4688837e435e5 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp
@@ -93,44 +93,46 @@ bool SparcMCExpr::printVariantKind(raw_ostream , 
VariantKind Kind)
 SparcMCExpr::VariantKind SparcMCExpr::parseVariantKind(StringRef name)
 {
   return StringSwitch(name)
-.Case("lo",  VK_Sparc_LO)
-.Case("hi",  VK_Sparc_HI)
-.Case("h44", VK_Sparc_H44)
-.Case("m44", VK_Sparc_M44)
-.Case("l44", VK_Sparc_L44)
-.Case("hh",  VK_Sparc_HH)
-.Case("hm",  VK_Sparc_HM)
-.Case("lm",  VK_Sparc_LM)
-.Case("pc22",  VK_Sparc_PC22)
-.Case("pc10",  VK_Sparc_PC10)
-.Case("got22", VK_Sparc_GOT22)
-.Case("got10", VK_Sparc_GOT10)
-.Case("got13", VK_Sparc_GOT13)
-.Case("r_disp32",   VK_Sparc_R_DISP32)
-.Case("tgd_hi22",   VK_Sparc_TLS_GD_HI22)
-.Case("tgd_lo10",   VK_Sparc_TLS_GD_LO10)
-.Case("tgd_add",VK_Sparc_TLS_GD_ADD)
-.Case("tgd_call",   VK_Sparc_TLS_GD_CALL)
-.Case("tldm_hi22",  VK_Sparc_TLS_LDM_HI22)
-.Case("tldm_lo10",  VK_Sparc_TLS_LDM_LO10)
-.Case("tldm_add",   VK_Sparc_TLS_LDM_ADD)
-.Case("tldm_call",  VK_Sparc_TLS_LDM_CALL)
-.Case("tldo_hix22", VK_Sparc_TLS_LDO_HIX22)
-.Case("tldo_lox10", VK_Sparc_TLS_LDO_LOX10)
-.Case("tldo_add",   VK_Sparc_TLS_LDO_ADD)
-.Case("tie_hi22",   VK_Sparc_TLS_IE_HI22)
-.Case("tie_lo10",   VK_Sparc_TLS_IE_LO10)
-.Case("tie_ld", VK_Sparc_TLS_IE_LD)
-.Case("tie_ldx",VK_Sparc_TLS_IE_LDX)
-.Case("tie_add",VK_Sparc_TLS_IE_ADD)
-.Case("tle_hix22",  VK_Sparc_TLS_LE_HIX22)
-.Case("tle_lox10",  VK_Sparc_TLS_LE_LOX10)
-.Case("hix",VK_Sparc_HIX22)
-.Case("lox",VK_Sparc_LOX10)
-.Case("gdop_hix22", VK_Sparc_GOTDATA_HIX22)
-.Case("gdop_lox10", VK_Sparc_GOTDATA_LOX10)
-.Case("gdop",   VK_Sparc_GOTDATA_OP)
-.Default(VK_Sparc_None);
+  .Case("lo", VK_Sparc_LO)
+  .Case("hi", VK_Sparc_HI)
+  .Case("h44", VK_Sparc_H44)
+  .Case("m44", VK_Sparc_M44)
+  .Case("l44", VK_Sparc_L44)
+  .Case("hh", VK_Sparc_HH)
+  .Case("uhi", VK_Sparc_HH) // Nonstandard GNU extension
+  .Case("hm", VK_Sparc_HM)
+  .Case("ulo", VK_Sparc_HM) // Nonstandard GNU extension
+  .Case("lm", VK_Sparc_LM)
+  .Case("pc22", VK_Sparc_PC22)
+  .Case("pc10", VK_Sparc_PC10)
+  .Case("got22", VK_Sparc_GOT22)
+  .Case("got10", VK_Sparc_GOT10)
+  .Case("got13", VK_Sparc_GOT13)
+  .Case("r_disp32", VK_Sparc_R_DISP32)
+  .Case("tgd_hi22", VK_Sparc_TLS_GD_HI22)
+  .Case("tgd_lo10", VK_Sparc_TLS_GD_LO10)
+  .Case("tgd_add", VK_Sparc_TLS_GD_ADD)
+  .Case("tgd_call", VK_Sparc_TLS_GD_CALL)
+  .Case("tldm_hi22", VK_Sparc_TLS_LDM_HI22)
+  .Case("tldm_lo10", VK_Sparc_TLS_LDM_LO10)
+  .Case("tldm_add", VK_Sparc_TLS_LDM_ADD)
+  .Case("tldm_call", VK_Sparc_TLS_LDM_CALL)
+  .Case("tldo_hix22", VK_Sparc_TLS_LDO_HIX22)
+  .Case("tldo_lox10", VK_Sparc_TLS_LDO_LOX10)
+  .Case("tldo_add", VK_Sparc_TLS_LDO_ADD)
+  .Case("tie_hi22", VK_Sparc_TLS_IE_HI22)
+  .Case("tie_lo10", VK_Sparc_TLS_IE_LO10)
+  .Case("tie_ld", VK_Sparc_TLS_IE_LD)
+  .Case("tie_ldx", VK_Sparc_TLS_IE_LDX)
+  .Case("tie_add", VK_Sparc_TLS_IE_ADD)
+  .Case("tle_hix22", VK_Sparc_TLS_LE_HIX22)
+  .Case("tle_lox10", VK_Sparc_TLS_LE_LOX10)
+  .Case("hix", VK_Sparc_HIX22)
+  .Case("lox", VK_Sparc_LOX10)
+  .Case("gdop_hix22", VK_Sparc_GOTDATA_HIX22)
+  .Case("gdop_lox10", VK_Sparc_GOTDATA_LOX10)
+  .Case("gdop", VK_Sparc_GOTDATA_OP)
+  .Default(VK_Sparc_None);
 }
 
 Sparc::Fixups SparcMCExpr::getFixupKind(SparcMCExpr::VariantKind Kind) {
diff --git a/llvm/test/MC/Sparc/sparc-relocations.s 
b/llvm/test/MC/Sparc/sparc-relocations.s
index d99ddb7e2f802..82314e440acf6 100644
--- a/llvm/test/MC/Sparc/sparc-relocations.s
+++ b/llvm/test/MC/Sparc/sparc-relocations.s
@@ -10,6 +10,8 @@
 ! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} R_SPARC_M44 sym
 ! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} R_SPARC_L44 sym
 ! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} R_SPARC_HH22 sym
+! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} R_SPARC_HH22 sym
+! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} R_SPARC_HM10 sym
 ! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} R_SPARC_HM10 sym
 ! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} R_SPARC_LM22 sym
 ! CHECK-OBJ-NEXT: 0x{{[0-9,A-F]+}} 

[llvm-branch-commits] [SPARC][IAS] Add named prefetch tag constants (PR #94249)

2024-06-03 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/94249

This adds named tag constants (such as `#one_write` and `#one_read`)
for the prefetch instruction.



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


[llvm-branch-commits] [SPARC][IAS] Add aliases for %asr20-21 as defined in JPS1 (PR #94247)

2024-06-03 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/94247

This adds %set_softint and %clear_softint alias for %asr20 and %asr21
as defined in JPS1.



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


[llvm-branch-commits] [SPARC][IAS] Add support for %uhi and %ulo extensions (PR #94246)

2024-06-03 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/94246

This adds support for GNU %uhi and %ulo extensions.
Those resolve to the same relocations as %hh and %hm.



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


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-06-03 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Julian Schmidt (5chmidti)


Changes

The overload that did not take the additional `ASTContext *` argument is 
unnecessary when the context could simply be commented out, as it is always 
passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a single 
overload.

---
Full diff: https://github.com/llvm/llvm-project/pull/94244.diff


3 Files Affected:

- (modified) clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (-2) 
- (modified) clang/unittests/ASTMatchers/ASTMatchersTest.h (+1-6) 
- (modified) clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (+3-6) 


``diff
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index aed6a6408adc9..dd98fbdce3945 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e981299531574..ad2f5f355621c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap  = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ada3be287ed59..6bb402caa4d6d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5641,7 +5641,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5850,16 +5849,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher ,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;

``




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


[llvm-branch-commits] [clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #94244)

2024-06-03 Thread Julian Schmidt via llvm-branch-commits

https://github.com/5chmidti created 
https://github.com/llvm/llvm-project/pull/94244

The overload that did not take the additional `ASTContext *` argument is 
unnecessary when the context could simply be commented out, as it is always 
passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a single 
overload.

>From 0c53f15ee5461f479bd8da88f1fba2aecad6430a Mon Sep 17 00:00:00 2001
From: Julian Schmidt 
Date: Sat, 1 Jun 2024 17:49:13 +0200
Subject: [PATCH] [clang][test] remove unused `run` overload in
 `BoundNodesCallback`

The overload that did not take the additional `ASTContext *` argument is
unnecessary when the context could simply be commented out, as it is
always passed to `run` from `VerifyMatcher::run`.
This patch removes the single-argument overload in favor of having a
single overload.
---
 clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp  | 2 --
 clang/unittests/ASTMatchers/ASTMatchersTest.h| 7 +--
 clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 9 +++--
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index aed6a6408adc9..dd98fbdce3945 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2030,8 +2030,6 @@ TEST_P(ASTMatchersTest,
 template 
 class VerifyAncestorHasChildIsEqual : public BoundNodesCallback {
 public:
-  bool run(const BoundNodes *Nodes) override { return false; }
-
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs("");
 return verify(*Nodes, *Context, Node);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e981299531574..ad2f5f355621c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -28,7 +28,6 @@ using clang::tooling::runToolOnCodeWithArgs;
 class BoundNodesCallback {
 public:
   virtual ~BoundNodesCallback() {}
-  virtual bool run(const BoundNodes *BoundNodes) = 0;
   virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0;
   virtual void onEndOfTranslationUnit() {}
 };
@@ -403,7 +402,7 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 EXPECT_EQ("", Name);
   }
 
-  bool run(const BoundNodes *Nodes) override {
+  bool run(const BoundNodes *Nodes, ASTContext * /*Context*/) override {
 const BoundNodes::IDToNodeMap  = Nodes->getMap();
 if (Nodes->getNodeAs(Id)) {
   ++Count;
@@ -426,10 +425,6 @@ template  class VerifyIdIsBoundTo : public 
BoundNodesCallback {
 return false;
   }
 
-  bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-return run(Nodes);
-  }
-
 private:
   const std::string Id;
   const int ExpectedCount;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ada3be287ed59..6bb402caa4d6d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5641,7 +5641,6 @@ TEST(HasParent, MatchesAllParents) {
 TEST(HasParent, NoDuplicateParents) {
   class HasDuplicateParents : public BoundNodesCallback {
   public:
-bool run(const BoundNodes *Nodes) override { return false; }
 bool run(const BoundNodes *Nodes, ASTContext *Context) override {
   const Stmt *Node = Nodes->getNodeAs("node");
   std::set Parents;
@@ -5850,16 +5849,14 @@ template  class VerifyMatchOnNode : public 
BoundNodesCallback {
 public:
   VerifyMatchOnNode(StringRef Id, const internal::Matcher ,
 StringRef InnerId)
-: Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {
-  }
-
-  bool run(const BoundNodes *Nodes) override { return false; }
+  : Id(Id), InnerMatcher(InnerMatcher), InnerId(InnerId) {}
 
   bool run(const BoundNodes *Nodes, ASTContext *Context) override {
 const T *Node = Nodes->getNodeAs(Id);
 return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) !=
-  nullptr;
+   nullptr;
   }
+
 private:
   std::string Id;
   internal::Matcher InnerMatcher;

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


[llvm-branch-commits] [clang] [Serialization] No transitive identifier change (PR #92085)

2024-06-03 Thread Chuanqi Xu via llvm-branch-commits

ChuanqiXu9 wrote:

@jansvoboda11 ping. Did my answers resolve your concerns?

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