<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi,<br>
<br>
I have a problem relating to the way clang handles static const structure declarations in c++ classes.<br>
<br>
If only the declaration is visible:<br>
<font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">    class K {static const struct S k; ...}</span></font><font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr"><br>
</span></font>the constness is not emitted in the declaration:<br>
<font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">    @_ZN1K1kE = external global %struct.S<br>
should this not be:</span></font><br>
<font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">    @_ZN1K1kE = external
</span></font><font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr"><font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">constant</span></font> %struct.S</span></font><br>
<br>
If the definition is visible too:<br>
<font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">    class J {static const struct S j;...}<br>
    const struct S J::j = {1,2};</span></font><br>
we get a global 'const' definition, viz:<br>
<font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">    @_ZN1J1jE = constant %struct.S { i32 1, i32 2 }, align 4<br>
</span></font><br>
It should be noted that the handling of arrays always uses const - see below.<br>
<br>
Am I correct in believing this is a bug?<br>
Can anyone direct me to where the problem may reside?<br>
<br>
This is a problem on the XCore target as we handle constant and non-constant data in separate areas and hence will emit different assembler instructions.<br>
<br>
Robert<br>
<br>
<br>
<font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">struct S{int s1; int s2;};<br>
<br>
class I {<br>
  static const int i[2];<br>
  static int ii();<br>
};<br>
int I::ii(){return i[0];}<br>
// I::i defined else where - OK<br>
<br>
class J {<br>
  static const struct S j;<br>
  static struct S jj();<br>
};<br>
struct S J::jj(){return j;}<br>
const struct S J::j = {1,2};<br>
<br>
<br>
class K {<br>
  static const struct S k;<br>
  static struct S kk();<br>
};<br>
struct S K::kk(){return k;}<br>
// K::k defined else where - const is lost<br>
<br>
<br>
%struct.S = type { i32, i32 }<br>
@_ZN1I1iE = external constant [2 x i32]<br>
@_ZN1J1jE = constant %struct.S { i32 1, i32 2 }, align 4<br>
@_ZN1K1kE = external global %struct.S<br>
<br>
define i32 @_ZN1I2iiEv() #0 align 2 {<br>
entry:<br>
  %0 = load i32* getelementptr inbounds ([2 x i32]* @_ZN1I1iE, i32 0, i32 0), align 4<br>
  ret i32 %0<br>
}<br>
<br>
define void @_ZN1J2jjEv(%struct.S* noalias sret %agg.result) #0 align 2 {<br>
entry:<br>
  %0 = bitcast %struct.S* %agg.result to i8*<br>
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast (%struct.S* @_ZN1J1jE to i8*), i32 8, i32 4, i1 false)<br>
  ret void<br>
}<br>
<br>
define void @_ZN1K2kkEv(%struct.S* noalias sret %agg.result) #0 align 2 {<br>
entry:<br>
  %0 = bitcast %struct.S* %agg.result to i8*<br>
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast (%struct.S* @_ZN1K1kE to i8*), i32 8, i32 4, i1 false)<br>
  ret void<br>
}</span></font><br>
<br>
</div>
</body>
</html>