Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/basic-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-24.04 ]
llvm-version: [ 14, 18 ]
llvm-version: [ 14, 18, 19 ]
typeart-typegen-legacy: [ 0, 1 ]
preset:
- name: ci-thread-safe-safeptr
Expand All @@ -65,12 +65,22 @@ jobs:
os: ubuntu-22.04
- llvm-version: 18
typeart-typegen-legacy: 1
- llvm-version: 19
os: ubuntu-22.04
- llvm-version: 19
typeart-typegen-legacy: 1

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: LLVM apt
if: ${{ matrix.llvm-version == 19 }}
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm-19.list

- name: Update apt
run: sudo apt-get update

Expand Down
30 changes: 27 additions & 3 deletions .github/workflows/ext-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-24.04 ]
llvm-version: [ 14, 18 ]
llvm-version: [ 14, 18, 19 ]
preset:
- name: release-counter
- name: release-safeptr-counter
Expand All @@ -25,6 +25,8 @@ jobs:
os: ubuntu-24.04
- llvm-version: 18
os: ubuntu-22.04
- llvm-version: 19
os: ubuntu-22.04

runs-on: ${{ matrix.os }}

Expand All @@ -38,6 +40,12 @@ jobs:
ssh-key: ${{ secrets.AUTH_SSH_CI_EXT }}
path: test-bench

- name: LLVM apt
if: ${{ matrix.llvm-version == 19 }}
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm-19.list

- name: Update apt
run: sudo apt-get update

Expand Down Expand Up @@ -106,7 +114,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-24.04 ]
llvm-version: [ 14, 18 ]
llvm-version: [ 14, 18, 19 ]
preset:
- name: release-counter
- name: release-unsafe-counter
Expand All @@ -115,6 +123,8 @@ jobs:
os: ubuntu-24.04
- llvm-version: 18
os: ubuntu-22.04
- llvm-version: 19
os: ubuntu-22.04

runs-on: ${{ matrix.os }}

Expand All @@ -129,6 +139,12 @@ jobs:
ref: feat/ci
path: ad-test-bench

- name: LLVM apt
if: ${{ matrix.llvm-version == 19 }}
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm-19.list

- name: Update apt
run: sudo apt-get update

Expand Down Expand Up @@ -184,7 +200,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-24.04 ]
llvm-version: [ 14, 18 ]
llvm-version: [ 14, 18, 19 ]
preset:
- name: release-counter
- name: release-safeptr-counter
Expand All @@ -193,6 +209,8 @@ jobs:
os: ubuntu-24.04
- llvm-version: 18
os: ubuntu-22.04
- llvm-version: 19
os: ubuntu-22.04

runs-on: ${{ matrix.os }}

Expand All @@ -207,6 +225,12 @@ jobs:
ref: ci/omp
path: omp-test-bench

- name: LLVM apt
if: ${{ matrix.llvm-version == 19 }}
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm-19.list

- name: Update apt
run: sudo apt-get update

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)

project(typeart
VERSION 1.9
VERSION 2.0
HOMEPAGE_URL https://github.com/tudasc/TypeART
DESCRIPTION "LLVM-based type and memory allocation tracking sanitizer"
)
Expand Down
2 changes: 1 addition & 1 deletion externals/dimeta/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FetchContent_Declare(
llvm-dimeta
GIT_REPOSITORY https://github.com/ahueck/llvm-dimeta
GIT_TAG devel
GIT_TAG v0.2.0
GIT_SHALLOW 1
)

