[clang] [Clang][ARM] Call constructor on BranchTargetInfo. (PR #98307)

Daniel Kiss via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 10 07:02:41 PDT 2024


https://github.com/DanielKristofKiss updated https://github.com/llvm/llvm-project/pull/98307

>From 4e10c95c390e519853428f424cd655379d99c61c Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Wed, 10 Jul 2024 13:58:52 +0200
Subject: [PATCH 1/2] [Clang][ARM] Call constructor on BranchTargetInfo.

Otherwise members will be uninitialised.
---
 clang/lib/CodeGen/Targets/ARM.cpp | 2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/ARM.cpp b/clang/lib/CodeGen/Targets/ARM.cpp
index d449b97cdc685..93fea94a77248 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -141,7 +141,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
       ParsedTargetAttr Attr =
           CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
       if (!Attr.BranchProtection.empty()) {
-        TargetInfo::BranchProtectionInfo BPI;
+        TargetInfo::BranchProtectionInfo BPI{};
         StringRef DiagMsg;
         StringRef Arch =
             Attr.CPU.empty() ? CGM.getTarget().getTargetOpts().CPU : Attr.CPU;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 73a85ff39667b..f2cd46d1e7c93 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2991,7 +2991,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
              << Unsupported << None << CurFeature << Target;
   }
 
-  TargetInfo::BranchProtectionInfo BPI;
+  TargetInfo::BranchProtectionInfo BPI{};
   StringRef DiagMsg;
   if (ParsedAttrs.BranchProtection.empty())
     return false;

>From 4dfab4b3e6dca97ddc0348bcfbea7609170a3078 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Wed, 10 Jul 2024 16:01:47 +0200
Subject: [PATCH 2/2] Initialize members from the constructor.

---
 clang/include/clang/Basic/TargetInfo.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 1f208b40f92cb..079c71d10525f 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1434,7 +1434,14 @@ class TargetInfo : public TransferrableTargetInfo,
     }
 
   public:
-    BranchProtectionInfo() = default;
+    BranchProtectionInfo() {
+      SignReturnAddr = LangOptions::SignReturnAddressScopeKind::None;
+      SignKey = LangOptions::SignReturnAddressKeyKind::AKey;
+      BranchTargetEnforcement = false;
+      BranchProtectionPAuthLR = false;
+      GuardedControlStack = false;
+    };
+
     BranchProtectionInfo(const LangOptions &LangOpts) {
       SignReturnAddr =
           LangOpts.hasSignReturnAddress()



More information about the cfe-commits mailing list