Fix LLVM 14 related warnings. (#591)

* LLVM 14 compatibility (#589)

* LLVM 13/14 compatibility
* Fix CUDA support

Co-authored-by: Artem Dinaburg <artem@trailofbits.com>

* bc:util: Remove unused variable.

* arch:x86: Fix bitwise to boolean operations.

* arch: Add missing thumb2 serialization.

* bc:util: Fix llvm-14 deprecated getElementType from PointerType.

* treewide: Fix pointer element naming.

* bc:compat: Return nullptr on access of element type of an opaque pointer.

Co-authored-by: Eric Kilmer <eric.d.kilmer@gmail.com>
Co-authored-by: Artem Dinaburg <artem@trailofbits.com>
This commit is contained in:
Henrich Lauko
2022-05-05 19:33:13 +02:00
committed by GitHub
parent 5563adad01
commit f56c2dd36a
7 changed files with 47 additions and 9 deletions
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 Trail of Bits, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "remill/BC/Version.h"
namespace remill {
inline static llvm::Type *PointerElementType(llvm::PointerType *type) {
#if LLVM_VERSION_NUMBER > LLVM_VERSION(13, 0)
if (type->isOpaque())
return nullptr;
#endif
#if LLVM_VERSION_NUMBER < LLVM_VERSION(14, 0)
return type->getElementType();
#else
return type->getPointerElementType();
#endif
}
} // namespace remill
+1
View File
@@ -656,6 +656,7 @@ std::string Instruction::Serialize(void) const {
case kArchX86:
case kArchX86_AVX:
case kArchX86_AVX512: ss << "X86"; break;
case kArchThumb2LittleEndian: ss << "Thumb2"; break;
case kArchAArch32LittleEndian: ss << "AArch32"; break;
case kArchAArch64LittleEndian: ss << "AArch64"; break;
case kArchSparc32: ss << "SPARC32"; break;
+1
View File
@@ -21,6 +21,7 @@
#include "Decode.h"
#include "remill/Arch/Instruction.h"
#include "remill/Arch/Name.h"
#include "remill/BC/Compat/PointerType.h"
#include "remill/BC/ABI.h"
#include "remill/BC/Util.h"
#include "remill/OS/OS.h"
+1
View File
@@ -22,6 +22,7 @@
#include "remill/Arch/Instruction.h"
#include "remill/Arch/Name.h"
#include "remill/BC/ABI.h"
#include "remill/BC/Compat/PointerType.h"
#include "remill/BC/Util.h"
#include "remill/OS/OS.h"
+2 -2
View File
@@ -1370,7 +1370,7 @@ DEF_FPU_SEM(DoFYL2X) {
auto st1 = Read(X87_ST1);
state.sw.ze = IsZero(st0);
state.sw.de = IsDenormal(st0) | IsDenormal(st1);
state.sw.ie = (IsSignalingNaN(st0) | IsSignalingNaN(st1)) ||
state.sw.ie = (IsSignalingNaN(st0) || IsSignalingNaN(st1)) ||
(IsNegative(st0) && !IsInfinite(st0) && !state.sw.ze);
auto res = FMul(st1, Log2(st0));
state.sw.pe = IsImprecise(res);
@@ -1385,7 +1385,7 @@ DEF_FPU_SEM(DoFYL2XP1) {
auto st1 = Read(X87_ST1);
state.sw.ze = IsZero(st0);
state.sw.de = IsDenormal(st0) | IsDenormal(st1);
state.sw.ie = IsSignalingNaN(st0) | IsSignalingNaN(st1);
state.sw.ie = IsSignalingNaN(st0) || IsSignalingNaN(st1);
auto res = FMul(st1, Log2(FAdd(st0, Float80(1.0))));
state.sw.pe = IsImprecise(res);
Write(X87_ST1, res);
-1
View File
@@ -575,7 +575,6 @@ llvm::Value *InstructionLifter::LiftRegisterOperand(Instruction &inst,
auto val_type = val->getType();
auto val_size = data_layout.getTypeAllocSizeInBits(val_type);
auto arg_size = data_layout.getTypeAllocSizeInBits(arg_type);
const auto word_size = impl->arch->address_size;
if (val_size < arg_size) {
if (arg_type->isIntegerTy()) {
+7 -6
View File
@@ -53,6 +53,7 @@
#include "remill/BC/Compat/DebugInfo.h"
#include "remill/BC/Compat/GlobalValue.h"
#include "remill/BC/Compat/IRReader.h"
#include "remill/BC/Compat/PointerType.h"
#include "remill/BC/Compat/ToolOutputFile.h"
#include "remill/BC/Compat/VectorType.h"
#include "remill/BC/Compat/Verifier.h"
@@ -944,7 +945,7 @@ RecontextualizeType(llvm::Type *type, llvm::LLVMContext &context,
case llvm::Type::PointerTyID: {
auto ptr_type = llvm::dyn_cast<llvm::PointerType>(type);
auto elem_type = ptr_type->getElementType();
auto elem_type = PointerElementType(ptr_type);
cached =
llvm::PointerType::get(RecontextualizeType(elem_type, context, cache),
ptr_type->getAddressSpace());
@@ -1476,11 +1477,11 @@ llvm::GlobalVariable *DeclareVarInModule(llvm::GlobalVariable *var,
auto &dest_context = dest_module->getContext();
const auto type = ::remill::RecontextualizeType(
var->getType()->getElementType(), dest_context);
PointerElementType(var->getType()), dest_context);
auto dest_var = dest_module->getGlobalVariable(var->getName());
if (dest_var) {
CHECK_EQ(type, dest_var->getType()->getElementType());
CHECK_EQ(type, PointerElementType(dest_var->getType()));
moved_var = dest_var;
return dest_var;
}
@@ -1530,7 +1531,7 @@ llvm::GlobalAlias *DeclareAliasInModule(llvm::GlobalAlias *var,
}
}
const auto elem_type = dest_type->getElementType();
const auto elem_type = PointerElementType(dest_type);
const auto dest_var = llvm::GlobalAlias::create(
elem_type, var->getType()->getAddressSpace(), var->getLinkage(),
var->getName(), nullptr, dest_module);
@@ -2446,8 +2447,8 @@ llvm::Value *BuildPointerToOffset(llvm::IRBuilder<> &ir, llvm::Value *ptr,
}
}
const auto dest_elem_type = dest_elem_ptr_type->getElementType();
const auto ptr_elem_type = ptr_type->getElementType();
const auto dest_elem_type = PointerElementType(dest_elem_ptr_type);
const auto ptr_elem_type = PointerElementType(ptr_type);
const auto ptr_elem_size = dl.getTypeAllocSize(ptr_elem_type);
const auto base_index = dest_elem_offset / ptr_elem_size;