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

Daniil Kovalev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jun 7 03:47:05 PDT 2024


================
@@ -0,0 +1,63 @@
+//===--- 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 "CodeGenModule.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
+
+using namespace clang;
+using namespace CodeGen;
+
+/// Build a signed-pointer "ptrauth" constant.
+static llvm::ConstantPtrAuth *
+buildConstantAddress(CodeGenModule &CGM, llvm::Constant *Pointer, unsigned Key,
+                     llvm::Constant *StorageAddress,
+                     llvm::Constant *OtherDiscriminator) {
+  llvm::Constant *AddressDiscriminator = nullptr;
----------------
kovdan01 wrote:

Do we need to set this to `nullptr`? We 100% define this in either `if` or `else` branch and do not use the unitialized value before. Same applies to `IntegerDiscriminator` below.

You can also use smth like

```
llvm::Constant *AddressDiscriminator =
      (StorageAddress ? StorageAddress
                      : llvm::Constant::getNullValue(CGM.UnqualPtrTy));
  assert(!StorageAddress || (StorageAddress->getType() == CGM.UnqualPtrTy));
```

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


More information about the llvm-branch-commits mailing list