-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Revert "[clang][Sema] Declare builtins used in #pragma intrinsic" #141994
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Nick Sarnie (sarnex) ChangesReverts llvm/llvm-project#138205 Breaks Chrome. Full diff: https://github.com/llvm/llvm-project/pull/141994.diff 3 Files Affected:
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 4e67fd033b9aa..77b61af768993 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -301,13 +301,9 @@ struct PragmaMSRuntimeChecksHandler : public EmptyPragmaHandler {
};
struct PragmaMSIntrinsicHandler : public PragmaHandler {
- PragmaMSIntrinsicHandler(Sema &Actions)
- : PragmaHandler("intrinsic"), Actions(Actions) {}
+ PragmaMSIntrinsicHandler() : PragmaHandler("intrinsic") {}
void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
Token &FirstToken) override;
-
-private:
- Sema &Actions;
};
// "\#pragma fenv_access (on)".
@@ -521,7 +517,7 @@ void Parser::initializePragmaHandlers() {
PP.AddPragmaHandler(MSOptimize.get());
MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
PP.AddPragmaHandler(MSRuntimeChecks.get());
- MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>(Actions);
+ MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>();
PP.AddPragmaHandler(MSIntrinsic.get());
MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
PP.AddPragmaHandler(MSFenvAccess.get());
@@ -3797,15 +3793,7 @@ void PragmaMSIntrinsicHandler::HandlePragma(Preprocessor &PP,
if (!II->getBuiltinID())
PP.Diag(Tok.getLocation(), diag::warn_pragma_intrinsic_builtin)
<< II << SuggestIntrinH;
- // If the builtin hasn't already been declared, declare it now.
- DeclarationNameInfo NameInfo(II, Tok.getLocation());
- LookupResult Previous(Actions, NameInfo, Sema::LookupOrdinaryName,
- Actions.forRedeclarationInCurContext());
- Actions.LookupName(Previous, Actions.getCurScope(),
- /*CreateBuiltins*/ false);
- if (Previous.empty())
- Actions.LazilyCreateBuiltin(II, II->getBuiltinID(), Actions.getCurScope(),
- /*ForRedeclaration*/ true, Tok.getLocation());
+
PP.Lex(Tok);
if (Tok.isNot(tok::comma))
break;
diff --git a/clang/test/Sema/Inputs/builtin-system-header.h b/clang/test/Sema/Inputs/builtin-system-header.h
deleted file mode 100644
index 7eeb8d811fcfa..0000000000000
--- a/clang/test/Sema/Inputs/builtin-system-header.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifdef USE_PRAGMA_BEFORE
-#pragma intrinsic(_InterlockedOr64)
-#endif
-
-#define MACRO(x,y) _InterlockedOr64(x,y);
-
-#ifdef USE_PRAGMA_AFTER
-#pragma intrinsic(_InterlockedOr64)
-#endif
diff --git a/clang/test/Sema/builtin-pragma-intrinsic.c b/clang/test/Sema/builtin-pragma-intrinsic.c
deleted file mode 100644
index 1e8507bfd37df..0000000000000
--- a/clang/test/Sema/builtin-pragma-intrinsic.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify -triple arm64-windows -isystem %S/Inputs %s -DUSE_PRAGMA_BEFORE
-// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify -triple arm64-windows -isystem %S/Inputs %s -DUSE_PRAGMA_AFTER
-// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify -triple arm64-windows -isystem %S/Inputs %s -DUSE_PRAGMA_AFTER_USE
-// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify -triple arm64-windows -isystem %S/Inputs %s -DUSE_PRAGMA_SAME_FILE
-// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify -triple arm64-windows -isystem %S/Inputs %s
-
-#if defined(USE_PRAGMA_BEFORE) || defined(USE_PRAGMA_AFTER) || defined(USE_PRAGMA_SAME_FILE)
-// expected-no-diagnostics
-#else
-// expected-error@+10 {{call to undeclared library function '_InterlockedOr64'}}
-// expected-note@+9 {{include the header <intrin.h> or explicitly provide a declaration for '_InterlockedOr64'}}
-#endif
-#include <builtin-system-header.h>
-
-#ifdef USE_PRAGMA_SAME_FILE
-#pragma intrinsic(_InterlockedOr64)
-#endif
-
-void foo() {
- MACRO(0,0);
-}
-
-#ifdef USE_PRAGMA_AFTER_USE
-#pragma intrinsic(_InterlockedOr64)
-#endif
|
Thanks! |
Sorry for the trouble |
sarnex
added a commit
to sarnex/llvm-project
that referenced
this pull request
May 30, 2025
sarnex
added a commit
to sarnex/llvm-project
that referenced
this pull request
May 30, 2025
sarnex
added a commit
to sarnex/llvm-project
that referenced
this pull request
May 30, 2025
sarnex
added a commit
that referenced
this pull request
Jun 3, 2025
…insic #138205' (#142019) I had to revert #138205 in #141994 because it broke the Chrome build. The problem came down to the following: ```c++ unsigned __int64 _umul128(unsigned __int64, unsigned __int64, unsigned __int64 *); namespace {} #pragma intrinsic(_umul128) void foo() { unsigned __int64 carry; unsigned __int64 low = _umul128(0, 0, &carry); } ``` When processing the `#pragma intrinsic` line, we do a name lookup to see if the builtin was previously declared. In this case the lookup fails because the current namespace of the parser and sema is the above namespace scope. The processing of the pragma happens as part of the namespace close parsing. This is usually fine because most pragmas don't care about scopes. However, that's not true for this and other MS pragmas. To fix this, we change the `#pragma intrinsic` processing to be the same as other MS pragmas such as "optimize". Those are processed like a declaration, and because of that we have the correct current scope, so the lookup succeeds. I added a test case that locks down the Chrome fix, as well as manually tested the Chrome build and confirmed it passed.
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Jun 3, 2025
…ragma intrinsic #138205' (#142019) I had to revert llvm/llvm-project#138205 in llvm/llvm-project#141994 because it broke the Chrome build. The problem came down to the following: ```c++ unsigned __int64 _umul128(unsigned __int64, unsigned __int64, unsigned __int64 *); namespace {} #pragma intrinsic(_umul128) void foo() { unsigned __int64 carry; unsigned __int64 low = _umul128(0, 0, &carry); } ``` When processing the `#pragma intrinsic` line, we do a name lookup to see if the builtin was previously declared. In this case the lookup fails because the current namespace of the parser and sema is the above namespace scope. The processing of the pragma happens as part of the namespace close parsing. This is usually fine because most pragmas don't care about scopes. However, that's not true for this and other MS pragmas. To fix this, we change the `#pragma intrinsic` processing to be the same as other MS pragmas such as "optimize". Those are processed like a declaration, and because of that we have the correct current scope, so the lookup succeeds. I added a test case that locks down the Chrome fix, as well as manually tested the Chrome build and confirmed it passed.
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Jun 3, 2025
…vm#141994) Reverts llvm#138205 Breaks Chrome.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #138205
Breaks Chrome.