Skip to content

Commit d6301b2

Browse files
authored
Revert "[clang][dataflow] Fix unsupported types always being equal" (#129761)
Reverts #129502 seeing new crashes around https://github.com/google/crubit/blob/859520eca82d60a169fb85cdbf648c57d0a14a99/nullability/test/smart_pointers_diagnosis.cc#L57 Would like some time to investigate.
1 parent 855178a commit d6301b2

File tree

2 files changed

+1
-46
lines changed

2 files changed

+1
-46
lines changed

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ static BoolValue &evaluateBooleanEquality(const Expr &LHS, const Expr &RHS,
6060
Value *LHSValue = Env.getValue(LHS);
6161
Value *RHSValue = Env.getValue(RHS);
6262

63-
// When two unsupported values are compared, both are nullptr. Only supported
64-
// values should evaluate to equal.
65-
if (LHSValue == RHSValue && LHSValue)
63+
if (LHSValue == RHSValue)
6664
return Env.getBoolLiteralValue(true);
6765

6866
if (auto *LHSBool = dyn_cast_or_null<BoolValue>(LHSValue))
@@ -800,14 +798,6 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
800798
Env.setValue(*S, Env.getIntLiteralValue(S->getValue()));
801799
}
802800

803-
// Untyped nullptr's aren't handled by NullToPointer casts, so they need to be
804-
// handled separately.
805-
void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
806-
auto &NullPointerVal =
807-
Env.getOrCreateNullPointerValue(S->getType()->getPointeeType());
808-
Env.setValue(*S, NullPointerVal);
809-
}
810-
811801
void VisitParenExpr(const ParenExpr *S) {
812802
// The CFG does not contain `ParenExpr` as top-level statements in basic
813803
// blocks, however manual traversal to sub-expressions may encounter them.

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4974,41 +4974,6 @@ TEST(TransferTest, IntegerLiteralEquality) {
49744974
});
49754975
}
49764976

4977-
TEST(TransferTest, UnsupportedValueEquality) {
4978-
std::string Code = R"(
4979-
// An explicitly unsupported type by the framework.
4980-
enum class EC {
4981-
A,
4982-
B
4983-
};
4984-
4985-
void target() {
4986-
EC ec = EC::A;
4987-
4988-
bool unsupported_eq_same = (EC::A == EC::A);
4989-
bool unsupported_eq_other = (EC::A == EC::B);
4990-
bool unsupported_eq_var = (ec == EC::B);
4991-
4992-
(void)0; // [[p]]
4993-
}
4994-
)";
4995-
runDataflow(
4996-
Code,
4997-
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
4998-
ASTContext &ASTCtx) {
4999-
const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
5000-
5001-
// We do not model the values of unsupported types, so this
5002-
// seemingly-trivial case will not be true either.
5003-
EXPECT_TRUE(isa<AtomicBoolValue>(
5004-
getValueForDecl<BoolValue>(ASTCtx, Env, "unsupported_eq_same")));
5005-
EXPECT_TRUE(isa<AtomicBoolValue>(
5006-
getValueForDecl<BoolValue>(ASTCtx, Env, "unsupported_eq_other")));
5007-
EXPECT_TRUE(isa<AtomicBoolValue>(
5008-
getValueForDecl<BoolValue>(ASTCtx, Env, "unsupported_eq_var")));
5009-
});
5010-
}
5011-
50124977
TEST(TransferTest, CorrelatedBranches) {
50134978
std::string Code = R"(
50144979
void target(bool B, bool C) {

0 commit comments

Comments
 (0)