[PATCH] D70113: Mark llvm::ConstantExpr::getAsInstruction as const

Alex Denisov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 02:31:17 PST 2019


AlexDenisov created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
AlexDenisov added reviewers: jmolloy, majnemer.

getAsInstruction is the only non-const member method.
It is impossible to enforce const-correctness because of it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70113

Files:
  llvm/include/llvm/IR/Constants.h
  llvm/lib/IR/Constants.cpp


Index: llvm/lib/IR/Constants.cpp
===================================================================
--- llvm/lib/IR/Constants.cpp
+++ llvm/lib/IR/Constants.cpp
@@ -3004,7 +3004,7 @@
       NewOps, this, From, To, NumUpdated, OperandNo);
 }
 
-Instruction *ConstantExpr::getAsInstruction() {
+Instruction *ConstantExpr::getAsInstruction() const {
   SmallVector<Value *, 4> ValueOperands(op_begin(), op_end());
   ArrayRef<Value*> Ops(ValueOperands);
 
Index: llvm/include/llvm/IR/Constants.h
===================================================================
--- llvm/include/llvm/IR/Constants.h
+++ llvm/include/llvm/IR/Constants.h
@@ -1250,7 +1250,7 @@
   /// which would take a ConstantExpr parameter, but that would have spread
   /// implementation details of ConstantExpr outside of Constants.cpp, which
   /// would make it harder to remove ConstantExprs altogether.
-  Instruction *getAsInstruction();
+  Instruction *getAsInstruction() const;
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static bool classof(const Value *V) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70113.228836.patch
Type: text/x-patch
Size: 1070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191112/d3bad833/attachment.bin>


More information about the llvm-commits mailing list