Skip to content

cookie.c triggers C1001 under msvc 14 with -O2 #6112

@plujon

Description

@plujon

lib/cookie.c and lib/strcase.c team up to trigger an internal compiler error under msvc-14.

Here's a reduced translation unit that triggers the bug.

#include <stddef.h>

#define COOKIE_HASH_SIZE 256

char Curl_raw_toupper(char in);

size_t cookie_hash_domain(const char *domain, const size_t len)
{
  const char *end = domain + len;
  size_t h = 5381;

  while(domain < end) {
    h += h << 5;
    h ^= Curl_raw_toupper(*domain++);
  }

  return (h % COOKIE_HASH_SIZE);
}

/*
 * cl -O2 -c t.c
 *
 * t.c(..) : fatal error C1001: An internal error has occurred in the compiler.
 * (compiler file 'f:/dd/vctools/compiler/utc/src/p2/main.c', line 246)
 *  To work around this problem, try simplifying or changing the program near the locations listed above.
 * Please choose the Technical Support command on the Visual C++
 *  Help menu, or open the Technical Support help file for more information
 *
 * INTERNAL COMPILER ERROR in 'C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/BIN/cl.exe'
 *     Please choose the Technical Support command on the Visual C++
 *     Help menu, or open the Technical Support help file for more information
 */

I have verified the bug is hit when _MSC_VER is 1900, but not when _MSC_VER is 1926 (msvc-15).

Disabling optimization for msvc-14 avoids the problem.

#if _MSC_VER == 1900
#pragma optimize("", off)
#endif

size_t cookie_hash_domain(const char *domain, const size_t len)
. . .

#if _MSC_VER == 1900
#pragma optimize("", on)
#endif

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions