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

Builtin::BIalloca not defined under MSVC #4885

Closed
llvmbot opened this issue Jul 7, 2009 · 5 comments
Closed

Builtin::BIalloca not defined under MSVC #4885

llvmbot opened this issue Jul 7, 2009 · 5 comments
Labels
bugzilla Issues migrated from bugzilla build-problem clang:frontend Language frontend issues, e.g. anything involving "Sema" portability

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 7, 2009

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.

@lattner
Copy link
Collaborator

lattner commented Jul 7, 2009

#undef'ing alloca is the right fix. Please prepare a patch for this and I'd be happy to apply it. I would do it, but I can't test on VC++.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 8, 2009

#undef alloca for VC++
Here's a patch. Feel free to change/delete the comment.

@lattner
Copy link
Collaborator

lattner commented Jul 8, 2009

The #undef shouldn't go in the .def file, please add it to the .cpp or .h file that #includes the .def file. Thanks, sorry for the confusion.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 8, 2009

#undef alloca for VC++ (take 2)
This puts the #undef in Builtins.h. Builtins.def is also #included by Builtins.cpp but there's no issue there because it provides a #define for LIBBUILTIN.

@lattner
Copy link
Collaborator

lattner commented Jul 8, 2009

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this issue Jun 30, 2022
[swift/release/5.7][LLDB][ClangASTImporter] Revert "[lldb] Disable minimal import mode for RecordDecls that back FieldDecls"
aeubanks added a commit that referenced this issue Feb 13, 2024
Added in 26670dc to workaround #4885.

Windows CI and a local Windows build are happy with this change, so it
seems like this has been properly fixed at some point. If this does
break somebody, this can be easily reverted. (Also, Linux does the same
`#define alloca` in system headers, so I'm not sure why it'd be
different on Windows)

This is tech debt that caused breakages, see comments on #71709.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla build-problem clang:frontend Language frontend issues, e.g. anything involving "Sema" portability
Projects
None yet
Development

No branches or pull requests

2 participants