aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed@bougacha.org>2024-06-20 11:55:41 -0700
committerGitHub <noreply@github.com>2024-06-20 11:55:41 -0700
commit50b919378186ebb59e2dd402720f6ea8576d2477 (patch)
tree21c1a6f6ab03a81881d81eb46d5c8a10d211b185 /clang/lib/Sema/SemaChecking.cpp
parent99f5fcb0d1e04125daa404ff14c9cd14b7a2c40b (diff)
downloadllvm-50b919378186ebb59e2dd402720f6ea8576d2477.zip
llvm-50b919378186ebb59e2dd402720f6ea8576d2477.tar.gz
llvm-50b919378186ebb59e2dd402720f6ea8576d2477.tar.bz2
[clang] Define ptrauth_string_discriminator builtin. (#93903)
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. The argument must be a string literal of char character type. The result has type ptrauth_extra_data_t. The result value is never zero and always within range for both the __ptrauth qualifier and ptrauth_blend_discriminator. This can be used in constant expressions. Co-authored-by: John McCall <rjmccall@apple.com>
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 07cd072..60a7a38 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2166,6 +2166,24 @@ static ExprResult PointerAuthAuthAndResign(Sema &S, CallExpr *Call) {
return Call;
}
+static ExprResult PointerAuthStringDiscriminator(Sema &S, CallExpr *Call) {
+ if (checkPointerAuthEnabled(S, Call))
+ return ExprError();
+
+ // We've already performed normal call type-checking.
+ const Expr *Arg = Call->getArg(0)->IgnoreParenImpCasts();
+
+ // Operand must be an ordinary or UTF-8 string literal.
+ const auto *Literal = dyn_cast<StringLiteral>(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;
+}
+
static ExprResult BuiltinLaunder(Sema &S, CallExpr *TheCall) {
if (S.checkArgCount(TheCall, 1))
return ExprError();
@@ -2933,6 +2951,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
return PointerAuthSignGenericData(*this, TheCall);
case Builtin::BI__builtin_ptrauth_auth_and_resign:
return PointerAuthAuthAndResign(*this, TheCall);
+ case Builtin::BI__builtin_ptrauth_string_discriminator:
+ return PointerAuthStringDiscriminator(*this, TheCall);
// OpenCL v2.0, s6.13.16 - Pipe functions
case Builtin::BIread_pipe:
case Builtin::BIwrite_pipe: