Skip to content

Commit

Permalink
Merged main:2c7786e94a1058bd4f96794a1d4f70dcb86e5cc5 into amd-gfx:585…
Browse files Browse the repository at this point in the history
…6ee5fcb79

Local branch amd-gfx 5856ee5 Merged main:8e5b43c8effc0a01745bb7c53ca21fb6c8384c51 into amd-gfx:3cfe7da32635
Remote branch main 2c7786e Prefer use of 0.0 over -0.0 for fadd reductions w/nsz (in IR) (llvm#106770)
  • Loading branch information
SC llvm team authored and SC llvm team committed Sep 3, 2024
2 parents 5856ee5 + 2c7786e commit dd32935
Show file tree
Hide file tree
Showing 287 changed files with 2,385 additions and 1,474 deletions.
32 changes: 16 additions & 16 deletions clang/docs/analyzer/checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,22 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
strncpy(buf, "a", 1); // warn
}
.. _security-MmapWriteExec:
security.MmapWriteExec (C)
""""""""""""""""""""""""""
Warn on ``mmap()`` calls with both writable and executable access.
.. code-block:: c
void test(int n) {
void *c = mmap(NULL, 32, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON, -1, 0);
// warn: Both PROT_WRITE and PROT_EXEC flags are set. This can lead to
// exploitable memory regions, which could be overwritten with malicious
// code
}
.. _security-putenv-stack-array:
security.PutenvStackArray (C)
Expand Down Expand Up @@ -2967,22 +2983,6 @@ Warn about buffer overflows (newer checker).
char c = s[x]; // warn: index is tainted
}
.. _alpha-security-MmapWriteExec:
alpha.security.MmapWriteExec (C)
""""""""""""""""""""""""""""""""
Warn on mmap() calls that are both writable and executable.
.. code-block:: c
void test(int n) {
void *c = mmap(NULL, 32, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON, -1, 0);
// warn: Both PROT_WRITE and PROT_EXEC flags are set. This can lead to
// exploitable memory regions, which could be overwritten with malicious
// code
}
.. _alpha-security-ReturnPtrRange:
alpha.security.ReturnPtrRange (C)
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,10 @@ def FloatLoopCounter : Checker<"FloatLoopCounter">,
Dependencies<[SecuritySyntaxChecker]>,
Documentation<HasDocumentation>;

def MmapWriteExecChecker : Checker<"MmapWriteExec">,
HelpText<"Warn on mmap() calls with both writable and executable access">,
Documentation<HasDocumentation>;

def PutenvStackArray : Checker<"PutenvStackArray">,
HelpText<"Finds calls to the function 'putenv' which pass a pointer to "
"an automatic (stack-allocated) array as the argument.">,
Expand Down Expand Up @@ -1039,10 +1043,6 @@ def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">,
HelpText<"Warn about buffer overflows (newer checker)">,
Documentation<HasDocumentation>;

def MmapWriteExecChecker : Checker<"MmapWriteExec">,
HelpText<"Warn on mmap() calls that are both writable and executable">,
Documentation<HasDocumentation>;

def ReturnPointerRangeChecker : Checker<"ReturnPtrRange">,
HelpText<"Check for an out-of-bound pointer being returned to callers">,
Documentation<HasDocumentation>;
Expand Down
68 changes: 34 additions & 34 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
return false;

const auto *TargetSemantics = &Ctx.getFloatSemantics(CE->getType());
llvm::RoundingMode RM = getRoundingMode(CE);
return this->emitCastIntegralFloating(*FromT, TargetSemantics, RM, CE);
return this->emitCastIntegralFloating(*FromT, TargetSemantics,
getFPOptions(CE), CE);
}

case CK_FloatingToBoolean:
Expand All @@ -317,12 +317,12 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {

if (ToT == PT_IntAP)
return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(CE->getType()),
CE);
getFPOptions(CE), CE);
if (ToT == PT_IntAPS)
return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(CE->getType()),
CE);
getFPOptions(CE), CE);

return this->emitCastFloatingIntegral(*ToT, CE);
return this->emitCastFloatingIntegral(*ToT, getFPOptions(CE), CE);
}

