<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re:assert failes if struct tag-name is given in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1209091#M704</link>
    <description>&lt;P&gt;Hi Gagan,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Could you let me know if the solution provided helped?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Rahul&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 14 Sep 2020 07:15:55 GMT</pubDate>
    <dc:creator>RahulV_intel</dc:creator>
    <dc:date>2020-09-14T07:15:55Z</dc:date>
    <item>
      <title>assert failes if struct tag-name is given</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1206806#M700</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I noticed a strange problem. If I give structs and unions without tag-names, I get no issues but if I specify tag-names, I get static_assert.&lt;/P&gt;
&lt;P&gt;Here is the code:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;typedef struct KernelLightDistribution {
  float totarea;
  int prim;
  union dpct_type_be6907 {
    struct dpct_type_12c54e {
      int shader_flag;
      int object_id;
    } mesh_light;
    struct dpct_type_ff924c {
      float pad;
      float size;
    } lamp;
  };
} KernelLightDistribution;
static_assert_align(KernelLightDistribution, 16);&lt;/LI-CODE&gt;
&lt;P&gt;where static_assert_align is:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#define static_assert_align(st, align) \
  static_assert((sizeof(st) % (align) == 0), "Structure must be strictly aligned")  // NOLINT
&lt;/LI-CODE&gt;
&lt;P&gt;When I compile using dpcpp (with -std=c++17), I get static_assert&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;../kernel/kernel_types.h:1553:1: error: static_assert failed due to requirement 'sizeof(ccl::KernelLightDistribution) % (16) == 0' "Structure must be strictly aligned"
static_assert_align(KernelLightDistribution, 16);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../util/util_static_assert.h:32:3: note: expanded from macro 'static_assert_align'
  static_assert((sizeof(st) % (align) == 0), "Structure must be strictly aligned")  // NOLINT
&lt;/LI-CODE&gt;
&lt;P&gt;But If I comment out the tag-names and use anonymous union and structs, static_assert disappears and code compiles without error.&lt;/P&gt;
&lt;P&gt;Code with tag-names commented out:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;typedef struct KernelLightDistribution {
  float totarea;
  int prim;
  union /* dpct_type_be6907 */ {
    struct /* dpct_type_12c54e */ {
      int shader_flag;
      int object_id;
    } mesh_light;
    struct /* dpct_type_ff924c */ {
      float pad;
      float size;
    } lamp;
  };
} KernelLightDistribution;
static_assert_align(KernelLightDistribution, 16);&lt;/LI-CODE&gt;
&lt;P&gt;Now the file compiles without any error.&lt;/P&gt;
&lt;P&gt;Should struct or union tag-names affect its size or alignment?&lt;/P&gt;
&lt;P&gt;static_assert comes back if I uncomment union tag name or struct tag-names ie if I uncomment any of the three tag-names, problem comes back.&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR /&gt;Gagan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 14:59:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1206806#M700</guid>
      <dc:creator>Shukla__Gagandeep</dc:creator>
      <dc:date>2020-09-04T14:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: assert failes if struct tag-name is given</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1207261#M703</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a small bug in your code. You have not initialized the union &lt;SPAN style="font-size: 14px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;"&gt;dpct_type_be6907.&amp;nbsp;&lt;/SPAN&gt;As a result, memory is not getting created for that particular data structure. Anonymous structs/unions are a bit lenient when it comes to initialization since they can be accessed right way and they are guaranteed to be present within a struct/union. (Memory always gets created for anonymous structs/unions)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Refer to the modified code snippet below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;
#include &amp;lt;iostream&amp;gt;

#define static_assert_align(st, align) \
  static_assert((sizeof(st) % (align) == 0), "Structure must be strictly aligned")  // NOLINT


typedef struct KernelLightDistribution {
  float totarea;
  int prim;
  union dpct_type_be6907 {
    struct dpct_type_12c54e {
      int shader_flag;
      int object_id;
    } mesh_light;
    struct  dpct_type_ff924c {
      float pad;
      float size;
    } lamp;
  } union_name; //Note the inialization here
} KernelLightDistribution;

int main() {

    std::cout &amp;lt;&amp;lt; sizeof(KernelLightDistribution) &amp;lt;&amp;lt; "\n";
    static_assert_align(KernelLightDistribution, 16);

    return 0;
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Rahul&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 09:23:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1207261#M703</guid>
      <dc:creator>RahulV_intel</dc:creator>
      <dc:date>2020-09-07T09:23:00Z</dc:date>
    </item>
    <item>
      <title>Re:assert failes if struct tag-name is given</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1209091#M704</link>
      <description>&lt;P&gt;Hi Gagan,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Could you let me know if the solution provided helped?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Rahul&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 14 Sep 2020 07:15:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1209091#M704</guid>
      <dc:creator>RahulV_intel</dc:creator>
      <dc:date>2020-09-14T07:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Re:assert failes if struct tag-name is given</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1209565#M705</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;
&lt;P&gt;Yes, that issue got solved. And yeah, once you pointed out, the mistake became quite clear.&lt;/P&gt;
&lt;P&gt;But to match ported code with actual code, I went ahead with using anonymous structs/unions. Thanks for your help.&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR /&gt;Gagan&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 13:35:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1209565#M705</guid>
      <dc:creator>Shukla__Gagandeep</dc:creator>
      <dc:date>2020-09-15T13:35:43Z</dc:date>
    </item>
    <item>
      <title>Re:assert failes if struct tag-name is given</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1209782#M707</link>
      <description>&lt;P&gt;Thanks for the confirmation.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Intel will no longer monitor this thread. However, it will remain open for community discussion.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Sep 2020 06:01:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/assert-failes-if-struct-tag-name-is-given/m-p/1209782#M707</guid>
      <dc:creator>RahulV_intel</dc:creator>
      <dc:date>2020-09-16T06:01:16Z</dc:date>
    </item>
  </channel>
</rss>

