Blame SOURCES/bpftrace-0.16.0-IR-builder-get-rid-of-getPointerElementType-calls.patch

ec494a
From dfc1f92653707c8d11bdb3be98e68f8297b9bc71 Mon Sep 17 00:00:00 2001
ec494a
From: Viktor Malik <viktor.malik@gmail.com>
ec494a
Date: Mon, 10 Oct 2022 14:26:38 +0200
ec494a
Subject: [PATCH] IR builder: get rid of getPointerElementType calls
ec494a
ec494a
Usage of Value::getPointerElementType is deprecated and will be dropped
ec494a
in LLVM 16 [1].
ec494a
ec494a
There are several places where we use this method:
ec494a
- function (value) calls - the called function type is usually
ec494a
  available, so just pass it to createCall, the only exception is
ec494a
  CreateProbeReadStr which must have been refactored
ec494a
- getting the type of alloca instruction - there is a dedicated
ec494a
  AllocaInst::getAllocatedType method that can be used instead
ec494a
- strncmp - pass sizes of the strings to CreateStrncmp to be able to get
ec494a
  the correct string type (which is array of uint8)
ec494a
ec494a
[1] https://llvm.org/docs/OpaquePointers.html
ec494a
---
ec494a
 src/ast/irbuilderbpf.cpp        | 143 ++++++++++++--------------------
ec494a
 src/ast/irbuilderbpf.h          |  23 +++--
ec494a
 src/ast/passes/codegen_llvm.cpp |  30 +++++--
ec494a
 3 files changed, 86 insertions(+), 110 deletions(-)
ec494a
ec494a
diff --git a/src/ast/irbuilderbpf.cpp b/src/ast/irbuilderbpf.cpp
ec494a
index d49883f7..4036b2df 100644
ec494a
--- a/src/ast/irbuilderbpf.cpp
ec494a
+++ b/src/ast/irbuilderbpf.cpp
ec494a
@@ -288,17 +288,16 @@ CallInst *IRBuilderBPF::CreateHelperCall(libbpf::bpf_func_id func_id,
ec494a
   Constant *helper_func = ConstantExpr::getCast(Instruction::IntToPtr,
ec494a
                                                 getInt64(func_id),
ec494a
                                                 helper_ptr_type);
ec494a
-  return createCall(helper_func, args, Name);
ec494a
+  return createCall(helper_type, helper_func, args, Name);
ec494a
 }
ec494a
 
ec494a
-CallInst *IRBuilderBPF::createCall(Value *callee,
ec494a
+CallInst *IRBuilderBPF::createCall(FunctionType *callee_type,
ec494a
+                                   Value *callee,
ec494a
                                    ArrayRef<Value *> args,
ec494a
                                    const Twine &Name)
ec494a
 {
ec494a
 #if LLVM_VERSION_MAJOR >= 11
ec494a
-  auto *calleePtrType = cast<PointerType>(callee->getType());
ec494a
-  auto *calleeType = cast<FunctionType>(calleePtrType->getPointerElementType());
ec494a
-  return CreateCall(calleeType, callee, args, Name);
ec494a
+  return CreateCall(callee_type, callee, args, Name);
ec494a
 #else
ec494a
   return CreateCall(callee, args, Name);
ec494a
 #endif
ec494a
@@ -307,7 +306,7 @@ CallInst *IRBuilderBPF::createCall(Value *callee,
ec494a
 CallInst *IRBuilderBPF::CreateBpfPseudoCallId(int mapid)
ec494a
 {
ec494a
   Function *pseudo_func = module_.getFunction("llvm.bpf.pseudo");
ec494a
-  return createCall(pseudo_func,
ec494a
+  return CreateCall(pseudo_func,
ec494a
                     { getInt64(BPF_PSEUDO_MAP_FD), getInt64(mapid) },
ec494a
                     "pseudo");
ec494a
 }
ec494a
@@ -346,7 +345,8 @@ CallInst *IRBuilderBPF::createMapLookup(int mapid, Value *key)
ec494a
       Instruction::IntToPtr,
ec494a
       getInt64(libbpf::BPF_FUNC_map_lookup_elem),
ec494a
       lookup_func_ptr_type);
ec494a
-  return createCall(lookup_func, { map_ptr, key }, "lookup_elem");
ec494a
+  return createCall(
ec494a
+      lookup_func_type, lookup_func, { map_ptr, key }, "lookup_elem");
ec494a
 }
ec494a
 
ec494a
 CallInst *IRBuilderBPF::CreateGetJoinMap(Value *ctx, const location &loc)
ec494a
@@ -397,8 +397,7 @@ Value *IRBuilderBPF::CreateMapLookupElem(Value *ctx,
ec494a
     CREATE_MEMCPY(value, call, type.GetSize(), 1);
ec494a
   else
ec494a
   {
ec494a
-    assert(value->getType()->isPointerTy() &&
ec494a
-           (value->getType()->getPointerElementType() == getInt64Ty()));
ec494a
+    assert(value->getAllocatedType() == getInt64Ty());
ec494a
     // createMapLookup  returns an u8*
ec494a
     auto *cast = CreatePointerCast(call, value->getType(), "cast");
ec494a
     CreateStore(CreateLoad(getInt64Ty(), cast), value);
ec494a
@@ -448,7 +447,8 @@ void IRBuilderBPF::CreateMapUpdateElem(Value *ctx,
ec494a
       Instruction::IntToPtr,
ec494a
       getInt64(libbpf::BPF_FUNC_map_update_elem),
ec494a
       update_func_ptr_type);
ec494a
-  CallInst *call = createCall(update_func,
ec494a
+  CallInst *call = createCall(update_func_type,
ec494a
+                              update_func,
ec494a
                               { map_ptr, key, val, flags },
ec494a
                               "update_elem");
ec494a
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_map_update_elem, loc);
ec494a
@@ -472,7 +472,8 @@ void IRBuilderBPF::CreateMapDeleteElem(Value *ctx,
ec494a
       Instruction::IntToPtr,
ec494a
       getInt64(libbpf::BPF_FUNC_map_delete_elem),
ec494a
       delete_func_ptr_type);
ec494a
-  CallInst *call = createCall(delete_func, { map_ptr, key }, "delete_elem");
ec494a
+  CallInst *call = createCall(
ec494a
+      delete_func_type, delete_func, { map_ptr, key }, "delete_elem");
ec494a
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_map_delete_elem, loc);
ec494a
 }
ec494a
 
ec494a
@@ -508,72 +509,53 @@ void IRBuilderBPF::CreateProbeRead(Value *ctx,
ec494a
   Constant *proberead_func = ConstantExpr::getCast(Instruction::IntToPtr,
ec494a
                                                    getInt64(read_fn),
ec494a
                                                    proberead_func_ptr_type);
ec494a
-  CallInst *call = createCall(proberead_func,
ec494a
+  CallInst *call = createCall(proberead_func_type,
ec494a
+                              proberead_func,
ec494a
                               { dst, size, src },
ec494a
                               probeReadHelperName(read_fn));
ec494a
   CreateHelperErrorCond(ctx, call, read_fn, loc);
ec494a
 }
ec494a
 
ec494a
-Constant *IRBuilderBPF::createProbeReadStrFn(llvm::Type *dst,
ec494a
-                                             llvm::Type *src,
ec494a
-                                             AddrSpace as)
ec494a
-{
ec494a
-  assert(src && (src->isIntegerTy() || src->isPointerTy()));
ec494a
-  // int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
ec494a
-  FunctionType *probereadstr_func_type = FunctionType::get(
ec494a
-      getInt64Ty(), { dst, getInt32Ty(), src }, false);
ec494a
-  PointerType *probereadstr_func_ptr_type = PointerType::get(
ec494a
-      probereadstr_func_type, 0);
ec494a
-  return ConstantExpr::getCast(Instruction::IntToPtr,
ec494a
-                               getInt64(selectProbeReadHelper(as, true)),
ec494a
-                               probereadstr_func_ptr_type);
ec494a
-}
ec494a
-
ec494a
 CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
ec494a
-                                           AllocaInst *dst,
ec494a
+                                           Value *dst,
ec494a
                                            size_t size,
ec494a
                                            Value *src,
ec494a
                                            AddrSpace as,
ec494a
                                            const location &loc)
ec494a
 {
ec494a
-  assert(ctx && ctx->getType() == getInt8PtrTy());
ec494a
   return CreateProbeReadStr(ctx, dst, getInt32(size), src, as, loc);
ec494a
 }
ec494a
 
ec494a
 CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
ec494a
                                            Value *dst,
ec494a
-                                           size_t size,
ec494a
-                                           Value *src,
ec494a
-                                           AddrSpace as,
ec494a
-                                           const location &loc)
ec494a
-{
ec494a
-  assert(ctx && ctx->getType() == getInt8PtrTy());
ec494a
-  Constant *fn = createProbeReadStrFn(dst->getType(), src->getType(), as);
ec494a
-  auto read_fn = selectProbeReadHelper(as, true);
ec494a
-  CallInst *call = createCall(fn,
ec494a
-                              { dst, getInt32(size), src },
ec494a
-                              probeReadHelperName(read_fn));
ec494a
-  CreateHelperErrorCond(ctx, call, read_fn, loc);
ec494a
-  return call;
ec494a
-}
ec494a
-
ec494a
-CallInst *IRBuilderBPF::CreateProbeReadStr(Value *ctx,
ec494a
-                                           AllocaInst *dst,
ec494a
                                            llvm::Value *size,
ec494a
                                            Value *src,
ec494a
                                            AddrSpace as,
ec494a
                                            const location &loc)
ec494a
 {
ec494a
   assert(ctx && ctx->getType() == getInt8PtrTy());
ec494a
-  assert(dst && dst->getAllocatedType()->isArrayTy() &&
ec494a
-         dst->getAllocatedType()->getArrayElementType() == getInt8Ty());
ec494a
   assert(size && size->getType()->isIntegerTy());
ec494a
+  if (auto *dst_alloca = dyn_cast<AllocaInst>(dst))
ec494a
+  {
ec494a
+    assert(dst_alloca->getAllocatedType()->isArrayTy() &&
ec494a
+           dst_alloca->getAllocatedType()->getArrayElementType() ==
ec494a
+               getInt8Ty());
ec494a
+  }
ec494a
 
ec494a
-  auto *size_i32 = CreateIntCast(size, getInt32Ty(), false);
ec494a
+  auto *size_i32 = size;
ec494a
+  if (size_i32->getType()->getScalarSizeInBits() != 32)
ec494a
+    size_i32 = CreateIntCast(size_i32, getInt32Ty(), false);
ec494a
 
ec494a
-  Constant *fn = createProbeReadStrFn(dst->getType(), src->getType(), as);
ec494a
   auto read_fn = selectProbeReadHelper(as, true);
ec494a
-  CallInst *call = createCall(fn,
ec494a
+  // int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
ec494a
+  FunctionType *probereadstr_func_type = FunctionType::get(
ec494a
+      getInt64Ty(), { dst->getType(), getInt32Ty(), src->getType() }, false);
ec494a
+  PointerType *probereadstr_func_ptr_type = PointerType::get(
ec494a
+      probereadstr_func_type, 0);
ec494a
+  Constant *probereadstr_callee = ConstantExpr::getCast(
ec494a
+      Instruction::IntToPtr, getInt64(read_fn), probereadstr_func_ptr_type);
ec494a
+  CallInst *call = createCall(probereadstr_func_type,
ec494a
+                              probereadstr_callee,
ec494a
                               { dst, size_i32, src },
ec494a
                               probeReadHelperName(read_fn));
ec494a
   CreateHelperErrorCond(ctx, call, read_fn, loc);
ec494a
@@ -732,8 +714,10 @@ Value *IRBuilderBPF::CreateUSDTReadArgument(Value *ctx,
ec494a
   return result;
ec494a
 }
ec494a
 
ec494a
-Value *IRBuilderBPF::CreateStrncmp(Value *val1,
ec494a
-                                   Value *val2,
ec494a
+Value *IRBuilderBPF::CreateStrncmp(Value *str1,
ec494a
+                                   uint64_t str1_size,
ec494a
+                                   Value *str2,
ec494a
+                                   uint64_t str2_size,
ec494a
                                    uint64_t n,
ec494a
                                    bool inverse)
ec494a
 {
ec494a
@@ -762,40 +746,21 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
ec494a
   // Check if the compared strings are literals.
ec494a
   // If so, we can avoid storing the literal in memory.
ec494a
   std::optional<std::string> literal1;
ec494a
-  if (auto constString1 = dyn_cast<ConstantDataArray>(val1))
ec494a
+  if (auto constString1 = dyn_cast<ConstantDataArray>(str1))
ec494a
     literal1 = constString1->getAsString();
ec494a
-  else if (isa<ConstantAggregateZero>(val1))
ec494a
+  else if (isa<ConstantAggregateZero>(str1))
ec494a
     literal1 = "";
ec494a
   else
ec494a
     literal1 = std::nullopt;
ec494a
 
ec494a
   std::optional<std::string> literal2;
ec494a
-  if (auto constString2 = dyn_cast<ConstantDataArray>(val2))
ec494a
+  if (auto constString2 = dyn_cast<ConstantDataArray>(str2))
ec494a
     literal2 = constString2->getAsString();
ec494a
-  else if (isa<ConstantAggregateZero>(val2))
ec494a
+  else if (isa<ConstantAggregateZero>(str2))
ec494a
     literal2 = "";
ec494a
   else
ec494a
     literal2 = std::nullopt;
ec494a
 
ec494a
-  auto *val1p = dyn_cast<PointerType>(val1->getType());
ec494a
-  auto *val2p = dyn_cast<PointerType>(val2->getType());
ec494a
-#ifndef NDEBUG
ec494a
-  if (!literal1)
ec494a
-  {
ec494a
-    assert(val1p);
ec494a
-    assert(val1p->getPointerElementType()->isArrayTy() &&
ec494a
-           val1p->getPointerElementType()->getArrayElementType() ==
ec494a
-               getInt8Ty());
ec494a
-  }
ec494a
-  if (!literal2)
ec494a
-  {
ec494a
-    assert(val2p);
ec494a
-    assert(val2p->getPointerElementType()->isArrayTy() &&
ec494a
-           val2p->getPointerElementType()->getArrayElementType() ==
ec494a
-               getInt8Ty());
ec494a
-  }
ec494a
-#endif
ec494a
-
ec494a
   Function *parent = GetInsertBlock()->getParent();
ec494a
   AllocaInst *store = CreateAllocaBPF(getInt1Ty(), "strcmp.result");
ec494a
   BasicBlock *str_ne = BasicBlock::Create(module_.getContext(),
ec494a
@@ -822,8 +787,8 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
ec494a
       l = getInt8(literal1->c_str()[i]);
ec494a
     else
ec494a
     {
ec494a
-      auto *ptr_l = CreateGEP(val1p->getPointerElementType(),
ec494a
-                              val1,
ec494a
+      auto *ptr_l = CreateGEP(ArrayType::get(getInt8Ty(), str1_size),
ec494a
+                              str1,
ec494a
                               { getInt32(0), getInt32(i) });
ec494a
       l = CreateLoad(getInt8Ty(), ptr_l);
ec494a
     }
ec494a
@@ -833,8 +798,8 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
ec494a
       r = getInt8(literal2->c_str()[i]);
ec494a
     else
ec494a
     {
ec494a
-      auto *ptr_r = CreateGEP(val2p->getPointerElementType(),
ec494a
-                              val2,
ec494a
+      auto *ptr_r = CreateGEP(ArrayType::get(getInt8Ty(), str2_size),
ec494a
+                              str2,
ec494a
                               { getInt32(0), getInt32(i) });
ec494a
       r = CreateLoad(getInt8Ty(), ptr_r);
ec494a
     }
ec494a
@@ -994,11 +959,9 @@ void IRBuilderBPF::CreateGetCurrentComm(Value *ctx,
ec494a
                                         size_t size,
ec494a
                                         const location &loc)
ec494a
 {
ec494a
-  assert(buf->getType()->getPointerElementType()->isArrayTy() &&
ec494a
-         buf->getType()->getPointerElementType()->getArrayNumElements() >=
ec494a
-             size &&
ec494a
-         buf->getType()->getPointerElementType()->getArrayElementType() ==
ec494a
-             getInt8Ty());
ec494a
+  assert(buf->getAllocatedType()->isArrayTy() &&
ec494a
+         buf->getAllocatedType()->getArrayNumElements() >= size &&
ec494a
+         buf->getAllocatedType()->getArrayElementType() == getInt8Ty());
ec494a
 
ec494a
   // long bpf_get_current_comm(char *buf, int size_of_buf)
ec494a
   // Return: 0 on success or negative error
ec494a
@@ -1077,7 +1040,7 @@ void IRBuilderBPF::CreateSignal(Value *ctx, Value *sig, const location &loc)
ec494a
       Instruction::IntToPtr,
ec494a
       getInt64(libbpf::BPF_FUNC_send_signal),
ec494a
       signal_func_ptr_type);
ec494a
-  CallInst *call = createCall(signal_func, { sig }, "signal");
ec494a
+  CallInst *call = createCall(signal_func_type, signal_func, { sig }, "signal");
ec494a
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_send_signal, loc);
ec494a
 }
ec494a
 
ec494a
@@ -1091,7 +1054,7 @@ void IRBuilderBPF::CreateOverrideReturn(Value *ctx, Value *rc)
ec494a
   Constant *override_func = ConstantExpr::getCast(Instruction::IntToPtr,
ec494a
       getInt64(libbpf::BPF_FUNC_override_return),
ec494a
       override_func_ptr_type);
ec494a
-  createCall(override_func, { ctx, rc }, "override");
ec494a
+  createCall(override_func_type, override_func, { ctx, rc }, "override");
ec494a
 }
ec494a
 
ec494a
 CallInst *IRBuilderBPF::CreateSkbOutput(Value *skb,
ec494a
@@ -1126,7 +1089,8 @@ CallInst *IRBuilderBPF::CreateSkbOutput(Value *skb,
ec494a
       Instruction::IntToPtr,
ec494a
       getInt64(libbpf::BPF_FUNC_skb_output),
ec494a
       skb_output_func_ptr_type);
ec494a
-  CallInst *call = createCall(skb_output_func,
ec494a
+  CallInst *call = createCall(skb_output_func_type,
ec494a
+                              skb_output_func,
ec494a
                               { skb, map_ptr, flags, data, size_val },
ec494a
                               "skb_output");
ec494a
   return call;
ec494a
@@ -1320,7 +1284,8 @@ void IRBuilderBPF::CreateSeqPrintf(Value *ctx,
ec494a
                           CreateGEP(getInt64Ty(), meta, getInt64(0)),
ec494a
                           "seq");
ec494a
 
ec494a
-  CallInst *call = createCall(seq_printf_func,
ec494a
+  CallInst *call = createCall(seq_printf_func_type,
ec494a
+                              seq_printf_func,
ec494a
                               { seq, fmt, fmt_size, data, data_len },
ec494a
                               "seq_printf");
ec494a
   CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_seq_printf, loc);
ec494a
diff --git a/src/ast/irbuilderbpf.h b/src/ast/irbuilderbpf.h
ec494a
index e124911b..c9ffb545 100644
ec494a
--- a/src/ast/irbuilderbpf.h
ec494a
+++ b/src/ast/irbuilderbpf.h
ec494a
@@ -90,17 +90,11 @@ public:
ec494a
                        AddrSpace as,
ec494a
                        const location &loc;;
ec494a
   CallInst *CreateProbeReadStr(Value *ctx,
ec494a
-                               AllocaInst *dst,
ec494a
+                               Value *dst,
ec494a
                                llvm::Value *size,
ec494a
                                Value *src,
ec494a
                                AddrSpace as,
ec494a
                                const location &loc;;
ec494a
-  CallInst *CreateProbeReadStr(Value *ctx,
ec494a
-                               AllocaInst *dst,
ec494a
-                               size_t size,
ec494a
-                               Value *src,
ec494a
-                               AddrSpace as,
ec494a
-                               const location &loc;;
ec494a
   CallInst *CreateProbeReadStr(Value *ctx,
ec494a
                                Value *dst,
ec494a
                                size_t size,
ec494a
@@ -115,7 +109,12 @@ public:
ec494a
                                 pid_t pid,
ec494a
                                 AddrSpace as,
ec494a
                                 const location &loc;;
ec494a
-  Value *CreateStrncmp(Value *val1, Value *val2, uint64_t n, bool inverse);
ec494a
+  Value *CreateStrncmp(Value *str1,
ec494a
+                       uint64_t str1_size,
ec494a
+                       Value *str2,
ec494a
+                       uint64_t str2_size,
ec494a
+                       uint64_t n,
ec494a
+                       bool inverse);
ec494a
   CallInst *CreateGetNs(bool boot_time, const location &loc;;
ec494a
   CallInst *CreateGetPidTgid(const location &loc;;
ec494a
   CallInst *CreateGetCurrentCgroupId(const location &loc;;
ec494a
@@ -131,7 +130,10 @@ public:
ec494a
                              ArrayRef<Value *> args,
ec494a
                              const Twine &Name,
ec494a
                              const location *loc = nullptr);
ec494a
-  CallInst   *createCall(Value *callee, ArrayRef<Value *> args, const Twine &Name);
ec494a
+  CallInst *createCall(FunctionType *callee_type,
ec494a
+                       Value *callee,
ec494a
+                       ArrayRef<Value *> args,
ec494a
+                       const Twine &Name);
ec494a
   void        CreateGetCurrentComm(Value *ctx, AllocaInst *buf, size_t size, const location& loc);
ec494a
   void CreatePerfEventOutput(Value *ctx,
ec494a
                              Value *data,
ec494a
@@ -185,9 +187,6 @@ private:
ec494a
                                 AddrSpace as,
ec494a
                                 const location &loc;;
ec494a
   CallInst *createMapLookup(int mapid, Value *key);
ec494a
-  Constant *createProbeReadStrFn(llvm::Type *dst,
ec494a
-                                 llvm::Type *src,
ec494a
-                                 AddrSpace as);
ec494a
   libbpf::bpf_func_id selectProbeReadHelper(AddrSpace as, bool str);
ec494a
 
ec494a
   std::map<std::string, StructType *> structs_;
ec494a
diff --git a/src/ast/passes/codegen_llvm.cpp b/src/ast/passes/codegen_llvm.cpp
ec494a
index a818ca0b..2b888087 100644
ec494a
--- a/src/ast/passes/codegen_llvm.cpp
ec494a
+++ b/src/ast/passes/codegen_llvm.cpp
ec494a
@@ -1133,8 +1133,12 @@ void CodegenLLVM::visit(Call &call)
ec494a
     auto left_string = getString(left_arg);
ec494a
     auto right_string = getString(right_arg);
ec494a
 
ec494a
-    expr_ = b_.CreateStrncmp(
ec494a
-        left_string.first, right_string.first, size, false);
ec494a
+    expr_ = b_.CreateStrncmp(left_string.first,
ec494a
+                             left_string.second,
ec494a
+                             right_string.first,
ec494a
+                             right_string.second,
ec494a
+                             size,
ec494a
+                             false);
ec494a
   }
ec494a
   else if (call.func == "override")
ec494a
   {
ec494a
@@ -1269,8 +1273,7 @@ void CodegenLLVM::visit(Variable &var)
ec494a
   else
ec494a
   {
ec494a
     auto *var_alloca = variables_[var.ident];
ec494a
-    expr_ = b_.CreateLoad(var_alloca->getType()->getPointerElementType(),
ec494a
-                          var_alloca);
ec494a
+    expr_ = b_.CreateLoad(var_alloca->getAllocatedType(), var_alloca);
ec494a
   }
ec494a
 }
ec494a
 
ec494a
@@ -1310,7 +1313,12 @@ void CodegenLLVM::binop_string(Binop &binop)
ec494a
   auto right_string = getString(binop.right);
ec494a
 
ec494a
   size_t len = std::min(left_string.second, right_string.second);
ec494a
-  expr_ = b_.CreateStrncmp(left_string.first, right_string.first, len, inverse);
ec494a
+  expr_ = b_.CreateStrncmp(left_string.first,
ec494a
+                           left_string.second,
ec494a
+                           right_string.first,
ec494a
+                           right_string.second,
ec494a
+                           len,
ec494a
+                           inverse);
ec494a
 }
ec494a
 
ec494a
 void CodegenLLVM::binop_buf(Binop &binop)
ec494a
@@ -1334,7 +1342,12 @@ void CodegenLLVM::binop_buf(Binop &binop)
ec494a
 
ec494a
   size_t len = std::min(binop.left->type.GetSize(),
ec494a
                         binop.right->type.GetSize());
ec494a
-  expr_ = b_.CreateStrncmp(left_string, right_string, len, inverse);
ec494a
+  expr_ = b_.CreateStrncmp(left_string,
ec494a
+                           binop.left->type.GetSize(),
ec494a
+                           right_string,
ec494a
+                           binop.right->type.GetSize(),
ec494a
+                           len,
ec494a
+                           inverse);
ec494a
 }
ec494a
 
ec494a
 void CodegenLLVM::binop_int(Binop &binop)
ec494a
@@ -3528,9 +3541,8 @@ void CodegenLLVM::createIncDec(Unop &unop)
ec494a
   else if (unop.expr->is_variable)
ec494a
   {
ec494a
     Variable &var = static_cast<Variable &>(*unop.expr);
ec494a
-    Value *oldval = b_.CreateLoad(
ec494a
-        variables_[var.ident]->getType()->getPointerElementType(),
ec494a
-        variables_[var.ident]);
ec494a
+    Value *oldval = b_.CreateLoad(variables_[var.ident]->getAllocatedType(),
ec494a
+                                  variables_[var.ident]);
ec494a
     Value *newval;
ec494a
     if (is_increment)
ec494a
       newval = b_.CreateAdd(oldval, b_.GetIntSameSize(step, oldval));
ec494a
-- 
ec494a
2.38.1
ec494a