-
Notifications
You must be signed in to change notification settings - Fork 15.5k
WIP warning #172186
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
Draft
ojhunt
wants to merge
2
commits into
main
Choose a base branch
from
users/ojhunt/warning-on-weak-global-ptrauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP warning #172186
+60
−25
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang/include/clang/AST/ASTContext.h clang/lib/AST/ASTContext.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaDecl.cpp clang/test/SemaCXX/ptrauth-type-traits.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index bfa3ddebf..f6c7e8020 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -696,7 +696,9 @@ public:
bool containsAddressDiscriminatedPointerAuth(QualType T) const {
if (!isPointerAuthenticationAvailable())
return false;
- return (findPointerAuthContent(T) & PointerAuthContent::ContainsAddressDiscriminatedData) != PointerAuthContent::ContainsNone;
+ return (findPointerAuthContent(T) &
+ PointerAuthContent::ContainsAddressDiscriminatedData) !=
+ PointerAuthContent::ContainsNone;
}
/// Examines a given type, and returns whether the type itself
@@ -707,13 +709,17 @@ public:
bool containsNonRelocatablePointerAuth(QualType T) {
if (!isPointerAuthenticationAvailable())
return false;
- return (findPointerAuthContent(T) & PointerAuthContent::ContainsAddressDiscriminatedData) != PointerAuthContent::ContainsNone;
+ return (findPointerAuthContent(T) &
+ PointerAuthContent::ContainsAddressDiscriminatedData) !=
+ PointerAuthContent::ContainsNone;
}
bool containsDefaultAuthenticatedFunctionPointer(QualType T) {
if (!isPointerAuthenticationAvailable())
return false;
- return (findPointerAuthContent(T) & PointerAuthContent::ContainsDefaultAuthenticatedFunction) != PointerAuthContent::ContainsNone;
+ return (findPointerAuthContent(T) &
+ PointerAuthContent::ContainsDefaultAuthenticatedFunction) !=
+ PointerAuthContent::ContainsNone;
}
// A simple helper function to short circuit pointer auth checks.
@@ -731,8 +737,11 @@ private:
ContainsAddressDiscriminatedVTable = 1 << 0,
ContainsAddressDiscriminatedData = 1 << 1,
ContainsDefaultAuthenticatedFunction = 1 << 2,
- ContainsAllFlags = ContainsAddressDiscriminatedVTable | ContainsAddressDiscriminatedData | ContainsDefaultAuthenticatedFunction,
- LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ContainsDefaultAuthenticatedFunction)
+ ContainsAllFlags = ContainsAddressDiscriminatedVTable |
+ ContainsAddressDiscriminatedData |
+ ContainsDefaultAuthenticatedFunction,
+ LLVM_MARK_AS_BITMASK_ENUM(
+ /*LargestValue=*/ContainsDefaultAuthenticatedFunction)
};
PointerAuthContent findPointerAuthContent(QualType T) const;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index eccce701c..df8deecfd 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1647,8 +1647,10 @@ ASTContext::findPointerAuthContent(QualType T) const {
Result = Result | PointerAuthContent::ContainsAddressDiscriminatedData;
if (T->isFunctionPointerType()) {
PointerAuthQualifier ExplicitQualifier = T.getPointerAuth();
- if (!ExplicitQualifier.isPresent() || !ExplicitQualifier.isAddressDiscriminated())
- Result = Result | PointerAuthContent::ContainsDefaultAuthenticatedFunction;
+ if (!ExplicitQualifier.isPresent() ||
+ !ExplicitQualifier.isAddressDiscriminated())
+ Result =
+ Result | PointerAuthContent::ContainsDefaultAuthenticatedFunction;
}
const RecordDecl *RD = T->getAsRecordDecl();
if (!RD)
@@ -1671,7 +1673,8 @@ ASTContext::findPointerAuthContent(QualType T) const {
};
auto ShouldContinueAfterUpdate = [&](PointerAuthContent NewFlag) {
Result = Result | NewFlag;
- if ((NewFlag & PointerAuthContent::ContainsAddressDiscriminatedVTable) != PointerAuthContent::ContainsNone)
+ if ((NewFlag & PointerAuthContent::ContainsAddressDiscriminatedVTable) !=
+ PointerAuthContent::ContainsNone)
Result = Result | PointerAuthContent::ContainsAddressDiscriminatedData;
return Result != PointerAuthContent::ContainsAllFlags;
};
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index dabcd1596..75a3ab293 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -994,9 +994,7 @@ void Sema::getUndefinedButUsed(
}
}
-static void checkQuestionableGlobalFunctionPointers(Sema &S) {
-
-}
+static void checkQuestionableGlobalFunctionPointers(Sema &S) {}
/// checkUndefinedButUsed - Check for undefined objects with internal linkage
/// or that are inline.
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dd63f2c76..22eab65a2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15055,9 +15055,11 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
CheckCompleteDecompositionDeclaration(DD);
if (GlobalStorage && Context.isPointerAuthenticationAvailable() &&
- !Diags.isIgnored(diag::warn_ptrauth_weak_global_function_pointer, var->getLocation())) {
+ !Diags.isIgnored(diag::warn_ptrauth_weak_global_function_pointer,
+ var->getLocation())) {
if (Context.containsDefaultAuthenticatedFunctionPointer(var->getType())) {
- Diag(var->getLocation(), diag::warn_ptrauth_weak_global_function_pointer) << var << var->getSourceRange();
+ Diag(var->getLocation(), diag::warn_ptrauth_weak_global_function_pointer)
+ << var << var->getSourceRange();
}
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.