[all-commits] [llvm/llvm-project] d9df71: [clang][Sema] Fix and reapply 'Declare builtins u...

Nick Sarnie via All-commits all-commits at lists.llvm.org
Tue Jun 3 07:25:41 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d9df71045441e02d33cd01fad203862c7efd637e
      https://github.com/llvm/llvm-project/commit/d9df71045441e02d33cd01fad203862c7efd637e
  Author: Nick Sarnie <nick.sarnie at intel.com>
  Date:   2025-06-03 (Tue, 03 Jun 2025)

  Changed paths:
    M clang/include/clang/Parse/Parser.h
    M clang/lib/Parse/ParsePragma.cpp
    A clang/test/Sema/Inputs/builtin-system-header.h
    A clang/test/Sema/builtin-pragma-intrinsic-namespace.cpp
    A clang/test/Sema/builtin-pragma-intrinsic.c

  Log Message:
  -----------
   [clang][Sema] Fix and reapply 'Declare builtins used in #pragma intrinsic #138205' (#142019)

I had to revert https://github.com/llvm/llvm-project/pull/138205 in
https://github.com/llvm/llvm-project/pull/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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list