Skip to content

Commit 5ca4128

Browse files
committedAug 20, 2018
[PSV] Update API to be able to use TargetCustom without UB.
getTargetCustom() requires values for "Kind" in the constructor that are not in the PSVKind enum. Passing a value that is not inside an enum as an argument to a constructor of the type of the enum is UB. Changing to the underlying type of the enum would solve the UB Differential Revision: https://reviews.llvm.org/D50909 llvm-svn: 340200
1 parent 66555a7 commit 5ca4128

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed
 

‎llvm/include/llvm/CodeGen/PseudoSourceValue.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
3636
/// below the stack frame (e.g., argument space), or constant pool.
3737
class PseudoSourceValue {
3838
public:
39-
enum PSVKind {
39+
enum PSVKind : unsigned {
4040
Stack,
4141
GOT,
4242
JumpTable,
@@ -48,7 +48,7 @@ class PseudoSourceValue {
4848
};
4949

5050
private:
51-
PSVKind Kind;
51+
unsigned Kind;
5252
unsigned AddressSpace;
5353
friend raw_ostream &llvm::operator<<(raw_ostream &OS,
5454
const PseudoSourceValue* PSV);
@@ -60,11 +60,11 @@ class PseudoSourceValue {
6060
virtual void printCustom(raw_ostream &O) const;
6161

6262
public:
63-
explicit PseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII);
63+
explicit PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
6464

6565
virtual ~PseudoSourceValue();
6666

67-
PSVKind kind() const { return Kind; }
67+
unsigned kind() const { return Kind; }
6868

6969
bool isStack() const { return Kind == Stack; }
7070
bool isGOT() const { return Kind == GOT; }
@@ -116,7 +116,7 @@ class FixedStackPseudoSourceValue : public PseudoSourceValue {
116116

117117
class CallEntryPseudoSourceValue : public PseudoSourceValue {
118118
protected:
119-
CallEntryPseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII);
119+
CallEntryPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);
120120

121121
public:
122122
bool isConstant(const MachineFrameInfo *) const override;

‎llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ class TargetInstrInfo : public MCInstrInfo {
10631063
/// getAddressSpaceForPseudoSourceKind - Given the kind of memory
10641064
/// (e.g. stack) the target returns the corresponding address space.
10651065
virtual unsigned
1066-
getAddressSpaceForPseudoSourceKind(PseudoSourceValue::PSVKind Kind) const {
1066+
getAddressSpaceForPseudoSourceKind(unsigned Kind) const {
10671067
return 0;
10681068
}
10691069

‎llvm/lib/CodeGen/PseudoSourceValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const char *const PSVNames[] = {
2525
"Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
2626
"GlobalValueCallEntry", "ExternalSymbolCallEntry"};
2727

28-
PseudoSourceValue::PseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII)
28+
PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
2929
: Kind(Kind) {
3030
AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
3131
}
@@ -81,7 +81,7 @@ void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
8181
}
8282

8383
CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
84-
PSVKind Kind, const TargetInstrInfo &TII)
84+
unsigned Kind, const TargetInstrInfo &TII)
8585
: PseudoSourceValue(Kind, TII) {}
8686

8787
bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {

‎llvm/lib/Target/AMDGPU/R600InstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ void R600InstrInfo::clearFlag(MachineInstr &MI, unsigned Operand,
15001500
}
15011501

15021502
unsigned R600InstrInfo::getAddressSpaceForPseudoSourceKind(
1503-
PseudoSourceValue::PSVKind Kind) const {
1503+
unsigned Kind) const {
15041504
switch (Kind) {
15051505
case PseudoSourceValue::Stack:
15061506
case PseudoSourceValue::FixedStack:

‎llvm/lib/Target/AMDGPU/R600InstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class R600InstrInfo final : public R600GenInstrInfo {
324324
}
325325

326326
unsigned getAddressSpaceForPseudoSourceKind(
327-
PseudoSourceValue::PSVKind Kind) const override;
327+
unsigned Kind) const override;
328328
};
329329

330330
namespace R600 {

‎llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) const {
19331933
}
19341934

19351935
unsigned SIInstrInfo::getAddressSpaceForPseudoSourceKind(
1936-
PseudoSourceValue::PSVKind Kind) const {
1936+
unsigned Kind) const {
19371937
switch(Kind) {
19381938
case PseudoSourceValue::Stack:
19391939
case PseudoSourceValue::FixedStack:

‎llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
276276
unsigned TrueReg, unsigned FalseReg) const;
277277

278278
unsigned getAddressSpaceForPseudoSourceKind(
279-
PseudoSourceValue::PSVKind Kind) const override;
279+
unsigned Kind) const override;
280280

281281
bool
282282
areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,

0 commit comments

Comments
 (0)
Please sign in to comment.