Skip to content

Commit 93f3d41

Browse files
topperccor3ntin
authored andcommitted
[FrameLowering] Use MCRegister instead of Register in CalleeSavedInfo. NFC (llvm#128095)
Callee saved registers should always be phyiscal registers. They are often passed directly to other functions that take MCRegister like getMinimalPhysRegClass or TargetRegisterClass::contains. Unfortunately, sometimes the MCRegister is compared to a Register which gave an ambiguous comparison error when the MCRegister is on the LHS. Adding a MCRegister==Register comparison operator created more ambiguous comparison errors elsewhere. These cases were usually comparing against a base or frame pointer register that is a physical register in a Register. For those I added an explicit conversion of Register to MCRegister to fix the error.
1 parent 5815990 commit 93f3d41

32 files changed

+110
-111
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Improvements to Clang's diagnostics
147147
- The ``-Wunsafe-buffer-usage`` warning has been updated to warn
148148
about unsafe libc function calls. Those new warnings are emitted
149149
under the subgroup ``-Wunsafe-buffer-usage-in-libc-call``.
150+
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
151+
``-Wno-error=parentheses``.
150152

151153
Improvements to Clang's time-trace
152154
----------------------------------

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7126,7 +7126,7 @@ def note_precedence_conditional_first : Note<
71267126

71277127
def warn_consecutive_comparison : Warning<
71287128
"comparisons like 'X<=Y<=Z' don't have their mathematical meaning">,
7129-
InGroup<Parentheses>;
7129+
InGroup<Parentheses>, DefaultError;
71307130

71317131
def warn_enum_constant_in_bool_context : Warning<
71327132
"converting the enum constant to a boolean">,

clang/test/Sema/bool-compare.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void f(int x, int y, int z) {
8585
if ((a<y) != -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}}
8686

8787
if ((a<y) == z) {} // no warning
88-
if (a>y<z) {} // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
88+
if (a>y<z) {} // expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
8989
if ((a<y) > z) {} // no warning
9090
if((a<y)>(z<y)) {} // no warning
9191
if((a<y)==(z<y)){} // no warning
@@ -145,7 +145,7 @@ void f(int x, int y, int z) {
145145
if (-1 !=(a<y)) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}}
146146

147147
if (z ==(a<y)) {} // no warning
148-
if (z<a>y) {} // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
148+
if (z<a>y) {} // expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
149149
if (z > (a<y)) {} // no warning
150150
if((z<y)>(a<y)) {} // no warning
151151
if((z<y)==(a<y)){} // no warning

clang/test/Sema/parentheses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
2-
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
1+
// RUN: %clang_cc1 -Wno-error=parentheses -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -Wno-error=parentheses -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
33

44
bool someConditionFunc();
55

clang/test/SemaCXX/bool-compare.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void f(int x, int y, int z) {
9898
if ((a<y) != -1) {}// expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}
9999

100100
if ((a<y) == z) {} // no warning
101-
if (a>y<z) {} // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
101+
if (a>y<z) {} // expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
102102
if ((a<y) > z) {} // no warning
103103
if((a<y)>(z<y)) {} // no warning
104104
if((a<y)==(z<y)){} // no warning
@@ -159,7 +159,7 @@ void f(int x, int y, int z) {
159159
if (-1 !=(a<y)) {} // expected-warning {{comparison of constant -1 with expression of type 'bool' is always true}}
160160

161161
if (z ==(a<y)) {} // no warning
162-
if (z<a>y) {} // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
162+
if (z<a>y) {} // expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
163163
if (z > (a<y)) {} // no warning
164164
if((z<y)>(a<y)) {} // no warning
165165
if((z<y)==(a<y)){} // no warning
@@ -186,8 +186,7 @@ template<typename T, typename U, typename V> struct X6 {
186186
return v; // expected-error{{cannot initialize return object of type}}
187187
}
188188
bool r;
189-
// FIXME: We should warn here, DiagRuntimeBehavior does currently not detect this.
190-
if(r<0){}
189+
if(r<0){} // expected-warning {{result of comparison of constant 0 with expression of type 'bool' is always false}}
191190

192191
if (T x = t) {
193192
t = x;

clang/test/SemaCXX/cxx2a-adl-only-template-id.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int e = h<0>(q); // ok, found by unqualified lookup
2727
void fn() {
2828
f<0>(q);
2929
int f;
30-
f<0>(q); // expected-error {{invalid operands to binary expression}} // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
30+
f<0>(q); // expected-error {{invalid operands to binary expression}} // expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
3131
}
3232

3333
void disambig() {

clang/test/SemaTemplate/typo-dependent-name.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct X : Base<T> {
2020
bool f(T other) {
2121
// A pair of comparisons; 'inner' is a dependent name so can't be assumed
2222
// to be a template.
23-
return this->inner < other > ::z; // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
23+
return this->inner < other > ::z; // expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
2424
}
2525
};
2626

clang/test/SemaTemplate/typo-template-name.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace InExpr {
3636

3737
// These are valid expressions.
3838
foo<foo; // expected-warning {{self-comparison}}
39-
foo<int()>(0); // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
39+
foo<int()>(0); // expected-error {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
4040
foo<int(), true>(false);
4141
foo<Base{}.n;
4242
}

llvm/include/llvm/CodeGen/MachineFrameInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AllocaInst;
3232
/// Callee saved reg can also be saved to a different register rather than
3333
/// on the stack by setting DstReg instead of FrameIdx.
3434
class CalleeSavedInfo {
35-
Register Reg;
35+
MCRegister Reg;
3636
union {
3737
int FrameIdx;
3838
unsigned DstReg;
@@ -58,7 +58,7 @@ class CalleeSavedInfo {
5858
explicit CalleeSavedInfo(unsigned R, int FI = 0) : Reg(R), FrameIdx(FI) {}
5959

6060
// Accessors.
61-
Register getReg() const { return Reg; }
61+
MCRegister getReg() const { return Reg; }
6262
int getFrameIdx() const { return FrameIdx; }
6363
unsigned getDstReg() const { return DstReg; }
6464
void setFrameIdx(int FI) {

llvm/lib/CodeGen/LivePhysRegs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void llvm::recomputeLivenessFlags(MachineBasicBlock &MBB) {
301301
// the last instruction in the block.
302302
if (MI.isReturn() && MFI.isCalleeSavedInfoValid()) {
303303
for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) {
304-
if (Info.getReg() == Reg) {
304+
if (Info.getReg() == Reg.asMCReg()) {
305305
IsNotLive = !Info.isRestored();
306306
break;
307307
}

0 commit comments

Comments
 (0)