Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29236 Discussions

empty C string literals don't work: bug or feature?

Steve_Nuchia
New Contributor I
1,294 Views

I'm using 10.1.019 to compile a bunch of legacy code. The initial port went fairly smoothly, mainly some name decoration issues and such. But in one spot we were passing ''C as a literal; that didn't compile so I made it a variable and then it compiled.

Now we're seriously testing and we've found several places where the ''C construct is not doing what we expect it to do, which is what it used to do under DEC visual fortran.

I looked at some assembly code and

LINE=''C

is compiling to

 0000436E: 33 C0 xor eax,eax
00004370: 50 push eax
00004371: 50 push eax
00004372: 50 push eax
00004373: 68 00 00 00 00 push offset STRLITPACK_11.0
00004378: 50 push eax
00004379: 6A 3E push 3Eh
0000437B: 68 00 00 00 00 push offset _texty
00004380: E8 00 00 00 00 call _for_cpystr

I don't know what the interface to _for_cpystr is but this looks like it might be copying zero bytes instead of the expected one (null) byte. That would explain the symptom.

Is this by design? If not, has it been fixed in a later release?

Thank you!

0 Kudos
9 Replies
Steven_L_Intel1
Employee
1,294 Views
Can you provide a short but complete program that demonstrates this problem? The following program gets a call to _for_cpystr but it does it correctly.

subroutine copy (line)
character(*) line
line = 'ABCDEFGHIJ'
write (*,101) (line(i:i),i=1,10)
101 format(10Z3.2)
line = ''C
write (*,101) (line(i:i),i=1,10)
end

character(10) line
call copy(line)
end

Build and run with 10.1.024:

41 42 43 44 45 46 47 48 49 4A
00 20 20 20 20 20 20 20 20 20

0 Kudos
Steve_Nuchia
New Contributor I
1,294 Views

Repro cases are always a problem for those of us working on proprietary code bases. I spent a few minutes complicating your example to more closely match ours: putting line in a common, marking the common for C name decoration, changing the type to character*62, etc. No joy, they all work.

If I move the assignment into the context where line01 is defined I get code similar to the problem case we're having, but it's pushing a 1 where our code is pushing a 0. Perhaps the optimizer settings are relevant after all.

0040137B add esp,0FFFFFFE4h
0040137E mov dword ptr [esp],offset _lcom (497AE0h)
00401385 xor eax,eax
00401387 mov dword ptr [esp+4],3Eh
0040138F mov dword ptr [esp+8],eax
00401393 mov dword ptr [esp+0Ch],offset ___xt_z+74h (47A294h)
0040139B mov dword ptr [esp+10h],1
004013A3 mov dword ptr [esp+14h],eax
004013A7 mov dword ptr [esp+18h],eax
004013AB call _for_cpystr (40145Ch)
004013B0 add esp,1Ch

I'll keep hacking and submit a bug if I can get a repro case. Your answer has

clarified that is isn't some obscure standards conformance issue, that's the

main thing I was looking for. We have a workaround: globally replace ''C with '�'C.

Belt and suspenders, doncha know. (US: substitute "braces" in the rest of the English-

speaking world or it carries the wrong meaning.)

Thank you,

-swn

0 Kudos
Steve_Nuchia
New Contributor I
1,294 Views

I was able to get my modification of your code to exhibit the problem; it is quite sensitive to optimizer settings. This is the second optimizer bug we've tripped across with the settings we're using. Maybe I need to back off a bit :-)

0 Kudos
Steven_L_Intel1
Employee
1,294 Views
What are all the compile options you are using?
0 Kudos
Steve_Nuchia
New Contributor I
1,294 Views
Program, output, and build log follow.  I've opened ticket #515342on the issue.
subroutine copy (line)
character(*) line
line = 'ABCDEFGHIJ'
write (*,101) (line(i:i),i=1,10)
101 format(10Z3.2)
line = ''C
write (*,101) (line(i:i),i=1,10)
end
 program Console1
 character*62 line01, line02, line03
common /lcom/ line01, line02, line03
!MS$ATTRIBUTES C :: lcom
equivalence (linex,line01)
character*62 linex(3)
call copy(line01)
101 format(10Z3.2)
write (*,101) (line01(i:i),i=1,10)
line01='foo'C
write (*,101) (line01(i:i),i=1,10)
line01=''C
write (*,101) (line01(i:i),i=1,10)
 end program Console1
