-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang][ARM] Call constructor on BranchTargetInfo. #98307
Conversation
Otherwise members will be uninitialised.
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Daniel Kiss (DanielKristofKiss) ChangesOtherwise members will be uninitialised. Full diff: https://github.com/llvm/llvm-project/pull/98307.diff 2 Files Affected:
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;
|
Can something be done to prevent this happening accidentally again? |
+1. Currently, the struct is initialised with: |
IIRC there is a clang-tidy check that diagnoses uninitialized PODs, but probably making the constructor non-trivial is simpler / more reliable. |
Whatever the solution is, it would be better off done now, as "in future" is likely to get forgotten. |
Let's initialise everything from both of the constructors (as it was in an early version of the original patches) |
BranchProtectionInfo() { | ||
SignReturnAddr = LangOptions::SignReturnAddressScopeKind::None; | ||
SignKey = LangOptions::SignReturnAddressKeyKind::AKey; | ||
BranchTargetEnforcement = false; | ||
BranchProtectionPAuthLR = false; | ||
GuardedControlStack = false; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BranchProtectionInfo() { | |
SignReturnAddr = LangOptions::SignReturnAddressScopeKind::None; | |
SignKey = LangOptions::SignReturnAddressKeyKind::AKey; | |
BranchTargetEnforcement = false; | |
BranchProtectionPAuthLR = false; | |
GuardedControlStack = false; | |
}; | |
BranchProtectionInfo() : | |
SignReturnAddr(LangOptions::SignReturnAddressScopeKind::None), | |
SignKey(LangOptions::SignReturnAddressKeyKind::AKey), | |
BranchTargetEnforcement(false), | |
BranchProtectionPAuthLR(false), | |
GuardedControlStack(false) | |
{} |
This is more likely to show up warnings if something gets missed or reordered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, added and clang-formated.
@@ -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{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are unnecessary now, right? Making them explicit is fine though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, now unnecessary, maybe more stylish.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/1294 Here is the relevant piece of the build log for the reference:
|
Otherwise members will be uninitialised.
Otherwise members will be uninitialised.