From 3d7d4af71d045735a43d1eb47b5244aa27a6cdd8 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Thu, 18 Dec 2014 15:59:51 -0500 Subject: [PATCH] Backed out changesets acb4dd16755c and 40768f723990 (bug 867348) for static analysis bustage. CLOSED TREE --- build/clang-plugin/clang-plugin.cpp | 83 ------------------- .../tests/TestNoArithmeticExprInArgument.cpp | 32 ------- build/clang-plugin/tests/moz.build | 1 - dom/media/ogg/OggCodecState.cpp | 8 +- mfbt/Attributes.h | 4 - mfbt/CheckedInt.h | 3 +- mfbt/tests/TestCheckedInt.cpp | 2 +- 7 files changed, 5 insertions(+), 128 deletions(-) delete mode 100644 build/clang-plugin/tests/TestNoArithmeticExprInArgument.cpp diff --git a/build/clang-plugin/clang-plugin.cpp b/build/clang-plugin/clang-plugin.cpp index c75ce62f349066..f28c9fecbdc2cc 100644 --- a/build/clang-plugin/clang-plugin.cpp +++ b/build/clang-plugin/clang-plugin.cpp @@ -329,49 +329,6 @@ AST_MATCHER(QualType, nonheapClassAggregate) { AST_MATCHER(FunctionDecl, heapAllocator) { return MozChecker::hasCustomAnnotation(&Node, "moz_heap_allocator"); } - -/// This matcher will match any declaration that is marked as not accepting -/// arithmetic expressions in its arguments. -AST_MATCHER(Decl, noArithmeticExprInArgs) { - return MozChecker::hasCustomAnnotation(&Node, "moz_no_arith_expr_in_arg"); -} - -/// This matcher will match all arithmetic binary operators. -AST_MATCHER(BinaryOperator, binaryArithmeticOperator) { - BinaryOperatorKind opcode = Node.getOpcode(); - return opcode == BO_Mul || - opcode == BO_Div || - opcode == BO_Rem || - opcode == BO_Add || - opcode == BO_Sub || - opcode == BO_Shl || - opcode == BO_Shr || - opcode == BO_And || - opcode == BO_Xor || - opcode == BO_Or || - opcode == BO_MulAssign || - opcode == BO_DivAssign || - opcode == BO_RemAssign || - opcode == BO_AddAssign || - opcode == BO_SubAssign || - opcode == BO_ShlAssign || - opcode == BO_ShrAssign || - opcode == BO_AndAssign || - opcode == BO_XorAssign || - opcode == BO_OrAssign; -} - -/// This matcher will match all arithmetic unary operators. -AST_MATCHER(UnaryOperator, unaryArithmeticOperator) { - UnaryOperatorKind opcode = Node.getOpcode(); - return opcode == UO_PostInc || - opcode == UO_PostDec || - opcode == UO_PreInc || - opcode == UO_PreDec || - opcode == UO_Plus || - opcode == UO_Minus || - opcode == UO_Not; -} } } @@ -410,33 +367,6 @@ DiagnosticsMatcher::DiagnosticsMatcher() { astMatcher.addMatcher(callExpr(callee(functionDecl(allOf(heapAllocator(), returns(pointerType(pointee(stackClassAggregate()))))))).bind("node"), &stackClassChecker); - - astMatcher.addMatcher(callExpr(allOf(hasDeclaration(noArithmeticExprInArgs()), - anyOf( - hasDescendant(binaryOperator(allOf(binaryArithmeticOperator(), - hasLHS(hasDescendant(declRefExpr())), - hasRHS(hasDescendant(declRefExpr())) - )).bind("node")), - hasDescendant(unaryOperator(allOf(unaryArithmeticOperator(), - hasUnaryOperand(allOf(hasType(builtinType()), - anyOf(hasDescendant(declRefExpr()), declRefExpr()))) - )).bind("node")) - ) - )).bind("call"), - &arithmeticArgChecker); - astMatcher.addMatcher(constructExpr(allOf(hasDeclaration(noArithmeticExprInArgs()), - anyOf( - hasDescendant(binaryOperator(allOf(binaryArithmeticOperator(), - hasLHS(hasDescendant(declRefExpr())), - hasRHS(hasDescendant(declRefExpr())) - )).bind("node")), - hasDescendant(unaryOperator(allOf(unaryArithmeticOperator(), - hasUnaryOperand(allOf(hasType(builtinType()), - anyOf(hasDescendant(declRefExpr()), declRefExpr()))) - )).bind("node")) - ) - )).bind("call"), - &arithmeticArgChecker); } void DiagnosticsMatcher::StackClassChecker::run( @@ -542,19 +472,6 @@ void DiagnosticsMatcher::NonHeapClassChecker::noteInferred(QualType T, noteInferred(cast(cause)->getType(), Diag); } -void DiagnosticsMatcher::ArithmeticArgChecker::run( - const MatchFinder::MatchResult &Result) { - DiagnosticsEngine &Diag = Result.Context->getDiagnostics(); - unsigned errorID = Diag.getDiagnosticIDs()->getCustomDiagID( - DiagnosticIDs::Error, "cannot pass an arithmetic expression of built-in types to %0"); - const Expr *expr = Result.Nodes.getNodeAs("node"); - if (const CallExpr *call = Result.Nodes.getNodeAs("call")) { - Diag.Report(expr->getLocStart(), errorID) << call->getDirectCallee(); - } else if (const CXXConstructExpr *ctr = Result.Nodes.getNodeAs("call")) { - Diag.Report(expr->getLocStart(), errorID) << ctr->getConstructor(); - } -} - class MozCheckAction : public PluginASTAction { public: ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI, StringRef fileName) override { diff --git a/build/clang-plugin/tests/TestNoArithmeticExprInArgument.cpp b/build/clang-plugin/tests/TestNoArithmeticExprInArgument.cpp deleted file mode 100644 index 96f46c2ff41d2a..00000000000000 --- a/build/clang-plugin/tests/TestNoArithmeticExprInArgument.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT __attribute__((annotate("moz_no_arith_expr_in_arg"))) - -struct X { - explicit X(int) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT; - void baz(int) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT; -}; - -int operator+(int, X); -int operator+(X, int); -int operator++(X); - -void badArithmeticsInArgs() { - int a; - typedef int myint; - myint b; - X goodObj1(a); - goodObj1.baz(b); - X badObj1(a + b); // expected-error{{cannot pass an arithmetic expression of built-in types to 'X'}} - X badObj2 = X(a ? 0 : ++a); // expected-error{{cannot pass an arithmetic expression of built-in types to 'X'}} - X badObj3(~a); // expected-error{{cannot pass an arithmetic expression of built-in types to 'X'}} - badObj1.baz(a - 1 - b); // expected-error{{cannot pass an arithmetic expression of built-in types to 'baz'}} - badObj1.baz(++a); // expected-error{{cannot pass an arithmetic expression of built-in types to 'baz'}} - badObj1.baz(a++); // expected-error{{cannot pass an arithmetic expression of built-in types to 'baz'}} - badObj1.baz(a || b); - badObj1.baz(a + goodObj1); - badObj1.baz(goodObj1 + a); - badObj1.baz(++goodObj1); - badObj1.baz(-1); - badObj1.baz(-1.0); - badObj1.baz(1 + 2); - badObj1.baz(1 << (sizeof(int)/2)); -} diff --git a/build/clang-plugin/tests/moz.build b/build/clang-plugin/tests/moz.build index d2c78a93638cc3..4066642f13e506 100644 --- a/build/clang-plugin/tests/moz.build +++ b/build/clang-plugin/tests/moz.build @@ -8,7 +8,6 @@ SOURCES += [ 'TestBadImplicitConversionCtor.cpp', 'TestCustomHeap.cpp', 'TestMustOverride.cpp', - 'TestNoArithmeticExprInArgument.cpp', 'TestNonHeapClass.cpp', 'TestStackClass.cpp', ] diff --git a/dom/media/ogg/OggCodecState.cpp b/dom/media/ogg/OggCodecState.cpp index acba322a0500fd..58871bc8af7d63 100644 --- a/dom/media/ogg/OggCodecState.cpp +++ b/dom/media/ogg/OggCodecState.cpp @@ -936,7 +936,7 @@ int64_t OpusState::Time(int aPreSkip, int64_t aGranulepos) return -1; // Ogg Opus always runs at a granule rate of 48 kHz. - CheckedInt64 t = (CheckedInt64(aGranulepos) - aPreSkip) * USECS_PER_S; + CheckedInt64 t = CheckedInt64(aGranulepos - aPreSkip) * USECS_PER_S; return t.isValid() ? t.value() / 48000 : -1; } @@ -1197,8 +1197,7 @@ bool SkeletonState::DecodeIndex(ogg_packet* aPacket) } // Extract the start time. - int64_t timeRawInt = LittleEndian::readInt64(p + INDEX_FIRST_NUMER_OFFSET); - CheckedInt64 t = CheckedInt64(timeRawInt) * USECS_PER_S; + CheckedInt64 t = CheckedInt64(LittleEndian::readInt64(p + INDEX_FIRST_NUMER_OFFSET)) * USECS_PER_S; if (!t.isValid()) { return (mActive = false); } else { @@ -1206,8 +1205,7 @@ bool SkeletonState::DecodeIndex(ogg_packet* aPacket) } // Extract the end time. - timeRawInt = LittleEndian::readInt64(p + INDEX_LAST_NUMER_OFFSET); - t = CheckedInt64(timeRawInt) * USECS_PER_S; + t = LittleEndian::readInt64(p + INDEX_LAST_NUMER_OFFSET) * USECS_PER_S; if (!t.isValid()) { return (mActive = false); } else { diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index 4e52fe659c9284..fa190af92f78ae 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -502,15 +502,12 @@ * are disallowed by default unless they are marked as MOZ_IMPLICIT. This * attribute must be used for constructors which intend to provide implicit * conversions. - * MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT: Applies to functions. Makes it a compile - * time error to path arithmetic expressions on variables to the function. */ #ifdef MOZ_CLANG_PLUGIN # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) # define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) # define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) # define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) -# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT __attribute__((annotate("moz_no_arith_expr_in_arg"))) /* * It turns out that clang doesn't like void func() __attribute__ {} without a * warning, so use pragmas to disable the warning. This code won't work on GCC @@ -526,7 +523,6 @@ # define MOZ_STACK_CLASS /* nothing */ # define MOZ_NONHEAP_CLASS /* nothing */ # define MOZ_IMPLICIT /* nothing */ -# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT /* nothing */ # define MOZ_HEAP_ALLOCATOR /* nothing */ #endif /* MOZ_CLANG_PLUGIN */ diff --git a/mfbt/CheckedInt.h b/mfbt/CheckedInt.h index bed71a430922bf..e4f08992038b8b 100644 --- a/mfbt/CheckedInt.h +++ b/mfbt/CheckedInt.h @@ -11,7 +11,6 @@ #include #include "mozilla/Assertions.h" -#include "mozilla/Attributes.h" #include "mozilla/IntegerTypeTraits.h" namespace mozilla { @@ -526,7 +525,7 @@ class CheckedInt * argument is valid. */ template - CheckedInt(U aValue) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT + CheckedInt(U aValue) : mValue(T(aValue)), mIsValid(detail::IsInRange(aValue)) { diff --git a/mfbt/tests/TestCheckedInt.cpp b/mfbt/tests/TestCheckedInt.cpp index 7ded8e350a39b3..cca1821746c0aa 100644 --- a/mfbt/tests/TestCheckedInt.cpp +++ b/mfbt/tests/TestCheckedInt.cpp @@ -521,7 +521,7 @@ void test() : sizeof(T) >= sizeof(U)); \ } #define VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE(U) \ - VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE2(U,U,+zero) \ + VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE2(U,U,+0) \ VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE2(U,CheckedInt,.toChecked()) VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE(int8_t)