case CK_NullToPointer:
Expand Down Expand Up @@ -810,21 +810,21 @@ bool Compiler<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
return MaybeCastToBool(this->emitGE(*LT, BO));
case BO_Sub:
if (BO->getType()->isFloatingType())
return Discard(this->emitSubf(getRoundingMode(BO), BO));
return Discard(this->emitSubf(getFPOptions(BO), BO));
return Discard(this->emitSub(*T, BO));
case BO_Add:
if (BO->getType()->isFloatingType())
return Discard(this->emitAddf(getRoundingMode(BO), BO));
return Discard(this->emitAddf(getFPOptions(BO), BO));
return Discard(this->emitAdd(*T, BO));
case BO_Mul:
if (BO->getType()->isFloatingType())
return Discard(this->emitMulf(getRoundingMode(BO), BO));
return Discard(this->emitMulf(getFPOptions(BO), BO));
return Discard(this->emitMul(*T, BO));
case BO_Rem:
return Discard(this->emitRem(*T, BO));
case BO_Div:
if (BO->getType()->isFloatingType())
return Discard(this->emitDivf(getRoundingMode(BO), BO));
return Discard(this->emitDivf(getFPOptions(BO), BO));
return Discard(this->emitDiv(*T, BO));
case BO_Assign:
if (DiscardResult)
Expand Down Expand Up @@ -1153,7 +1153,7 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
if (!loadComplexValue(RHSIsComplex, true, ElemIndex, RHSOffset, RHS))
return false;
if (ResultElemT == PT_Float) {
if (!this->emitAddf(getRoundingMode(E), E))
if (!this->emitAddf(getFPOptions(E), E))
return false;
} else {
if (!this->emitAdd(ResultElemT, E))
Expand All @@ -1167,7 +1167,7 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
if (!loadComplexValue(RHSIsComplex, true, ElemIndex, RHSOffset, RHS))
return false;
if (ResultElemT == PT_Float) {
if (!this->emitSubf(getRoundingMode(E), E))
if (!this->emitSubf(getFPOptions(E), E))
return false;
} else {
if (!this->emitSub(ResultElemT, E))
Expand All @@ -1182,7 +1182,7 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
return false;

if (ResultElemT == PT_Float) {
if (!this->emitMulf(getRoundingMode(E), E))
if (!this->emitMulf(getFPOptions(E), E))
return false;
} else {
if (!this->emitMul(ResultElemT, E))
Expand All @@ -1198,7 +1198,7 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
return false;

if (ResultElemT == PT_Float) {
if (!this->emitDivf(getRoundingMode(E), E))
if (!this->emitDivf(getFPOptions(E), E))
return false;
} else {
if (!this->emitDiv(ResultElemT, E))
Expand Down Expand Up @@ -2063,22 +2063,21 @@ bool Compiler<Emitter>::VisitFloatCompoundAssignOperator(
if (!this->emitGetLocal(*RT, TempOffset, E))
return false;

llvm::RoundingMode RM = getRoundingMode(E);
switch (E->getOpcode()) {
case BO_AddAssign:
if (!this->emitAddf(RM, E))
if (!this->emitAddf(getFPOptions(E), E))
return false;
break;
case BO_SubAssign:
if (!this->emitSubf(RM, E))
if (!this->emitSubf(getFPOptions(E), E))
return false;
break;
case BO_MulAssign:
if (!this->emitMulf(RM, E))
if (!this->emitMulf(getFPOptions(E), E))
return false;
break;
case BO_DivAssign:
if (!this->emitDivf(RM, E))
if (!this->emitDivf(getFPOptions(E), E))
return false;
break;
default:
Expand Down Expand Up @@ -3325,7 +3324,7 @@ template <class Emitter> bool Compiler<Emitter>::visitBool(const Expr *E) {

// Or Floats.
if (T == PT_Float)
return this->emitCastFloatingIntegralBool(E);
return this->emitCastFloatingIntegralBool(getFPOptions(E), E);

// Or anything else we can.
return this->emitCast(*T, PT_Bool, E);
Expand Down Expand Up @@ -5005,8 +5004,8 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
}

if (T == PT_Float) {
return DiscardResult ? this->emitIncfPop(getRoundingMode(E), E)
: this->emitIncf(getRoundingMode(E), E);
return DiscardResult ? this->emitIncfPop(getFPOptions(E), E)
: this->emitIncf(getFPOptions(E), E);
}

return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);
Expand All @@ -5028,8 +5027,8 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
}

if (T == PT_Float) {
return DiscardResult ? this->emitDecfPop(getRoundingMode(E), E)
: this->emitDecf(getRoundingMode(E), E);
return DiscardResult ? this->emitDecfPop(getFPOptions(E), E)
: this->emitDecf(getFPOptions(E), E);
}

return DiscardResult ? this->emitDecPop(*T, E) : this->emitDec(*T, E);
Expand All @@ -5056,7 +5055,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
// Post-inc and pre-inc are the same if the value is to be discarded.
if (DiscardResult) {
if (T == PT_Float)
return this->emitIncfPop(getRoundingMode(E), E);
return this->emitIncfPop(getFPOptions(E), E);
return this->emitIncPop(*T, E);
}

Expand All @@ -5066,7 +5065,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
return false;
if (!this->emitConstFloat(llvm::APFloat(TargetSemantics, 1), E))
return false;
if (!this->emitAddf(getRoundingMode(E), E))
if (!this->emitAddf(getFPOptions(E), E))
return false;
if (!this->emitStoreFloat(E))
return false;
Expand Down Expand Up @@ -5105,7 +5104,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
// Post-dec and pre-dec are the same if the value is to be discarded.
if (DiscardResult) {
if (T == PT_Float)
return this->emitDecfPop(getRoundingMode(E), E);
return this->emitDecfPop(getFPOptions(E), E);
return this->emitDecPop(*T, E);
}

Expand All @@ -5115,7 +5114,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
return false;
if (!this->emitConstFloat(llvm::APFloat(TargetSemantics, 1), E))
return false;
if (!this->emitSubf(getRoundingMode(E), E))
if (!this->emitSubf(getFPOptions(E), E))
return false;
if (!this->emitStoreFloat(E))
return false;
Expand Down Expand Up @@ -5579,13 +5578,15 @@ bool Compiler<Emitter>::emitPrimCast(PrimType FromT, PrimType ToT,
}

if (ToT == PT_IntAP)
return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT), E);
return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(ToQT),
getFPOptions(E), E);
if (ToT == PT_IntAPS)
return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT), E);
return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(ToQT),
getFPOptions(E), E);