Expand Down
1 change: 1 addition & 0 deletions lib/passes/instrumentation/MemOpInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
52 changes: 40 additions & 12 deletions lib/passes/typegen/dimeta/DimetaTypeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,25 @@ template <typename Type>
std::pair<std::optional<typeart_builtin_type>, int> typeid_if_ptr(const Type& type) {
using namespace dimeta;
const auto& quals = type.qual;
int count{0};
if (!quals.empty()) {
count = llvm::count_if(quals, [](auto& qual) { return qual == Qualifier::kPtr || qual == Qualifier::kRef; });
if (count > 0) {
return {{TYPEART_POINTER}, count};
const int count =
llvm::count_if(quals, [](auto& qual) { return qual == Qualifier::kPtr || qual == Qualifier::kRef; });

if constexpr (std::is_same_v<Type, typename dimeta::QualifiedFundamental>) {
switch (type.type.encoding) {
case FundamentalType::Encoding::kVtablePtr:
return {TYPEART_VTABLE_POINTER, count};
case FundamentalType::Encoding::kNullptr:
return {TYPEART_NULLPOINTER, count};
case FundamentalType::Encoding::kVoid:
return {TYPEART_VOID, count};
default:
break;
}
}
if (count > 0) {
return {{TYPEART_POINTER}, count};
}

return {{}, count};
}

Expand Down Expand Up @@ -220,6 +232,8 @@ std::optional<typeart_builtin_type> get_builtin_typeid(const dimeta::QualifiedFu
const auto encoding = type.type.encoding;

switch (encoding) {
case FundamentalType::Encoding::kVtablePtr:
return TYPEART_VTABLE_POINTER;
case FundamentalType::Encoding::kUnknown:
return TYPEART_UNKNOWN_TYPE;
case FundamentalType::Encoding::kVoid:
Expand Down Expand Up @@ -279,11 +293,11 @@ std::optional<typeart_builtin_type> get_builtin_typeid(const dimeta::QualifiedFu
}
case FundamentalType::Encoding::kComplex: {
switch (extent) {
case 2:
case 8:
return TYPEART_COMPLEX_64;
case 4:
case 16:
return TYPEART_COMPLEX_128;
case 1:
case 32:
return TYPEART_COMPLEX_256;
default:
return TYPEART_UNKNOWN_TYPE;
Expand Down Expand Up @@ -398,17 +412,31 @@ class DimetaTypeManager final : public TypeIDGenerator {
if (q.is_forward_decl) {
struct_info.flag = StructTypeFlag::FWD_DECL;
} else {
struct_info.flag = StructTypeFlag::USER_DEFINED;
if (q.type.type == CompoundType::Tag::kUnion) {
struct_info.flag = StructTypeFlag::UNION;
} else {
struct_info.flag = StructTypeFlag::USER_DEFINED;
}
}

struct_info.extent = compound.extent;
struct_info.offsets = compound.offsets;
struct_info.num_members = compound.bases.size() + compound.members.size();
struct_info.extent = compound.extent;

size_t num_bases{0};
for (const auto& base : compound.bases) {
if (base->is_empty_base_class) {
continue;
}
num_bases++;
struct_info.member_types.push_back(getOrRegister(base->base));
struct_info.array_sizes.push_back(array_size(base->base));
struct_info.offsets.push_back(base->offset);
}

struct_info.num_members = compound.members.size() + num_bases;
struct_info.offsets.insert(std::end(struct_info.offsets), //
std::begin(compound.offsets), //
std::end(compound.offsets));

for (const auto& member : compound.members) {
struct_info.member_types.push_back(getOrRegister(member->member));
struct_info.array_sizes.push_back(array_size(member->member));
Expand Down
10 changes: 9 additions & 1 deletion lib/runtime/RuntimeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,21 @@ bool typeart_is_struct_type(int type_id);

/**
* Returns true if the type ID is a user-defined structure type
* (struct, class etc.)
* (struct, class, union etc.)
*
* \param[in] type_id The type ID.
* \return true, false
*/
bool typeart_is_userdefined_type(int type_id);

/**
* Returns true if the type ID is a (user-defined) union
*
* \param[in] type_id The type ID.
* \return true, false
*/
bool typeart_is_union(int type_id);

/**
* Returns true if the type ID is a LLVM SIMD vector type
*
Expand Down
5 changes: 5 additions & 0 deletions lib/runtime/TypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ bool typeart_is_userdefined_type(int type_id) {
return typeart::RuntimeSystem::get().typeResolution.db().isUserDefinedType(type_id);
}

bool typeart_is_union(int type_id) {
typeart::RTGuard guard;
return typeart::RuntimeSystem::get().typeResolution.db().isUnion(type_id);
}

size_t typeart_get_type_size(int type_id) {
typeart::RTGuard guard;
return typeart::RuntimeSystem::get().typeResolution.db().getTypeSize(type_id);
Expand Down
14 changes: 12 additions & 2 deletions lib/typelib/TypeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ inline constexpr auto size_complex_long_double = sizeof(std::complex<long double
#define FOR_EACH_TYPEART_BUILTIN(X) \
X(TYPEART_UNKNOWN_TYPE, "typeart_unknown_type", 0) \
X(TYPEART_POINTER, "ptr", sizeof(void*)) \
X(TYPEART_VTABLE_POINTER, "vtable_ptr", sizeof(void*)) \
X(TYPEART_VOID, "void*", sizeof(void*)) \
X(TYPEART_NULLPOINTER, "nullptr_t", sizeof(void*)) \
X(TYPEART_BOOL, "bool", sizeof(bool)) \
Expand Down Expand Up @@ -114,9 +115,11 @@ bool TypeDB::isPointerType(int type_id) const {
bool TypeDB::isUserDefinedType(int type_id) const {
const auto* structInfo = getStructInfo(type_id);
LOG_DEBUG(structInfo->name << " " << static_cast<int>(structInfo->flag) << " "
<< (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::USER_DEFINED)))
<< (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::USER_DEFINED))
<< " " << (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::UNION)))
return (structInfo != nullptr) &&
(static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::USER_DEFINED));
(static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::USER_DEFINED) ||
static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::UNION));
}

bool TypeDB::isVectorType(int type_id) const {
Expand All @@ -127,6 +130,13 @@ bool TypeDB::isVectorType(int type_id) const {
(static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::LLVM_VECTOR));
}

bool TypeDB::isUnion(int type_id) const {
const auto* structInfo = getStructInfo(type_id);
LOG_DEBUG(structInfo->name << " " << static_cast<int>(structInfo->flag) << " "
<< (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::UNION)))
return (structInfo != nullptr) && (static_cast<int>(structInfo->flag) == static_cast<int>(StructTypeFlag::UNION));
}

bool TypeDB::isValid(int type_id) const {
if (isBuiltinType(type_id)) {
return true;
Expand Down
2 changes: 2 additions & 0 deletions lib/typelib/TypeDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class TypeDB final : public TypeDatabase {

bool isVectorType(int type_id) const override;

bool isUnion(int type_id) const override;

const std::string& getTypeName(int type_id) const override;

const StructTypeInfo* getStructInfo(int type_id) const override;
Expand Down
4 changes: 3 additions & 1 deletion lib/typelib/TypeDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace typeart {

enum class StructTypeFlag : int { USER_DEFINED = 1, LLVM_VECTOR = 2, FWD_DECL = 4 };
enum class StructTypeFlag : int { USER_DEFINED = 1, LLVM_VECTOR = 2, FWD_DECL = 4, UNION = 8 };

struct StructTypeInfo {
int type_id;
Expand Down Expand Up @@ -57,6 +57,8 @@ class TypeDatabase {

[[nodiscard]] virtual bool isVectorType(int type_id) const = 0;

[[nodiscard]] virtual bool isUnion(int type_id) const = 0;

[[nodiscard]] virtual const std::string& getTypeName(int type_id) const = 0;

[[nodiscard]] virtual const StructTypeInfo* getStructInfo(int type_id) const = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/typelib/TypeIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct llvm::yaml::ScalarTraits<typeart::StructTypeFlag> {
} else {
value = static_cast<typeart::StructTypeFlag>(flag);
}
return StringRef();
return {};
}

// Determine if this scalar needs quotes.
Expand Down
1 change: 1 addition & 0 deletions lib/typelib/TypeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef enum typeart_builtin_type_t { // NOLINT
TYPEART_UNKNOWN_TYPE = 0,

TYPEART_POINTER,
TYPEART_VTABLE_POINTER,
TYPEART_VOID,
TYPEART_NULLPOINTER,

Expand Down
2 changes: 1 addition & 1 deletion test/pass/arrays/01_simple_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ void test() {

// ALLOC: [[POINTER:%[0-9a-z]+]] = alloca [100 x i32]
// ALLOC-NEXT: [[POINTER2:%[0-9a-z]+]] = bitcast [100 x i32]* [[POINTER]] to i8*
// ALLOC-NEXT: call void @__typeart_alloc_stack(i8* [[POINTER2]], i32 12, i64 100)
// ALLOC-NEXT: call void @__typeart_alloc_stack(i8* [[POINTER2]], i32 13, i64 100)

// CHECK: call void @__typeart_leave_scope(i32 %__ta_counter_load)
2 changes: 1 addition & 1 deletion test/pass/arrays/02_array_to_pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ void test() {

// CHECK: [[POINTER:%[0-9a-z]+]] = alloca [100 x i32]
// CHECK-NEXT: [[POINTER2:%[0-9a-z]+]] = bitcast [100 x i32]* [[POINTER]] to i8*
// CHECK-NEXT: call void @__typeart_alloc_stack(i8* [[POINTER2]], i32 12, i64 100)
// CHECK-NEXT: call void @__typeart_alloc_stack(i8* [[POINTER2]], i32 13, i64 100)

// CHECK: call void @__typeart_leave_scope(i32 %__ta_counter_load)
8 changes: 4 additions & 4 deletions test/pass/arrays/03_multidim_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void test() {
// CHECK: Free{{[ ]*}}:{{[ ]*}}0
// CHECK: Alloca{{[ ]*}}:{{[ ]*}}6

// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 12, i64 64)
// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 12, i64 4096)
// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 12, i64 8192)
// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 12, i64 524288)
// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 13, i64 64)
// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 13, i64 4096)
// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 13, i64 8192)
// CHECK: call void @__typeart_alloc_stack({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 13, i64 524288)
2 changes: 1 addition & 1 deletion test/pass/arrays/06_malloc_of_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ void foo(int n) {
int(*array)[3] = malloc(2 * sizeof(int[3]));
}

// CHECK: @__typeart_alloc({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 12, i64 6)
// CHECK: @__typeart_alloc({{i8\*|ptr}} %{{[0-9a-z]+}}, i32 13, i64 6)
Loading