Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. What the hell GCC, again

What the hell GCC, again

Scheduled Pinned Locked Moved The Weird and The Wonderful
algorithmsperformancehelpquestion
2 Posts 2 Posters 34 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    k5054
    wrote on last edited by
    #1

    Given

    #include void swap(char foo[10][20], int i1, int i2)
    {
    if(i1 != i2)
    {
    char buff[20];
    strcpy(buff, foo[i1]);
    strcpy(foo[i1], foo[i2]);
    strcpy(foo[i2], buff);
    }
    }

    when compiling with any optimization level above -O0, gcc complains about the second strcpy, saying

    warning: ‘strcpy’ accessing 1 byte at offsets [-4611686018427387904, 4611686018427387903] and [-4611686018427387904, 4611686018427387903] overlaps 1 byte at offset [-4611686018427387904, 199] [-Wrestrict]

    clang doesn't complain, even at -O3. I think what gcc is trying to tell me is that there is an issue when i1 == i2, even though there's a test to not swap if i1 == i2! If I replace i1, i2 with integer values (eg. 1, 2) the warning goes away! Weird. So far, the only way I've found to stop gcc from issuing a warning is to use memcpy instead of strcpy. Though both have restrict qualifiers to both arguments. Or maybe I'm missing something?

    "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

    B 1 Reply Last reply
    0
    • K k5054

      Given

      #include void swap(char foo[10][20], int i1, int i2)
      {
      if(i1 != i2)
      {
      char buff[20];
      strcpy(buff, foo[i1]);
      strcpy(foo[i1], foo[i2]);
      strcpy(foo[i2], buff);
      }
      }

      when compiling with any optimization level above -O0, gcc complains about the second strcpy, saying

      warning: ‘strcpy’ accessing 1 byte at offsets [-4611686018427387904, 4611686018427387903] and [-4611686018427387904, 4611686018427387903] overlaps 1 byte at offset [-4611686018427387904, 199] [-Wrestrict]

      clang doesn't complain, even at -O3. I think what gcc is trying to tell me is that there is an issue when i1 == i2, even though there's a test to not swap if i1 == i2! If I replace i1, i2 with integer values (eg. 1, 2) the warning goes away! Weird. So far, the only way I've found to stop gcc from issuing a warning is to use memcpy instead of strcpy. Though both have restrict qualifiers to both arguments. Or maybe I'm missing something?

      "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      GCC's warnings are often way too strict (and in some cases, outright wrong).

      What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups