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

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