Skip to content

Commit

Permalink
Backed out changesets acb4dd16755c and 40768f723990 (bug 867348) for …
Browse files Browse the repository at this point in the history
…static analysis bustage.

CLOSED TREE
  • Loading branch information
rvandermeulen committed Dec 18, 2014
1 parent ee2a73f commit 3d7d4af
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 128 deletions.
83 changes: 0 additions & 83 deletions build/clang-plugin/clang-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -542,19 +472,6 @@ void DiagnosticsMatcher::NonHeapClassChecker::noteInferred(QualType T,
noteInferred(cast<ValueDecl>(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<Expr>("node");
if (const CallExpr *call = Result.Nodes.getNodeAs<CallExpr>("call")) {
Diag.Report(expr->getLocStart(), errorID) << call->getDirectCallee();
} else if (const CXXConstructExpr *ctr = Result.Nodes.getNodeAs<CXXConstructExpr>("call")) {
Diag.Report(expr->getLocStart(), errorID) << ctr->getConstructor();
}
}

class MozCheckAction : public PluginASTAction {
public:
ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI, StringRef fileName) override {
Expand Down
32 changes: 0 additions & 32 deletions build/clang-plugin/tests/TestNoArithmeticExprInArgument.cpp

This file was deleted.

1 change: 0 additions & 1 deletion build/clang-plugin/tests/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SOURCES += [
'TestBadImplicitConversionCtor.cpp',
'TestCustomHeap.cpp',
'TestMustOverride.cpp',
'TestNoArithmeticExprInArgument.cpp',
'TestNonHeapClass.cpp',
'TestStackClass.cpp',
]
Expand Down
8 changes: 3 additions & 5 deletions dom/media/ogg/OggCodecState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1197,17 +1197,15 @@ 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 {
startTime = t.value() / timeDenom;
}

// 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 {
Expand Down
4 changes: 0 additions & 4 deletions mfbt/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */

Expand Down
3 changes: 1 addition & 2 deletions mfbt/CheckedInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <stdint.h>
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/IntegerTypeTraits.h"

namespace mozilla {
Expand Down Expand Up @@ -526,7 +525,7 @@ class CheckedInt
* argument is valid.
*/
template<typename U>
CheckedInt(U aValue) MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT
CheckedInt(U aValue)
: mValue(T(aValue)),
mIsValid(detail::IsInRange<T>(aValue))
{
Expand Down
2 changes: 1 addition & 1 deletion mfbt/tests/TestCheckedInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<U>,.toChecked<T>())

VERIFY_CONSTRUCTION_FROM_INTEGER_TYPE(int8_t)
Expand Down

0 comments on commit 3d7d4af

Please sign in to comment.