Skip to content

Builtin::BIalloca not defined under MSVC #4885

Closed
@llvmbot

Description

@llvmbot
Bugzilla Link 4513
Resolution FIXED
Resolved on Mar 12, 2010 00:55
Version unspecified
OS Windows XP
Reporter LLVM Bugzilla Contributor
CC @asl

Extended Description

When compiling under MSVC, Builtin::BIalloca is not declared. This causes CGBuiltin.cpp to fail to compile.

The problem is that the system headers have this:

#if     !__STDC__
/* Non-ANSI names for compatibility */
#define alloca  _alloca
#endif  /* __STDC__*/

When Builtin.h #includes Builtins.def it does so with BUILTIN defined as:

#define BUILTIN(ID, TYPE, ATTRS) BI##ID,

LIBBUILTIN is not defined so Builtins.def supplies a default definition:

#if defined(BUILTIN) && !defined(LIBBUILTIN)
#  define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) BUILTIN(ID, TYPE, ATTRS)
#endif

Then the line

LIBBUILTIN(alloca, "v*z",         "f",     "stdlib.h")

expands to BI_alloca, instead of the intended BIalloca,

This happens because LIBBUILTIN is defined in terms of BUILTIN. The preprocessor rescans and expands the parameter before the concat. If the line was BUILTIN(alloca, ...) then it would work properly.

Any of the following should fix this:

  1. Explicitly #undef alloca
  2. Change Builtins.h to explictly #define LIBBUILTIN and remove the default definition from Builtins.def
  3. Change the default definition in Builtins.def to:
#  define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) BUILTIN(##ID, TYPE, ATTRS)

but this isn't portable. I don't know if there's a portable way to stop the preprocessor from rescanning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions