Skip to content

Commit

Permalink
[PSV] Update API to be able to use TargetCustom without UB.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kariddi committed Aug 20, 2018
1 parent 66555a7 commit 5ca4128
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions llvm/include/llvm/CodeGen/PseudoSourceValue.h
Expand Up @@ -36,7 +36,7 @@ raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
/// below the stack frame (e.g., argument space), or constant pool.
class PseudoSourceValue {
public:
enum PSVKind {
enum PSVKind : unsigned {
Stack,
GOT,
JumpTable,
Expand All @@ -48,7 +48,7 @@ class PseudoSourceValue {
};

private:
PSVKind Kind;
unsigned Kind;
unsigned AddressSpace;
friend raw_ostream &llvm::operator<<(raw_ostream &OS,
const PseudoSourceValue* PSV);
Expand All @@ -60,11 +60,11 @@ class PseudoSourceValue {
virtual void printCustom(raw_ostream &O) const;

public:
explicit PseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII);
explicit PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);

virtual ~PseudoSourceValue();

PSVKind kind() const { return Kind; }
unsigned kind() const { return Kind; }

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

class CallEntryPseudoSourceValue : public PseudoSourceValue {
protected:
CallEntryPseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII);
CallEntryPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII);

public:
bool isConstant(const MachineFrameInfo *) const override;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/TargetInstrInfo.h
Expand Up @@ -1063,7 +1063,7 @@ class TargetInstrInfo : public MCInstrInfo {
/// getAddressSpaceForPseudoSourceKind - Given the kind of memory
/// (e.g. stack) the target returns the corresponding address space.
virtual unsigned
getAddressSpaceForPseudoSourceKind(PseudoSourceValue::PSVKind Kind) const {
getAddressSpaceForPseudoSourceKind(unsigned Kind) const {
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/PseudoSourceValue.cpp
Expand Up @@ -25,7 +25,7 @@ static const char *const PSVNames[] = {
"Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack",
"GlobalValueCallEntry", "ExternalSymbolCallEntry"};

PseudoSourceValue::PseudoSourceValue(PSVKind Kind, const TargetInstrInfo &TII)
PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII)
: Kind(Kind) {
AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind);
}
Expand Down Expand Up @@ -81,7 +81,7 @@ void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const {
}

CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(
PSVKind Kind, const TargetInstrInfo &TII)
unsigned Kind, const TargetInstrInfo &TII)
: PseudoSourceValue(Kind, TII) {}

bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/R600InstrInfo.cpp
Expand Up @@ -1500,7 +1500,7 @@ void R600InstrInfo::clearFlag(MachineInstr &MI, unsigned Operand,
}

unsigned R600InstrInfo::getAddressSpaceForPseudoSourceKind(
PseudoSourceValue::PSVKind Kind) const {
unsigned Kind) const {
switch (Kind) {
case PseudoSourceValue::Stack:
case PseudoSourceValue::FixedStack:
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/R600InstrInfo.h
Expand Up @@ -324,7 +324,7 @@ class R600InstrInfo final : public R600GenInstrInfo {
}

unsigned getAddressSpaceForPseudoSourceKind(
PseudoSourceValue::PSVKind Kind) const override;
unsigned Kind) const override;
};

namespace R600 {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Expand Up @@ -1933,7 +1933,7 @@ bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) const {
}

unsigned SIInstrInfo::getAddressSpaceForPseudoSourceKind(
PseudoSourceValue::PSVKind Kind) const {
unsigned Kind) const {
switch(Kind) {
case PseudoSourceValue::Stack:
case PseudoSourceValue::FixedStack:
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/SIInstrInfo.h
Expand Up @@ -276,7 +276,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
unsigned TrueReg, unsigned FalseReg) const;

unsigned getAddressSpaceForPseudoSourceKind(
PseudoSourceValue::PSVKind Kind) const override;
unsigned Kind) const override;

bool
areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,
Expand Down

0 comments on commit 5ca4128

Please sign in to comment.