- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've got some code which contains a function with signature
/* cotd.h */ #ifndef COTD_PTR_H #define COTD_PTR_H void cotd(double *x); #endif
that updates the value in x, say by adding 2 for demonstration. When I invoke cotd with the address of a double, the value is never changed, and the assembly from passing /S contains no call to cotd when cotd is in a separate compilation unit from the call and no debug flags (e.g. /Z7) are passed.
Details follow.
Implementation:
/* cotd.c */ #include "cotd.h" void cotd(double *x) { *x = 2.0+*x; }
Useage:
/* cotdissue.c */ #include "stdio.h" #include "cotd.h" int main(void) { double x = 1.23; printf("Initial x = %g\n", x); cotd(&x); printf("x = %g; expected = 3.23\n",x); return 0; }
Compiling without /Z7 and executing produces:
icl /c /nologo /MD /I "Z:\sandbox\rlivings\temp\sparse\iclrepro" "cotdissue.c" icl /c /nologo /MD /I "Z:\sandbox\rlivings\temp\sparse\iclrepro" "cotd.c" link /nologo /NODEFAULTLIB:LIBCMT /OUT:cotdissue.exe cotdissue.obj cotd.obj Build completed using compiler intelc13msvs2013 cotdissue.exe Initial x = 1.23 x = 1.23; expected = 3.23
showing that x was never updated on the call to cotd. The assembly generated from cotdissue.c is:
main PROC .B1.1:: ; Preds .B1.0 sub rsp, 40 ;4.16 mov rdx, 0000000000H ;4.16 mov ecx, 3 ;4.16 call __intel_new_feature_proc_init ;4.16 ; LOE rbx rbp rsi rdi r12 r13 r14 r15 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 .B1.6:: ; Preds .B1.1 stmxcsr DWORD PTR [32+rsp] ;4.16 lea rcx, QWORD PTR [_2__STRING.0.0.1] ;6.5 or DWORD PTR [32+rsp], 32832 ;4.16 ldmxcsr DWORD PTR [32+rsp] ;4.16 movsd xmm1, QWORD PTR [_2il0floatpacket.0] ;6.5 movd rdx, xmm1 ;6.5 call QWORD PTR [__imp_printf] ;6.5 ; LOE rbx rbp rsi rdi r12 r13 r14 r15 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 .B1.2:: ; Preds .B1.6 movsd xmm1, QWORD PTR [_2il0floatpacket.0] ;8.5 lea rcx, QWORD PTR [_2__STRING.1.0.1] ;8.5 movd rdx, xmm1 ;8.5 call QWORD PTR [__imp_printf] ;8.5 ; LOE rbx rbp rsi rdi r12 r13 r14 r15 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 .B1.3:: ; Preds .B1.2 xor eax, eax ;9.12 add rsp, 40 ;9.12 ret ;9.12 ALIGN 16 ; LOE .B1.4:: ; mark_end; main ENDP
Some observations:
- Passing /Z7 produces the desired result, 3.23 for x
- There are no warnings that cotd may conflict with a built-in function. Are we possibly getting side effect information from the known trig function?
- Changing the name of cotd to bcotd produces expected results without /Z7
Any thoughts would be appreciated. I know that I can rename my function as a workaround but the incorrect answer without any notification is concerning to me.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ryan,
I can reproduce this problem on my end. I can check with the compiler development engineers on this. In the meantime, you can try the following:
>icl cotdissue.c cotd.c /Qno-builtin-cotd
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.180 Build 20160204
Copyright (C) 1985-2016 Intel Corporation. All rights reserved.
cotdissue.c
cotd.c
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:cotdissue.exe
cotdissue.obj
cotd.obj
>cotdissue.exe
Initial x = 1.23
x = 3.23; expected = 3.23
The compiler option /Qno-builtin-<function name> will not link to the builtin function rather link with the user defined one as you can above. Documentation on this option is available at https://software.intel.com/en-us/node/581706.
Thanks and Regards
Anoop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the quick reply Anoop. I confirm that your workaround succeeds and am interested to hear what the consensus on the behavior is.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page