Skip to content

Commit be79096

Browse files
committed
Use lambda to check for incompatible attributes [to squash]
1 parent 7de32ca commit be79096

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8808,40 +8808,25 @@ static bool MustDelayAttributeArguments(const ParsedAttr &AL) {
88088808

88098809
static bool checkArmNewAttrMutualExclusion(Sema &S, const ParsedAttr &AL,
88108810
const FunctionProtoType *FPT,
8811-
FunctionType::ArmStateValue State,
8811+
FunctionType::ArmStateValue CurrentState,
88128812
StringRef StateName) {
8813-
std::string ArmNewStr =
8814-
std::string("'__arm_new(\"") + StateName.str() + "\")'";
8815-
8816-
if (State == FunctionType::ARM_In) {
8817-
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
8818-
<< ArmNewStr << std::string("'__arm_in(\"") + StateName.str() + "\")'"
8819-
<< true;
8820-
AL.setInvalid();
8821-
}
8822-
8823-
if (State == FunctionType::ARM_Out) {
8824-
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
8825-
<< ArmNewStr << std::string("'__arm_out(\"") + StateName.str() + "\")'"
8826-
<< true;
8827-
AL.setInvalid();
8828-
}
8829-
8830-
if (State == FunctionType::ARM_InOut) {
8831-
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
8832-
<< ArmNewStr
8833-
<< std::string("'__arm_inout(\"") + StateName.str() + "\")'" << true;
8834-
AL.setInvalid();
8835-
}
8836-
8837-
if (State == FunctionType::ARM_Preserves) {
8838-
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
8839-
<< ArmNewStr
8840-
<< std::string("'__arm_preserves(\"") + StateName.str() + "\")'"
8841-
<< true;
8842-
AL.setInvalid();
8843-
}
8813+
auto CheckForIncompatibleAttr =
8814+
[&](FunctionType::ArmStateValue IncompatibleState,
8815+
StringRef IncompatibleStateName) {
8816+
if (CurrentState == IncompatibleState) {
8817+
S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
8818+
<< (std::string("'__arm_new(\"") + StateName.str() + "\")'")
8819+
<< (std::string("'") + IncompatibleStateName.str() + "(\"" +
8820+
StateName.str() + "\")'")
8821+
<< true;
8822+
AL.setInvalid();
8823+
}
8824+
};
88448825

8826+
CheckForIncompatibleAttr(FunctionType::ARM_In, "__arm_in");
8827+
CheckForIncompatibleAttr(FunctionType::ARM_Out, "__arm_out");
8828+
CheckForIncompatibleAttr(FunctionType::ARM_InOut, "__arm_inout");
8829+
CheckForIncompatibleAttr(FunctionType::ARM_Preserves, "__arm_preserves");
88458830
return AL.isInvalid();
88468831
}
88478832

0 commit comments

Comments
 (0)