diff --git a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp --- a/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp +++ b/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp @@ -80,24 +80,24 @@ "No signed operand found in problematic bitwise operations"); bool IsUnary = false; - SourceLocation Location; + SourceLocation OperatorLoc; if (const auto *UnaryOp = N.getNodeAs("unary-signed")) { IsUnary = true; - Location = UnaryOp->getBeginLoc(); + OperatorLoc = UnaryOp->getOperatorLoc(); } else { if (const auto *BinaryOp = N.getNodeAs("binary-no-sign-interference")) - Location = BinaryOp->getBeginLoc(); + OperatorLoc = BinaryOp->getOperatorLoc(); else if (const auto *BinaryOp = N.getNodeAs("binary-sign-interference")) - Location = BinaryOp->getBeginLoc(); + OperatorLoc = BinaryOp->getOperatorLoc(); else llvm_unreachable("unexpected matcher result"); } - diag(Location, "use of a signed integer operand with a " - "%select{binary|unary}0 bitwise operator") - << IsUnary << SignedOperand->getSourceRange(); + diag(SignedOperand->getBeginLoc(), "use of a signed integer operand with a " + "%select{binary|unary}0 bitwise operator") + << IsUnary << SignedOperand->getSourceRange() << OperatorLoc; } } // namespace hicpp diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp @@ -8,14 +8,14 @@ URes = UValue & 1u; //Ok URes = UValue & -1; - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use of a signed integer operand with a binary bitwise operator unsigned URes2 = URes << 1; //Ok int IResult; IResult = 10 & 2; //Ok IResult = 3 << -1; - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use of a signed integer operand with a binary bitwise operator int Int = 30; IResult = Int << 1; diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise.cpp @@ -42,7 +42,7 @@ UResult = SValue & -1; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator UResult&= 1; - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator UResult = UValue & 1u; // Ok UResult = UValue & UValue; // Ok @@ -63,43 +63,43 @@ // More complex expressions. UResult = UValue & (SByte1 + (SByte1 | SByte2)); - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use of a signed integer operand with a binary bitwise operator // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: use of a signed integer operand with a binary bitwise operator // The rest is to demonstrate functionality but all operators are matched equally. // Therefore functionality is the same for all binary operations. UByte1 = UByte1 | UByte2; // Ok UByte1 = UByte1 | SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use of a signed integer operand with a binary bitwise operator UByte1|= SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a binary bitwise operator UByte1|= UByte2; // Ok UByte1 = UByte1 ^ UByte2; // Ok UByte1 = UByte1 ^ SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use of a signed integer operand with a binary bitwise operator UByte1^= SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a binary bitwise operator UByte1^= UByte2; // Ok UByte1 = UByte1 >> UByte2; // Ok UByte1 = UByte1 >> SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use of a signed integer operand with a binary bitwise operator UByte1>>= SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator UByte1>>= UByte2; // Ok UByte1 = UByte1 << UByte2; // Ok UByte1 = UByte1 << SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use of a signed integer operand with a binary bitwise operator UByte1<<= SByte2; - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator UByte1<<= UByte2; // Ok int SignedInt1 = 1 << 12; // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use of a signed integer operand with a binary bitwise operator int SignedInt2 = 1u << 12; - // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use of a signed integer operand with a binary bitwise operator } void f1(unsigned char c) {} @@ -113,28 +113,28 @@ UByte1 = ~UByte1; // Ok SByte1 = ~UByte1; SByte1 = ~SByte1; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator UByte1 = ~SByte1; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator unsigned int UInt = 0u; int SInt = 0; f1(~UByte1); // Ok f1(~SByte1); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use of a signed integer operand with a unary bitwise operator f1(~UInt); f1(~SInt); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use of a signed integer operand with a unary bitwise operator f2(~UByte1); f2(~SByte1); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use of a signed integer operand with a unary bitwise operator f2(~UInt); f2(~SInt); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use of a signed integer operand with a unary bitwise operator f3(~UByte1); // Ok f3(~SByte1); - // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use of a signed integer operand with a unary bitwise operator } /// HICPP uses these examples to demonstrate the rule. @@ -158,7 +158,7 @@ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use of a signed integer operand with a binary bitwise operator r = ~0; - // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use of a signed integer operand with a unary bitwise operator + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use of a signed integer operand with a unary bitwise operator r = ~0u; // Ok k = ~k; // Ok @@ -236,5 +236,5 @@ test2 = one << two, // CHECK-MESSAGES: [[@LINE-1]]:11: warning: use of a signed integer operand with a binary bitwise operator test3 = 1u << 12, - // CHECK-MESSAGES: [[@LINE-1]]:11: warning: use of a signed integer operand with a binary bitwise operator + // CHECK-MESSAGES: [[@LINE-1]]:17: warning: use of a signed integer operand with a binary bitwise operator };