[PATCH] D154725: [AggressiveInstCombine] Fold strcmp for short string literals

Asmaa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 8 02:46:00 PDT 2023


asmok-g added a comment.

This is causing a mis-compilation. Repro:

  #include <string.h>
  
  #define TOKMAXLEN 10
  
  typedef struct {
    char token[TOKMAXLEN + 1]; /* always NUL-terminated */
  } datetkn;
  
  constexpr datetkn TimezoneAbbrevTable[] = {{"z"}};
  
  static const int TimezoneAbbrevTableSize =
      sizeof TimezoneAbbrevTable / sizeof TimezoneAbbrevTable[0];
  
  int main() {
    const char* token = "";
    for (int i = 0; i < TimezoneAbbrevTableSize; ++i) {
      const datetkn& timezone_abbrev = TimezoneAbbrevTable[i];
      if (strcmp("z", token) <= 0) {
        return 10;
      }
      token = timezone_abbrev.token;
    }
  
    return 0;
  }

cmd: `clang  -O2 ./prog.cc -o ./prog.o`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154725/new/

https://reviews.llvm.org/D154725



More information about the llvm-commits mailing list