mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out changesets acb4dd16755c and 40768f723990 (bug 867348) for static analysis bustage.
CLOSED TREE
This commit is contained in:
parent
562c58ba41
commit
c51c7d8b9a
@ -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<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 {
|
||||
|
@ -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));
|
||||
}
|
@ -8,7 +8,6 @@ SOURCES += [
|
||||
'TestBadImplicitConversionCtor.cpp',
|
||||
'TestCustomHeap.cpp',
|
||||
'TestMustOverride.cpp',
|
||||
'TestNoArithmeticExprInArgument.cpp',
|
||||
'TestNonHeapClass.cpp',
|
||||
'TestStackClass.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 {
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/IntegerTypeTraits.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -526,7 +525,7 @@ public:
|
||||
* 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))
|
||||
{
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user