// Float to integral.
if (isIntegralType(ToT) || ToT == PT_Bool)
return this->emitCastFloatingIntegral(ToT, E);
return this->emitCastFloatingIntegral(ToT, getFPOptions(E), E);
}

if (isIntegralType(FromT) || FromT == PT_Bool) {
Expand All @@ -5601,8 +5602,7 @@ bool Compiler<Emitter>::emitPrimCast(PrimType FromT, PrimType ToT,
if (ToT == PT_Float) {
// Integral to floating.
const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);
return this->emitCastIntegralFloating(FromT, ToSem, getRoundingMode(E),
E);
return this->emitCastIntegralFloating(FromT, ToSem, getFPOptions(E), E);
}
}

Expand Down Expand Up @@ -5639,7 +5639,7 @@ bool Compiler<Emitter>::emitComplexBoolCast(const Expr *E) {
if (!this->emitArrayElem(ElemT, 0, E))
return false;
if (ElemT == PT_Float) {
if (!this->emitCastFloatingIntegral(PT_Bool, E))
if (!this->emitCastFloatingIntegral(PT_Bool, getFPOptions(E), E))
return false;
} else {
if (!this->emitCast(ElemT, PT_Bool, E))
Expand All @@ -5654,7 +5654,7 @@ bool Compiler<Emitter>::emitComplexBoolCast(const Expr *E) {
if (!this->emitArrayElemPop(ElemT, 1, E))
return false;
if (ElemT == PT_Float) {
if (!this->emitCastFloatingIntegral(PT_Bool, E))
if (!this->emitCastFloatingIntegral(PT_Bool, getFPOptions(E), E))
return false;
} else {
if (!this->emitCast(ElemT, PT_Bool, E))
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
return FPO.getRoundingMode();
}

uint32_t getFPOptions(const Expr *E) const {
return E->getFPFeaturesInEffect(Ctx.getLangOpts()).getAsOpaqueInt();
}

bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
PrimType classifyComplexElementType(QualType T) const {
assert(T->isAnyComplexType());
Expand Down
Loading

0 comments on commit dd32935

Please sign in to comment.