overflow.h/Gcc5

本文介绍了一种使用编译器内置函数或通用方法来检测整数运算溢出的技术。对于支持的编译器如Clang和GCC,利用__builtin_add_overflow等内置函数可以直接进行溢出检查。对于不支持内置函数的编译器,则提供了通用实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#if __GNUC__ >= 5 || __has_builtin(__builtin_add_overflow)
/** assume clang and gcc (>=5) to only have builtins for now. */
#  define add_of(a, b, r) __builtin_add_overflow(a, b, r)
#  define sub_of(a, b, r) __builtin_sub_overflow(a, b, r)
#  define mul_of(a, b, r) __builtin_mul_overflow(a, b, r)
#  define of_attr
#else
/** else use these generics, note behaviour of these is not strictly defined. */
#  define add_of(a, b, r) ((*(r) = ((a) + (b))) < (a))
#  define sub_of(a, b, r) ((*(r) = ((a) - (b))) > (a))
#  define mul_of(a, b, r) (((*(r) = ((a) * (b))) || *(r) == 0) && ((a) != 0 && (b) > *(r) / (a)))
#  if __clang__
#     define of_attr __attribute__((optnone)) // Do not optimize above checks, in most systems this will work, but not defined.
#     warning "Using non compiler builtins for overflow checks, this will be undefined for signed integers"
#  elif __GNUC__
#     define of_attr __attribute__((optimize("wrapv"))) // in older GCC we can make this behavior defined
#  else
#     warning "Using non compiler builtins for overflow checks, this will be undefined for signed integers"
#  endif
#endif

