Skip to content

Commit 6054e68

Browse files
authored
Merge branch 'main' into warn_gcc11
2 parents cdd7464 + 397707f commit 6054e68

File tree

109 files changed

+2100
-1377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2100
-1377
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ Improvements to Clang's diagnostics
419419
- The warning for an unsupported type for a named register variable is now phrased ``unsupported type for named register variable``,
420420
instead of ``bad type for named register variable``. This makes it clear that the type is not supported at all, rather than being
421421
suboptimal in some way the error fails to mention (#GH111550).
422-
422+
423423
- Clang now emits a ``-Wdepredcated-literal-operator`` diagnostic, even if the
424424
name was a reserved name, which we improperly allowed to suppress the
425425
diagnostic.
@@ -538,6 +538,7 @@ Bug Fixes to C++ Support
538538
certain situations. (#GH47400), (#GH90896)
539539
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
540540
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
541+
- Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559)
541542

542543
Bug Fixes to AST Handling
543544
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ Expr *CastExpr::getSubExprAsWritten() {
19891989
SubExpr = IgnoreExprNodes(cast<CXXConstructExpr>(SubExpr)->getArg(0),
19901990
ignoreImplicitSemaNodes);
19911991
} else if (E->getCastKind() == CK_UserDefinedConversion) {
1992-
assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) &&
1992+
assert((isa<CallExpr, BlockExpr>(SubExpr)) &&
19931993
"Unexpected SubExpr for CK_UserDefinedConversion.");
19941994
if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
19951995
SubExpr = MCE->getImplicitObjectArgument();

clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,8 @@ class SymbolicRangeInferrer
12491249
// calculate the effective range set by intersecting the range set
12501250
// for A - B and the negated range set of B - A.
12511251
getRangeForNegatedSymSym(SSE),
1252+
// If commutative, we may have constaints for the commuted variant.
1253+
getRangeCommutativeSymSym(SSE),
12521254
// If Sym is a comparison expression (except <=>),
12531255
// find any other comparisons with the same operands.
12541256
// See function description.
@@ -1485,6 +1487,21 @@ class SymbolicRangeInferrer
14851487
Sym->getType());
14861488
}
14871489

1490+
std::optional<RangeSet> getRangeCommutativeSymSym(const SymSymExpr *SSE) {
1491+
auto Op = SSE->getOpcode();
1492+
bool IsCommutative = llvm::is_contained(
1493+
// ==, !=, |, &, +, *, ^
1494+
{BO_EQ, BO_NE, BO_Or, BO_And, BO_Add, BO_Mul, BO_Xor}, Op);
1495+
if (!IsCommutative)
1496+
return std::nullopt;
1497+
1498+
SymbolRef Commuted = State->getSymbolManager().getSymSymExpr(
1499+
SSE->getRHS(), Op, SSE->getLHS(), SSE->getType());
1500+
if (const RangeSet *Range = getConstraint(State, Commuted))
1501+
return *Range;
1502+
return std::nullopt;
1503+
}
1504+
14881505
// Returns ranges only for binary comparison operators (except <=>)
14891506
// when left and right operands are symbolic values.
14901507
// Finds any other comparisons with the same operands.
@@ -1936,27 +1953,27 @@ class RangeConstraintManager : public RangedConstraintManager {
19361953
const llvm::APSInt &To, const llvm::APSInt &Adjustment) override;
19371954

19381955
private:
1939-
RangeSet::Factory F;
1956+
mutable RangeSet::Factory F;
19401957

1941-
RangeSet getRange(ProgramStateRef State, SymbolRef Sym);
1958+
RangeSet getRange(ProgramStateRef State, SymbolRef Sym) const;
19421959
ProgramStateRef setRange(ProgramStateRef State, SymbolRef Sym,
19431960
RangeSet Range);
19441961

