Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Original source code:
- #include <stdio.h>
- class TestClass {
- public:
- TestClass(int _x, int _y) {
- x = _x;
- y = _y;
- }
- private:
- int x;
- int y;
- };
- int main()
- {
- char* buffer;
- int size = 101;
- buffer = new char[size];
- printf("CHECK address: 0x%p, size: %d\n", buffer, size);
- TestClass* test = new TestClass(1, 2);
- printf("(CHECK address: 0x%p, size: %d\n", test, sizeof(TestClass));
- delete buffer;
- delete test;
- }
- --------------------------------------
- IR after insrumentation:
- ; ModuleID = '..\main.cpp'
- source_filename = "..\\main.cpp"
- target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
- target triple = "x86_64-pc-windows-msvc19.16.27035"
- %struct.__crt_locale_pointers = type { %struct.__crt_locale_data*, %struct.__crt_multibyte_data* }
- %struct.__crt_locale_data = type opaque
- %struct.__crt_multibyte_data = type opaque
- $printf = comdat any
- $"??0TestClass@@QEAA@HH@Z" = comdat any
- $_vfprintf_l = comdat any
- $__local_stdio_printf_options = comdat any
- $"??_C@_0BP@DNHBDPL@CHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = comdat any
- $"??_C@_0CA@KKHCADGA@?$CICHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = comdat any
- $"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA" = comdat any
- @"??_C@_0BP@DNHBDPL@CHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [31 x i8] c"CHECK address: 0x%p, size: %d\0A\00", comdat, align 1
- @"??_C@_0CA@KKHCADGA@?$CICHECK?5address?3?50x?$CFp?0?5size?3?5?$CFd?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [32 x i8] c"(CHECK address: 0x%p, size: %d\0A\00", comdat, align 1
- @"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA" = linkonce_odr dso_local global i64 0, comdat, align 8
- @0 = private unnamed_addr constant [46 x i8] c"Allocated address: 0x%p, size: %d, key: 0x%x\0A\00", align 1
- @1 = private unnamed_addr constant [46 x i8] c"Allocated address: 0x%p, size: %d, key: 0x%x\0A\00", align 1
- ; Function Attrs: noinline norecurse optnone uwtable
- entry:
- %test = alloca %class.TestClass*, align 8
- to label %invoke.cont unwind label %ehcleanup
- invoke.cont: ; preds = %entry
- store %class.TestClass* %9, %class.TestClass** %test, align 8
- %10 = load %class.TestClass*, %class.TestClass** %test, align 8
- delete.notnull: ; preds = %invoke.cont
- br label %delete.end
- delete.end: ; preds = %delete.notnull, %invoke.cont
- %12 = load %class.TestClass*, %class.TestClass** %test, align 8
- %isnull5 = icmp eq %class.TestClass* %12, null
- delete.notnull6: ; preds = %delete.end
- br label %delete.end7
- delete.end7: ; preds = %delete.notnull6, %delete.end
- ehcleanup: ; preds = %entry
- %15 = cleanuppad within none []
- cleanupret from %15 unwind to caller
- }
- ; Function Attrs: nobuiltin allocsize(0)
- ; Function Attrs: nobuiltin noinline optnone uwtable
- entry:
- %agg.tmp.ensured = alloca %struct.__vcrt_assert_va_start_is_not_reference, align 1
- %call2 = call i32 @_vfprintf_l(%struct._iobuf* %call, i8* %1, %struct.__crt_locale_pointers* null, i8* %0)
- }
- ; Function Attrs: nobuiltin allocsize(0)
- ; Function Attrs: noinline nounwind optnone uwtable
- entry:
- %this.addr = alloca %class.TestClass*, align 8
- store %class.TestClass* %this, %class.TestClass** %this.addr, align 8
- %this1 = load %class.TestClass*, %class.TestClass** %this.addr, align 8
- ret %class.TestClass* %this1
- }
- ; Function Attrs: nobuiltin nounwind
- ; Function Attrs: nounwind
- ; Function Attrs: noinline optnone uwtable
- define linkonce_odr dso_local i32 @_vfprintf_l(%struct._iobuf* %_Stream, i8* %_Format, %struct.__crt_locale_pointers* %_Locale, i8* %_ArgList) #6 comdat {
- entry:
- %_Locale.addr = alloca %struct.__crt_locale_pointers*, align 8
- %_Stream.addr = alloca %struct._iobuf*, align 8
- store %struct.__crt_locale_pointers* %_Locale, %struct.__crt_locale_pointers** %_Locale.addr, align 8
- store %struct._iobuf* %_Stream, %struct._iobuf** %_Stream.addr, align 8
- %1 = load %struct.__crt_locale_pointers*, %struct.__crt_locale_pointers** %_Locale.addr, align 8
- %3 = load %struct._iobuf*, %struct._iobuf** %_Stream.addr, align 8
- %call1 = call i32 @__stdio_common_vfprintf(i64 %4, %struct._iobuf* %3, i8* %2, %struct.__crt_locale_pointers* %1, i8* %0)
- }
- declare dso_local i32 @__stdio_common_vfprintf(i64 %0, %struct._iobuf* %1, i8* %2, %struct.__crt_locale_pointers* %3, i8* %4) #7
- ; Function Attrs: noinline nounwind optnone uwtable
- entry:
- }
- attributes #0 = { noinline norecurse optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
- attributes #1 = { nobuiltin allocsize(0) "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
- attributes #2 = { nobuiltin noinline optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
- attributes #3 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
- attributes #4 = { nobuiltin nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
- attributes #5 = { nounwind }
- attributes #6 = { noinline optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
- attributes #7 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
- attributes #8 = { builtin allocsize(0) }
- attributes #9 = { builtin nounwind }
- !llvm.linker.options = !{!0}
- !llvm.module.flags = !{!1, !2}
- !llvm.ident = !{!3}
- !0 = !{!"/FAILIFMISMATCH:\22_CRT_STDIO_ISO_WIDE_SPECIFIERS=0\22"}
- !3 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 259238baa659f85d57d6f9bb07a166b6dcf041dd)"}
- --------------------------------------
- Program output (after instrumentation):
- Allocated address: 0x0000019614A01B20, size: 101, key: 0x0
- CHECK address: 0x0000019614A01B20, size: 101
- Allocated address: 0x0000019614A01B90, size: 8, key: 0x0
- CHECK address: 0x0000019614A01B90, size: 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement