[PATCH] D128649: [clang-cl] Handle some pragma alloc_text corner cases handled by MSVC

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 01:53:33 PDT 2022


hans added a comment.

In D128649#3612875 <https://reviews.llvm.org/D128649#3612875>, @steplong wrote:

>> Isn't the question whether `f` is considered "extern C" in the end or not? I thought `isExternC()` checks that? Are you saying it would return false for `f` in your example?
>
> Yup, `isExternC()` is returning false for that case because there's "static".

I see. It seems there's already some code that gives special treatment to "static extern c" functions in CodeGenModule::MaybeHandleStaticInExternC(): https://github.com/llvm/llvm-project/blob/llvmorg-14.0.6/clang/lib/CodeGen/CodeGenModule.cpp#L4420

Okay, I think this is almost ready. I just had one more comment about the if-statements above.



================
Comment at: clang/lib/Sema/SemaAttr.cpp:825
+      }
+    } else if (!isa<FunctionDecl>(ND)) {
+      Diag(Loc, diag::err_pragma_alloc_text_not_function);
----------------
Instead of checking this in two places, how about doing something like:

```
FunctionDecl *FD = dyn_cast<FunctionDecl>(ND->getCanonicalDecl());
if (!FD) {
  // error
}
```

above right after the `if (!ND)` check? Then the C++ specific code just becomes

```
if (!FD->isInExternCContext()) {
  // error
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128649/new/

https://reviews.llvm.org/D128649



More information about the cfe-commits mailing list