Compiled in Debug mode:
41 42 43 44 45 46 47 48 49 4A
00 20 20 20 20 20 20 20 20 20
00 20 20 20 20 20 20 20 20 20
66 6F 6F 00 20 20 20 20 20 20
00 20 20 20 20 20 20 20 20 20
Compiled as below and run on an E2180 under  :
OS NameMicrosoft Windows Server 2003 Enterprise x64 Edition
Version5.2.3790 Service Pack 2 Build 3790
Other OS Description R2
OS ManufacturerMicrosoft Corporation
System NameV9BUILD2
System ManufacturerDell Inc.
System ModelVostro 200
System Typex64-based PC
ProcessorEM64T Family 6 Model 15 Stepping 13 GenuineIntel ~1796 Mhz
ProcessorEM64T Family 6 Model 15 Stepping 13 GenuineIntel ~1796 Mhz
BIOS Version/DateDell Inc. 1.0.13, 3/21/2008
SMBIOS Version2.5
Windows DirectoryC:WINDOWS
System DirectoryC:WINDOWSsystem32
the output is:
 41 42 43 44 45 46 47 48 49 4A
20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20
66 6F 6F 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20
Build Log 
Build started: Project: Console1, Configuration: Release|Win32

Environment Space
=C:=C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDE
ALLUSERSPROFILE=C:Documents and SettingsAll Users
APPDATA=C:Documents and SettingssnuchiaApplication Data
BISTRO_GLOBAL_CACHE_DIR=C:Program Files (x86)IntelVTuneCGGlbCache
CLASSPATH=C:Program Files (x86)Common FilesCompuwareDLM40JNI.jar
ClusterLog=C:WINDOWSClustercluster.log
CommonProgramFiles=C:Program Files (x86)Common Files
CommonProgramFiles(x86)=C:Program Files (x86)Common Files
CommonProgramW6432=C:Program FilesCommon Files
COMPUTERNAME=V9BUILD2
ComSpec=C:WINDOWSsystem32cmd.exe
FOR__IS_DEBUGGER_PRESENT=1
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=Documents and Settingssnuchia
IFORT_COMPILER10=C:Program Files (x86)IntelCompilerFortran10.1.019
INCLUDE=C:Program Files (x86)IntelCompilerFortran10.1.019IA32Include;C:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfcinclude;C:Program Files (x86)Microsoft Visual Studio 9. 0VCinclude;C:Program FilesMicrosoft SDKsWindowsv6.0Ainclude;C:Program Files (x86)Microsoft Visual Studio 9.0VCATLMFCINCLUDE;C:Program Files (x86)Microsoft Visual Studio 9.0VCINCLUDE;C:Program FilesMicrosoft SDKsWindowsv6.0Ainclude
INTEL_LICENSE_FILE=C:Program Files (x86)Common FilesIntelLicenses
LIB=C:Program Files (x86)IntelCompilerFortran10.1.019IA32Lib;C:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfclib;C:Program Files (x86)Microsoft Visual Studio 9.0VClib;C:Program FilesMicrosoft SDKsWindowsv6.0Alib;C:Program Files (x86)Microsoft Visual Studio 9.0VCATLMFCLIB;C:Program Files (x86)Microsoft Visual Studio 9.0VCLIB;C:Program FilesMicrosoft SDKsWindowsv6.0Alib
LOGONSERVER=STAT-DC
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:Program Files (x86)IntelCompilerFortran10.1.019IA32Bin;C:Program Files (x86)Common FilesIntelShared FilesIa32Bin;C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDE;C:Program Files (x86)Microsoft Visual Studio 9.0VCBIN;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Toolsin;c:WINDOWSMicrosoft.NETFrameworkv2.0.50727;C:Program FilesMicrosoft SDKsWindowsv6.0Ain;C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDE;C:Program Files (x86)Microsoft Visual Studio 9.0VCBIN;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools;C:WINDOWSMicrosoft.NETFrameworkv3.5;C:WINDOWSMicrosoft.NETFrameworkv2.0.50727;C:Program Files (x86)Microsoft Visual Studio 9.0VCVCPackages;C:Program FilesMicrosoft SDKsWindowsv6.0Ain;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools..IDE;C:Program Files (x86)IntelVTuneCGGlbCache;C:Program Files (x86)IntelVTuneSharedBin32e;C:Program Files (x86)IntelVTuneAnalyzerBin32e;C:Program Files (x86)IntelVTuneAnalyzerBin;C:Program Files (x86)IntelVTuneSharedBin;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;c:Program Files (x86)Microsoft SQL Server90Toolsinn;C:Program Files (x86)IntelCompilerFortran10.1.019EM64TLib
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.VBS
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=EM64T Family 6 Model 15 Stepping 13, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0f0d
ProgramFiles=C:Program Files (x86)
ProgramFiles(x86)=C:Program Files (x86)
ProgramW6432=C:Program Files
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:WINDOWS
TEMP=C:DOCUME~1snuchiaLOCALS~1Temp
TMP=C:DOCUME~1snuchiaLOCALS~1Temp
USERDNSDOMAIN=TULSA.STATSOFT.COM
USERDOMAIN=TULSA
USERNAME=snuchia
USERPROFILE=C:Documents and Settingssnuchia
VisualStudioDir=C:Documents and SettingssnuchiaMy DocumentsVisual Studio 2008
VS90COMNTOOLS=C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools
VTUNE_GLOBAL_DIR=C:Program Files (x86)IntelVTuneglobal_data
WecVersionForRosebud.B88=2
windir=C:WINDOWS
__iflSearch=C:Program Files (x86)IntelCompilerFortran10.1.019IA32Bin;C:Program Files (x86)Common FilesIntelShared FilesIa32Bin;C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDE;C:Program Files (x86)Microsoft Visual Studio 9.0VCBIN;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools bin;c:WINDOWSMicrosoft.NETFrameworkv2.0.50727;C:Program FilesMicrosoft SDKsWindowsv6.0Ain;C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDE;C:Program Files (x86)Microsoft Visual Studio 9.0VCBIN;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools;C:WINDOWSMicrosoft.NETFrameworkv3.5;C:WINDOWSMicrosoft.NETFrameworkv2.0.50727;C:Program Files (x86)Microsoft Visual Studio 9.0VCVCPackages;C:Program FilesMicrosoft SDKsWindowsv6.0Ain;C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools..IDE;C:Program Files (x86)IntelVTuneCGGlbCache;C:Program Files (x86)IntelVTuneSharedBin32e;C:Program Files (x86)IntelVTuneAnalyzerBin32e;C:Program Files (x86)IntelVTuneAnalyzerBin;C:Program Files (x86)IntelVTuneSharedBin;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;c:Program Files (x86)Microsoft SQL Server90Toolsinn;C:Program Files (x86)IntelCompilerFortran10.1.019EM64TLib

