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

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