Starting C simulation ... D:/vitis202302/Vitis_HLS/2023.2/bin/vitis_hls.bat G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing/SmoothProfileOnXAxisMean_NoGray/SmoothProfileOnXAxisMean_NoGray/csim.tcl INFO: [HLS 200-10] Running 'D:/vitis202302/Vitis_HLS/2023.2/bin/unwrapped/win64.o/vitis_hls.exe' INFO: [HLS 200-10] For user 'HP' on host 'desktop-qjs3vb7' (Windows NT_amd64 version 6.2) on Tue Jul 22 17:03:51 +0800 2025 INFO: [HLS 200-10] In directory 'G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing' INFO: [HLS 200-2053] The vitis_hls executable is being deprecated. Consider using vitis-run --mode hls --tcl Sourcing Tcl script 'G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing/SmoothProfileOnXAxisMean_NoGray/SmoothProfileOnXAxisMean_NoGray/csim.tcl' INFO: [HLS 200-1510] Running: source G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing/SmoothProfileOnXAxisMean_NoGray/SmoothProfileOnXAxisMean_NoGray/csim.tcl INFO: [HLS 200-1510] Running: open_project SmoothProfileOnXAxisMean_NoGray INFO: [HLS 200-10] Opening project 'G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing/SmoothProfileOnXAxisMean_NoGray'. INFO: [HLS 200-1510] Running: set_top SmoothProfileOnXAxisMean INFO: [HLS 200-1510] Running: add_files src/SmoothProfileOnXAxisMean.cpp INFO: [HLS 200-10] Adding design file 'src/SmoothProfileOnXAxisMean.cpp' to the project INFO: [HLS 200-1510] Running: add_files -tb src/SmoothProfileOnXAxisMean_test.cpp INFO: [HLS 200-10] Adding test bench file 'src/SmoothProfileOnXAxisMean_test.cpp' to the project INFO: [HLS 200-1510] Running: open_solution SmoothProfileOnXAxisMean_NoGray -flow_target vivado INFO: [HLS 200-10] Opening solution 'G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing/SmoothProfileOnXAxisMean_NoGray/SmoothProfileOnXAxisMean_NoGray'. INFO: [SYN 201-201] Setting up clock 'default' with a period of 5ns. INFO: [HLS 200-1611] Setting target device to 'xcku060-ffva1156-2-e' INFO: [HLS 200-1505] Using flow_target 'vivado' Resolution: For help on HLS 200-1505 see docs.xilinx.com/access/sources/dita/topic?Doc_Version=2023.2%20English&url=ug1448-hls-guidance&resourceid=200-1505.html INFO: [HLS 200-1510] Running: set_part xcku060-ffva1156-2-e INFO: [HLS 200-1510] Running: create_clock -period 5 -name default INFO: [HLS 200-1510] Running: csim_design -quiet INFO: [SIM 211-2] *************** CSIM start *************** INFO: [SIM 211-4] CSIM will launch GCC as the compiler. INFO: [HLS 200-2036] Building debug C Simulation binaries Compiling ../../../../src/SmoothProfileOnXAxisMean.cpp in debug mode csim.mk:85: recipe for target 'obj/SmoothProfileOnXAxisMean.o' failed In file included from D:/vitis202302/Vitis_HLS/2023.2/include/floating_point_v7_1_bitacc_cmodel.h:150:0, from D:/vitis202302/Vitis_HLS/2023.2/include/hls_fpo.h:140, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/hls_half_fpo.h:19, from D:/vitis202302/Vitis_HLS/2023.2/include/hls_half.h:26, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_private.h:52, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_common.h:666, from D:/vitis202302/Vitis_HLS/2023.2/include/ap_int.h:10, from ../../../../src/SmoothProfileOnXAxisMean.h:3, from ../../../../src/SmoothProfileOnXAxisMean.cpp:1: D:/vitis202302/Vitis_HLS/2023.2/include/gmp.h:58:0: warning: "__GMP_LIBGMP_DLL" redefined #define __GMP_LIBGMP_DLL 0 In file included from D:/vitis202302/Vitis_HLS/2023.2/include/hls_fpo.h:140:0, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/hls_half_fpo.h:19, from D:/vitis202302/Vitis_HLS/2023.2/include/hls_half.h:26, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_private.h:52, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_common.h:666, from D:/vitis202302/Vitis_HLS/2023.2/include/ap_int.h:10, from ../../../../src/SmoothProfileOnXAxisMean.h:3, from ../../../../src/SmoothProfileOnXAxisMean.cpp:1: D:/vitis202302/Vitis_HLS/2023.2/include/floating_point_v7_1_bitacc_cmodel.h:142:0: note: this is the location of the previous definition #define __GMP_LIBGMP_DLL 1 ../../../../src/SmoothProfileOnXAxisMean.cpp: In function 'void SmoothProfileOnXAxisMean(hls::stream<float>&, hls::stream<float>&, ap_uint<6>, float)': ../../../../src/SmoothProfileOnXAxisMean.cpp:246:37: error: operands to ?: have different types 'int' and 'ap_int_base<6, false>::RType<32, true>::plus {aka ap_int<33>}' read_ptr = (read_ptr == 32) ? 0 : read_ptr + 1; ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ ../../../../src/SmoothProfileOnXAxisMean.cpp:246:37: note: and each type can be converted to the other ../../../../src/SmoothProfileOnXAxisMean.cpp:249:35: error: operands to ?: have different types 'int' and 'ap_int_base<6, false>::RType<32, true>::plus {aka ap_int<33>}' write_ptr = (write_ptr == 32) ? 0 : write_ptr + 1; ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ ../../../../src/SmoothProfileOnXAxisMean.cpp:249:35: note: and each type can be converted to the other make: *** [obj/SmoothProfileOnXAxisMean.o] Error 1 ERROR: [SIM 211-100] 'csim_design' failed: compilation error(s). INFO: [SIM 211-3] *************** CSIM finish *************** INFO: [HLS 200-111] Finished Command csim_design CPU user time: 0 seconds. CPU system time: 0 seconds. Elapsed time: 1.236 seconds; current allocated memory: 0.398 MB. 4 while executing "source G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing/SmoothProfileOnXAxisMean_NoGray/SmoothProfileOnXAxisMean_NoGray/csim.tcl" invoked from within "hls::main G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray_liangjing/SmoothProfileOnXAxisMean_NoGray/SmoothProfileOnXAxisMean_NoGray/csim.tcl" ("uplevel" body line 1) invoked from within "uplevel 1 hls::main {*}$newargs" (procedure "hls_proc" line 16) invoked from within "hls_proc [info nameofexecutable] $argv" INFO: [HLS 200-112] Total CPU user time: 1 seconds. Total CPU system time: 1 seconds. Total elapsed time: 2.984 seconds; peak allocated memory: 199.363 MB. Finished C simulation.
最新发布
07-23
Line 7: Char 9: ================================================================= ==22==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x502000000354 at pc 0x55de9091eda9 bp 0x7ffeb85c4260 sp 0x7ffeb85c4258 READ of size 4 at 0x502000000354 thread T0 #0 0x55de9091eda8 in swap<int> /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/move.h:222:13 #1 0x55de9091eda8 in iter_swap<__gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> > > > /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_algobase.h:185:7 #2 0x55de9091eda8 in void std::__reverse<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>>>>(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>>>, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>>>, std::random_access_iterator_tag) /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_algo.h:1062:4 #3 0x55de9091ec00 in reverse<__gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> > > > /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/bits/stl_algo.h:1089:7 #4 0x55de9091ec00 in Solution::rotate(std::vector<int, std::allocator<int>>&, int) solution.cpp:7:9 #5 0x55de9091e4ad in __helper__ solution.cpp:7:18 #6 0x55de9091e4ad in main solution.cpp:7:30 #7 0x7f3b1408a1c9 (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6) #8 0x7f3b1408a28a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6) #9 0x55de90847f44 in _start (solution+0xb2f44) 0x502000000354 is located 0 bytes after 4-byte region [0x502000000350,0x502000000354) allocated by thread T0 here: #0 0x55de9091bb6d in operator new(unsigned long) /root/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:86:3 #1 0x55de909381de i
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值