Output
Compiling with Intel Fortran Compiler 10.1.019 [IA-32]...
ifort /nologo /Zi /Og /GB /QaxP /recursive /assume:bscc /fpscomp:logicals /module:"Release" /object:"Release" /c /Qvc9 /Qlocation,link,"C:Program Files (x86)Microsoft Visual Studio 9.0VCin" "C:codeSolution3Console1Console1Console1.f90"
C:codeSolution3Console1Console1Console1.f90(25): (col. 13) remark: _MAIN__ has been targeted for automatic cpu dispatch.
C:codeSolution3Console1Console1Console1.f90(16): (col. 16) remark: _COPY has been targeted for automatic cpu dispatch.
Linking...
Link /OUT:"ReleaseConsole1.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"C:codeSolution3Console1Console1 eleaseconsole1.exe.intermediate.manifest" /DEBUG /PDB:"C:codeSolution3Console1Console1 eleaseconsole1.pdb" /SUBSYSTEM:CONSOLE /IMPLIB:"C:codeSolution3Console1Console1 eleaseconsole1.lib" "ReleaseConsole1.obj"
Link: executing 'link'
Embedding manifest...
mt.exe /nologo /outputresource:"C:codeSolution3Console1Console1 eleaseconsole1.exe;#1" /manifest "C:codeSolution3Console1Console1 eleaseconsole1.exe.intermediate.manifest"
Console1 - 0 error(s), 0 warning(s)


					
				
			
			
				
			
			
			
			
			
			
			
		
0 Kudos
Steve_Nuchia
New Contributor I
1,294 Views
Here's a clue I had not noticed before: there's a blank, not a null, following "foo" in the optimized output. So it's ignoring the C, not simply mis-processing zero-length C strings.
0 Kudos
Steve_Nuchia
New Contributor I
1,294 Views

/assume:bscc seems to be the culprit; that breaks the output in Debug mode too.

The documentation doesn't say anything about that flag causing the C suffix to be ignored. Is it by design?

0 Kudos
Steven_L_Intel1
Employee
1,294 Views
No, that's not by design. I see that my original sample shows the problem. Thanks for reporting it.
0 Kudos
Steve_Nuchia
New Contributor I
1,294 Views

You're welcome. I've now discovered, digging further into the documentation, that the C suffix turns on backslash interpretation as well. That's probably why the features interact, and it also provides the workaround. I'm going to turn off the flag and make sure any literals with backslashes have a C suffix. A regular expression search should do the trick.

Always a pleasure doing business with you, sir.

-swn

0 Kudos
Reply