19451962
RangeSet getSymLTRange(ProgramStateRef St, SymbolRef Sym,
19461963
const llvm::APSInt &Int,
1947-
const llvm::APSInt &Adjustment);
1964+
const llvm::APSInt &Adjustment) const;
19481965
RangeSet getSymGTRange(ProgramStateRef St, SymbolRef Sym,
19491966
const llvm::APSInt &Int,
1950-
const llvm::APSInt &Adjustment);
1967+
const llvm::APSInt &Adjustment) const;
19511968
RangeSet getSymLERange(ProgramStateRef St, SymbolRef Sym,
19521969
const llvm::APSInt &Int,
1953-
const llvm::APSInt &Adjustment);
1970+
const llvm::APSInt &Adjustment) const;
19541971
RangeSet getSymLERange(llvm::function_ref<RangeSet()> RS,
19551972
const llvm::APSInt &Int,
1956-
const llvm::APSInt &Adjustment);
1973+
const llvm::APSInt &Adjustment) const;
19571974
RangeSet getSymGERange(ProgramStateRef St, SymbolRef Sym,
19581975
const llvm::APSInt &Int,
1959-
const llvm::APSInt &Adjustment);
1976+
const llvm::APSInt &Adjustment) const;
19601977
};
19611978

19621979
//===----------------------------------------------------------------------===//
@@ -2863,21 +2880,18 @@ ConditionTruthVal RangeConstraintManager::checkNull(ProgramStateRef State,
28632880

28642881
const llvm::APSInt *RangeConstraintManager::getSymVal(ProgramStateRef St,
28652882
SymbolRef Sym) const {
2866-
auto &MutableSelf = const_cast<RangeConstraintManager &>(*this);
2867-
return MutableSelf.getRange(St, Sym).getConcreteValue();
2883+
return getRange(St, Sym).getConcreteValue();
28682884
}
28692885

28702886
const llvm::APSInt *RangeConstraintManager::getSymMinVal(ProgramStateRef St,
28712887
SymbolRef Sym) const {
2872-
auto &MutableSelf = const_cast<RangeConstraintManager &>(*this);
2873-
RangeSet Range = MutableSelf.getRange(St, Sym);
2888+
RangeSet Range = getRange(St, Sym);
28742889
return Range.isEmpty() ? nullptr : &Range.getMinValue();
28752890
}
28762891

28772892
const llvm::APSInt *RangeConstraintManager::getSymMaxVal(ProgramStateRef St,
28782893
SymbolRef Sym) const {
2879-
auto &MutableSelf = const_cast<RangeConstraintManager &>(*this);
2880-
RangeSet Range = MutableSelf.getRange(St, Sym);
2894+
RangeSet Range = getRange(St, Sym);
28812895
return Range.isEmpty() ? nullptr : &Range.getMaxValue();
28822896
}
28832897

@@ -3022,7 +3036,7 @@ RangeConstraintManager::removeDeadBindings(ProgramStateRef State,
30223036
}
30233037

30243038
RangeSet RangeConstraintManager::getRange(ProgramStateRef State,
3025-
SymbolRef Sym) {
3039+
SymbolRef Sym) const {
30263040
return SymbolicRangeInferrer::inferRange(F, State, Sym);
30273041
}
30283042

@@ -3077,10 +3091,10 @@ RangeConstraintManager::assumeSymEQ(ProgramStateRef St, SymbolRef Sym,
30773091
return setRange(St, Sym, New);
30783092
}
30793093

3080-
RangeSet RangeConstraintManager::getSymLTRange(ProgramStateRef St,
3081-
SymbolRef Sym,
3082-
const llvm::APSInt &Int,
3083-
const llvm::APSInt &Adjustment) {
3094+
RangeSet
3095+
RangeConstraintManager::getSymLTRange(ProgramStateRef St, SymbolRef Sym,
3096+
const llvm::APSInt &Int,
3097+
const llvm::APSInt &Adjustment) const {
30843098
// Before we do any real work, see if the value can even show up.
30853099
APSIntType AdjustmentType(Adjustment);
30863100
switch (AdjustmentType.testInRange(Int, true)) {
@@ -3114,10 +3128,10 @@ RangeConstraintManager::assumeSymLT(ProgramStateRef St, SymbolRef Sym,
31143128
return setRange(St, Sym, New);
31153129
}
31163130

3117-
RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St,
3118-
SymbolRef Sym,
3119-
const llvm::APSInt &Int,
3120-
const llvm::APSInt &Adjustment) {
3131+
RangeSet
3132+
RangeConstraintManager::getSymGTRange(ProgramStateRef St, SymbolRef Sym,
3133+
const llvm::APSInt &Int,
3134+
const llvm::APSInt &Adjustment) const {
31213135
// Before we do any real work, see if the value can even show up.
31223136
APSIntType AdjustmentType(Adjustment);
31233137
switch (AdjustmentType.testInRange(Int, true)) {
@@ -3151,10 +3165,10 @@ RangeConstraintManager::assumeSymGT(ProgramStateRef St, SymbolRef Sym,
31513165
return setRange(St, Sym, New);
31523166
}
31533167

3154-
RangeSet RangeConstraintManager::getSymGERange(ProgramStateRef St,
3155-
SymbolRef Sym,
3156-
const llvm::APSInt &Int,
3157-
const llvm::APSInt &Adjustment) {
3168+
RangeSet
3169+
RangeConstraintManager::getSymGERange(ProgramStateRef St, SymbolRef Sym,
3170+
const llvm::APSInt &Int,
3171+
const llvm::APSInt &Adjustment) const {
31583172
// Before we do any real work, see if the value can even show up.
31593173
APSIntType AdjustmentType(Adjustment);
31603174
switch (AdjustmentType.testInRange(Int, true)) {
@@ -3191,7 +3205,7 @@ RangeConstraintManager::assumeSymGE(ProgramStateRef St, SymbolRef Sym,
31913205
RangeSet
31923206
RangeConstraintManager::getSymLERange(llvm::function_ref<RangeSet()> RS,
31933207
const llvm::APSInt &Int,
3194-
const llvm::APSInt &Adjustment) {
3208+
const llvm::APSInt &Adjustment) const {
31953209
// Before we do any real work, see if the value can even show up.
31963210
APSIntType AdjustmentType(Adjustment);
31973211
switch (AdjustmentType.testInRange(Int, true)) {
@@ -3217,10 +3231,10 @@ RangeConstraintManager::getSymLERange(llvm::function_ref<RangeSet()> RS,
32173231
return F.intersect(Default, Lower, Upper);
32183232
}
32193233

3220-
RangeSet RangeConstraintManager::getSymLERange(ProgramStateRef St,
3221-
SymbolRef Sym,
3222-
const llvm::APSInt &Int,
3223-
const llvm::APSInt &Adjustment) {
3234+
RangeSet
3235+
RangeConstraintManager::getSymLERange(ProgramStateRef St, SymbolRef Sym,
3236+
const llvm::APSInt &Int,
3237+
const llvm::APSInt &Adjustment) const {
32243238
return getSymLERange([&] { return getRange(St, Sym); }, Int, Adjustment);
32253239
}
32263240

clang/test/Analysis/unary-sym-expr.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,39 @@ int test(int x, int y) {
2929
return 42;
3030
}
3131

32-
void test_svalbuilder_simplification(int x, int y) {
32+
void test_svalbuilder_simplification_add(int x, int y) {
3333
if (x + y != 3)
3434
return;
3535
clang_analyzer_eval(-(x + y) == -3); // expected-warning{{TRUE}}
36-
// FIXME Commutativity is not supported yet.
37-
clang_analyzer_eval(-(y + x) == -3); // expected-warning{{UNKNOWN}}
36+
clang_analyzer_eval(-(y + x) == -3); // expected-warning{{TRUE}}
37+
}
38+
39+
void test_svalbuilder_simplification_mul(int x, int y) {
40+
if (x * y != 3)
41+
return;
42+
clang_analyzer_eval(-(x * y) == -3); // expected-warning{{TRUE}}
43+
clang_analyzer_eval(-(y * x) == -3); // expected-warning{{TRUE}}
44+
}
45+
46+
void test_svalbuilder_simplification_and(int x, int y) {
47+
if ((x & y) != 3)
48+
return;
49+
clang_analyzer_eval(-(x & y) == -3); // expected-warning{{TRUE}}
50+
clang_analyzer_eval(-(y & x) == -3); // expected-warning{{TRUE}}
51+
}
52+
53+
void test_svalbuilder_simplification_or(int x, int y) {
54+
if ((x | y) != 3)
55+
return;
56+
clang_analyzer_eval(-(x | y) == -3); // expected-warning{{TRUE}}
57+
clang_analyzer_eval(-(y | x) == -3); // expected-warning{{TRUE}}
58+
}
59+
60+
void test_svalbuilder_simplification_xor(int x, int y) {
61+
if ((x ^ y) != 3)
62+
return;
63+
clang_analyzer_eval(-(x ^ y) == -3); // expected-warning{{TRUE}}
64+
clang_analyzer_eval(-(y ^ x) == -3); // expected-warning{{TRUE}}
3865
}
3966

4067
int test_fp(int flag) {

clang/test/SemaCXX/cxx2b-deducing-this.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,3 +1097,20 @@ struct C4 {
10971097
// expected-warning {{volatile-qualified parameter type 'const volatile C4' is deprecated}}
10981098
};
10991099
}
1100+
1101+
1102+
namespace GH112559 {
1103+
struct Wrap {};
1104+
struct S {
1105+
constexpr operator Wrap (this const S& self) {
1106+
return Wrap{};
1107+
};
1108+
constexpr int operator <<(this Wrap self, int i) {
1109+
return 0;
1110+
}
1111+
};
1112+
// Purposefully invalid expression to check an assertion in the
1113+
// expression recovery machinery.
1114+
static_assert((S{} << 11) == a);
1115+
// expected-error@-1 {{use of undeclared identifier 'a'}}
1116+
}

clang/utils/TableGen/ClangOptionDocEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
367367
for (const Record *VisibilityHelp :
368368
R->getValueAsListOfDefs("HelpTextsForVariants")) {
369369
// This is a list of visibilities.
370-
ArrayRef<Init *> Visibilities =
370+
ArrayRef<const Init *> Visibilities =
371371
VisibilityHelp->getValueAsListInit("Visibilities")->getValues();
372372

373373
// See if any of the program's visibilities are in the list.
374374
for (StringRef DocInfoMask :
375375
DocInfo->getValueAsListOfStrings("VisibilityMask")) {
376-
for (Init *Visibility : Visibilities) {
376+
for (const Init *Visibility : Visibilities) {
377377
if (Visibility->getAsUnquotedString() == DocInfoMask) {
378378
// Use the first one we find.
379379
Description = escapeRST(VisibilityHelp->getValueAsString("Text"));

clang/utils/TableGen/RISCVVEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static VectorTypeModifier getTupleVTM(unsigned NF) {
169169

170170
static unsigned getIndexedLoadStorePtrIdx(const RVVIntrinsic *RVVI) {
171171
// We need a special rule for segment load/store since the data width is not
172-
// encoded in the instrinsic name itself.
172+
// encoded in the intrinsic name itself.
173173
const StringRef IRName = RVVI->getIRName();
174174
constexpr unsigned RVV_VTA = 0x1;
175175
constexpr unsigned RVV_VMA = 0x2;
@@ -192,7 +192,7 @@ static unsigned getIndexedLoadStorePtrIdx(const RVVIntrinsic *RVVI) {
192192
static unsigned getSegInstLog2SEW(StringRef InstName) {
193193
// clang-format off
194194
// We need a special rule for indexed segment load/store since the data width
195-
// is not encoded in the instrinsic name itself.
195+
// is not encoded in the intrinsic name itself.
196196
if (InstName.starts_with("vloxseg") || InstName.starts_with("vluxseg") ||
197197
InstName.starts_with("vsoxseg") || InstName.starts_with("vsuxseg"))
198198
return (unsigned)-1;

flang/docs/OptionComparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ eN
5353
</td>
5454
<td>fdec,
5555
<p>
56-
fall-instrinsics
56+
fall-intrinsics
5757
</td>
5858
<td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=297">qxlf77</a>,
5959
<p>

flang/include/flang/Runtime/magic-numbers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ The denorm value is a nonstandard extension.
107107

108108
#if 0
109109
ieee_round_type values
110-
The values are those of the llvm.get.rounding instrinsic, which is assumed by
110+
The values are those of the llvm.get.rounding intrinsic, which is assumed by
111111
ieee_arithmetic module rounding procedures.
112112
#endif
113113
#define _FORTRAN_RUNTIME_IEEE_TO_ZERO 0

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
16901690
// MAX and MIN (and others that map to them) allow their last argument to
16911691
// be repeated indefinitely. The actualForDummy vector is sized
16921692
// and null-initialized to the non-repeated dummy argument count
1693-
// for other instrinsics.
1693+
// for other intrinsics.
16941694
bool isMaxMin{dummyArgPatterns > 0 &&
16951695
dummy[dummyArgPatterns - 1].optionality == Optionality::repeats};
16961696
std::vector<ActualArgument *> actualForDummy(

0 commit comments

Comments
 (0)