Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
plujon opened this issue Oct 21, 2020 · 3 comments
Closed

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

plujon opened this issue Oct 21, 2020 · 3 comments

Comments

@plujon
Copy link
Contributor

@plujon plujon commented Oct 21, 2020

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
@plujon plujon changed the title cookie.c triggers C1001 undef msvc 14 cookie.c triggers C1001 under msvc 14 Oct 21, 2020
@plujon plujon changed the title cookie.c triggers C1001 under msvc 14 cookie.c triggers C1001 under msvc 14 with -O2 Oct 21, 2020
@bagder
Copy link
Member

@bagder bagder commented Oct 22, 2020

This is a compiler bug, not a curl bug!

It makes me curious. This function you point out to trigger this problem has been around for a long time and lots of users have compiled curl in the mean time. Did really none of them use this optimization level with this compiler version?

Can you submit the proposed work-around as a pull request?

plujon added a commit to plujon/curl that referenced this issue Oct 27, 2020
plujon added a commit to plujon/curl that referenced this issue Oct 27, 2020
@jay
Copy link
Member

@jay jay commented Oct 27, 2020

How are you building curl that this happens? I don't recall anyone else reporting this.

@plujon
Copy link
Contributor Author

@plujon plujon commented Oct 28, 2020

cd winbuild && nmake /f Makefile.vc mode=dll GEN_PDB=yes
@bagder bagder closed this in e2075f2 Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants