diff options
author | Dan McArdle <dmcardle@google.com> | 2024-07-01 09:47:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-01 09:47:09 -0400 |
commit | d6987606872a4152495cca0c52b3261b7c44f3ee (patch) | |
tree | 8d525ca8a4b43a9523c83754ebda2a45d9406fff /clang/lib/Sema | |
parent | 51d87aa4380046588124c2e474924cd8f57189db (diff) | |
download | llvm-d6987606872a4152495cca0c52b3261b7c44f3ee.zip llvm-d6987606872a4152495cca0c52b3261b7c44f3ee.tar.gz llvm-d6987606872a4152495cca0c52b3261b7c44f3ee.tar.bz2 |
[clang][ThreadSafety] Revert stricter typing on trylock attributes (#97293)
This PR reverts #95290 and the one-liner followup PR #96494.
I received some substantial feedback on #95290, which I plan to address
in a future PR.
I've also received feedback that because the change emits errors where
they were not emitted before, we should at least have a flag to disable
the stricter warnings.
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 41489789..b8842e9 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -14,7 +14,6 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/ASTMutationListener.h" #include "clang/AST/CXXInheritance.h" -#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" @@ -26,7 +25,6 @@ #include "clang/Basic/CharInfo.h" #include "clang/Basic/Cuda.h" #include "clang/Basic/DarwinSDKInfo.h" -#include "clang/Basic/DiagnosticSema.h" #include "clang/Basic/HLSLRuntime.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LangOptions.h" @@ -67,13 +65,10 @@ #include "llvm/Demangle/Demangle.h" #include "llvm/IR/Assumptions.h" #include "llvm/MC/MCSectionMachO.h" -#include "llvm/Support/Casting.h" #include "llvm/Support/Error.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Triple.h" -#include <cassert> #include <optional> using namespace clang; @@ -171,6 +166,13 @@ bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum, return checkStringLiteralArgumentAttr(AL, ArgExpr, Str, ArgLocation); } +/// Check if the passed-in expression is of type int or bool. +static bool isIntOrBool(Expr *Exp) { + QualType QT = Exp->getType(); + return QT->isBooleanType() || QT->isIntegerType(); +} + + // Check to see if the type is a smart pointer of some kind. We assume // it's a smart pointer if it defines both operator-> and operator*. static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType* RT) { @@ -606,31 +608,15 @@ static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, if (!AL.checkAtLeastNumArgs(S, 1)) return false; - // The attribute's first argument defines the success value. - const Expr *SuccessArg = AL.getArgAsExpr(0); - if (!isa<CXXNullPtrLiteralExpr>(SuccessArg) && - !isa<GNUNullExpr>(SuccessArg) && !isa<CXXBoolLiteralExpr>(SuccessArg) && - !isa<IntegerLiteral>(SuccessArg) && !SuccessArg->getEnumConstantDecl()) { + if (!isIntOrBool(AL.getArgAsExpr(0))) { S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) - << AL << 1 << AANT_ArgumentNullptrOrBoolIntOrEnumLiteral; + << AL << 1 << AANT_ArgumentIntOrBool; return false; } - // All remaining arguments must be lockable objects. + // check that all arguments are lockable objects checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1); - // The function must return a pointer, boolean, integer, or enum. We already - // know that `D` is a function because `ExclusiveTrylockFunction` and friends - // are defined in Attr.td with subject lists that only include functions. - QualType ReturnType = D->getAsFunction()->getReturnType(); - if (!ReturnType->isPointerType() && !ReturnType->isBooleanType() && - !ReturnType->isIntegerType() && !ReturnType->isEnumeralType()) { - S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type) - << AL << AL.isRegularKeywordAttribute() - << ExpectedFunctionReturningPointerBoolIntOrEnum; - return false; - } - return true; } |