Skip to content

Commit

Permalink
check that some parameter attributes are not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Apr 6, 2024
1 parent 2fccad2 commit 9b7d1ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 11 additions & 0 deletions ir/attrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ ostream& operator<<(ostream &os, const ParamAttrs &attr) {
os << "zeroext ";
if (attr.has(ParamAttrs::SignExt))
os << "signext ";
if (attr.has(ParamAttrs::InReg))
os << "inreg ";
if (attr.has(ParamAttrs::AllocPtr))
os << "allocptr ";
if (attr.has(ParamAttrs::AllocAlign))
Expand Down Expand Up @@ -299,6 +301,15 @@ bool ParamAttrs::refinedBy(const ParamAttrs &other) const {
if ((bits & other_params) != other_params)
return false;

// check attributes that cannot change
attrs =
SignExt |
ZeroExt |
InReg
;
if ((bits & attrs) != (other.bits & attrs))
return false;

return derefBytes == other.derefBytes &&
derefOrNullBytes == other.derefOrNullBytes &&
blockSize == other.blockSize &&
Expand Down
4 changes: 2 additions & 2 deletions ir/attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class ParamAttrs final {
NoUndef = 1<<6, Align = 1<<7, Returned = 1<<8,
NoAlias = 1<<9, DereferenceableOrNull = 1<<10,
AllocPtr = 1<<11, AllocAlign = 1<<12,
ZeroExt = 1<<13, SignExt = 1<<14, NoFPClass = 1<<15,
IsArg = 1<<16 };
ZeroExt = 1<<13, SignExt = 1<<14, InReg = 1<<15,
NoFPClass = 1<<16, IsArg = 1<<17 };

ParamAttrs(unsigned bits = None) : bits(bits) {}

Expand Down
5 changes: 1 addition & 4 deletions llvm_util/llvm2alive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,11 +1352,8 @@ class llvm2alive_ : public llvm::InstVisitor<llvm2alive_, unique_ptr<Instr>> {
continue;

switch (llvmattr.getKindAsEnum()) {

// TODO: SignExt, ZeroExt, and InReg are not important for IR
// verification, but we should check that they don't change

case llvm::Attribute::InReg:
attrs.set(ParamAttrs::InReg);
break;

case llvm::Attribute::SExt:
Expand Down

0 comments on commit 9b7d1ab

Please sign in to comment.