[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-27 Thread Sean Perry via cfe-commits

https://github.com/perry-ca edited 
https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-20 Thread Sean Perry via cfe-commits


@@ -7552,6 +7552,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``_Export`` keyword on a function or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the ``_Export``

perry-ca wrote:

We don't diagnose that `anthony` isn't defined. This was never diagnosed in the 
existing z/OS compiler and neither with the visibility attribute.  The wording 
is a little strong.  We should say the object is only exported if it is also 
defined in the translation unit.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-20 Thread Sean Perry via cfe-commits


@@ -4504,6 +4504,11 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // We're done with the declaration-specifiers.
+  goto DoneWithDeclSpec;

perry-ca wrote:

`_Export` is part of the declarator.  If you see the keyword, the declspec is 
done and and you are now in the declarator.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-20 Thread Sean Perry via cfe-commits


@@ -401,6 +401,12 @@ struct PragmaMaxTokensTotalHandler : public PragmaHandler {
 Token &FirstToken) override;
 };
 
+struct PragmaExportHandler : public PragmaHandler {

perry-ca wrote:

Ok.  Multiple requests now.  I'll move the keyword _Export into a new PR.  Do 
you prefer two new ones or keep this one going just for the pragma?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-20 Thread Sean Perry via cfe-commits


@@ -1400,6 +1416,171 @@ bool Parser::HandlePragmaMSAllocText(StringRef 
PragmaName,
   return true;
 }
 
+NestedNameSpecifier *
+Parser::zOSParseIdentifier(StringRef PragmaName,
+   const IdentifierInfo *IdentName) {
+  NestedNameSpecifier *NestedId = nullptr;

perry-ca wrote:

The grammar for the pragma is:
```
'#pragma' 'map' '(' name  ',' string-literal ')'
```
or
```
'#pragma' 'map' '(' qualified-name '(' argument-list ')' cv-qualifiers ',' 
string-literal ')'
```
The first syntax is straight forward.  The name matches functions declared as 
extern "C" in C++.  The second syntax provides matching for functions with C++ 
linkage.  The qualified name here isn't an expression.  It is like the 
declarator-id and will match a future declaration.  I haven't seen anything 
that does what this code does.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-20 Thread Sean Perry via cfe-commits


@@ -7552,6 +7552,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``_Export`` keyword on a function or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the ``_Export``
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function ``anthony``, if you define the function in 
the
+translation unit. The ``_Export`` keyword must immediately precede the 
declaration name.
+If you apply the ``_Export`` keyword to a class, the compiler automatically 
exports

perry-ca wrote:

Unions are handled the same way as classes or structs.  Any member function or 
static data member of the union will be exported.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-20 Thread Sean Perry via cfe-commits


@@ -4504,6 +4504,11 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // We're done with the declaration-specifiers.
+  goto DoneWithDeclSpec;

perry-ca wrote:

The test case above is valid and exports x.
```
@x = global ptr null, align 8
```
I'll add a test case to cover this.

You are correct.  This keyword is expected to appear right before the 
identifier of the symbol being exported.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Hubert Tong via cfe-commits


@@ -4504,6 +4504,11 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // We're done with the declaration-specifiers.
+  goto DoneWithDeclSpec;

hubert-reinterpretcast wrote:

`_Export` is not really a declaration specifier (at least in the traditional 
implementation).
It is more like a C++11 attribute except that it lives on the left of a 
_declarator-id_ instead of on the right.
In some realizations, the (less clean) conceptual model is that it is a 
declarator like `*` is, except it binds more strongly than `()` or `[]`.

@perry-ca, I don't see any test in this PR for `_Export` in positions like:
```cpp
int (*_Export x)(void) = 0;
```

Is the above accepted with this PR? Which conceptual model is being implemented 
here?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Sean Perry via cfe-commits


@@ -5087,6 +5087,19 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, 
AccessSpecifier AS,
   assert(EllipsisLoc.isInvalid() &&
  "Friend ellipsis but not friend-specified?");
 
+  if (DS.isExportSpecified()) {
+VisibilityAttr *existingAttr = TagD->getAttr();
+if (existingAttr) {
+  VisibilityAttr::VisibilityType existingValue =
+  existingAttr->getVisibility();
+  if (existingValue != VisibilityAttr::Default)
+Diag(DS.getExportSpecLoc(), diag::err_mismatched_visibility);
+} else {
+  Tag->addAttr(

perry-ca wrote:

Totally valid.  The intention was to have these be another way to specify 
`__attribute__((visibility("default")))`.  I've rewritten the code to these 
issues and have hopefully addressed all of your concerns.  

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Erich Keane via cfe-commits


@@ -401,6 +401,12 @@ struct PragmaMaxTokensTotalHandler : public PragmaHandler {
 Token &FirstToken) override;
 };
 
+struct PragmaExportHandler : public PragmaHandler {

erichkeane wrote:

This patch is big enough... I am beginning to wonder if we should split this 
pragma off into a separate patch.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Erich Keane via cfe-commits


@@ -7552,6 +7552,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``_Export`` keyword on a function or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the ``_Export``
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function ``anthony``, if you define the function in 
the
+translation unit. The ``_Export`` keyword must immediately precede the 
declaration name.
+If you apply the ``_Export`` keyword to a class, the compiler automatically 
exports

erichkeane wrote:

```suggestion
If you apply the ``_Export`` keyword to a class or struct, the compiler 
automatically exports
```

What does it do with unions?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

There seems to be a LOT of added complexity for the `#pragma export`, to the 
point that I'm not sure of the value compared to the keyword, and if we're 
going to keep it, we need to spend quite a bit more time on it.

As far as the keyword itself, I think there are quite a few more diagnostics we 
should look at, particularly for 'completeness'.  I don't really like the error 
that is being diagnosed (just 'cannot be qualified'), as that is really quite 
vague.  We need to try harder on that.


https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Erich Keane via cfe-commits


@@ -7552,6 +7552,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``_Export`` keyword on a function or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the ``_Export``

erichkeane wrote:

This documentation should also mention the pragma spelling and document the 
whole thing.  Also, do we diagnose that `anothony` isn't defined?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Erich Keane via cfe-commits


@@ -1400,6 +1416,171 @@ bool Parser::HandlePragmaMSAllocText(StringRef 
PragmaName,
   return true;
 }
 
+NestedNameSpecifier *
+Parser::zOSParseIdentifier(StringRef PragmaName,
+   const IdentifierInfo *IdentName) {
+  NestedNameSpecifier *NestedId = nullptr;

erichkeane wrote:

What is this for the grammar of?  Are you just trying to get the name of a 
thing?  I did something similar, see : `ParseOpenACCIDExpression`.  For C++ you 
can use `ParseCXXIdExpression`, and I emulated it for C.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Erich Keane via cfe-commits


@@ -4504,6 +4504,11 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // We're done with the declaration-specifiers.
+  goto DoneWithDeclSpec;

erichkeane wrote:

Does this mean `_Export` has to be last?   Not a parser guy here, but this one 
doesn't feel right to me?  @aaronballman can you double check here?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Erich Keane via cfe-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-09 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

I didn't spot any further concerns, but I'd appreciate a second set of eyes on 
this given the size of the changes.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-05-02 Thread Sean Perry via cfe-commits

https://github.com/perry-ca updated 
https://github.com/llvm/llvm-project/pull/111035



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-04-15 Thread Eli Friedman via cfe-commits


@@ -5087,6 +5087,19 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, 
AccessSpecifier AS,
   assert(EllipsisLoc.isInvalid() &&
  "Friend ellipsis but not friend-specified?");
 
+  if (DS.isExportSpecified()) {
+VisibilityAttr *existingAttr = TagD->getAttr();
+if (existingAttr) {
+  VisibilityAttr::VisibilityType existingValue =
+  existingAttr->getVisibility();
+  if (existingValue != VisibilityAttr::Default)
+Diag(DS.getExportSpecLoc(), diag::err_mismatched_visibility);
+} else {
+  Tag->addAttr(

efriedma-quic wrote:

My concern here is that you have code scattered in multiple places to control 
the visibility; you have two different places you add a visibility attribute, 
and then you override the visibility in codegen.  Having overlapping ways of 
specifying the visibility will likely lead to weird bugs in edge cases.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-04-10 Thread Sean Perry via cfe-commits

perry-ca wrote:

@AaronBallman @efriedma-quic.  I believe I have addressed all of your comments. 
 I moved the tests into Parser/Sema and added some more (and fixed problems 
these found).  Thanks for the feedback.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-04-05 Thread Hubert Tong via cfe-commits


@@ -4456,6 +4456,12 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // If we find kw__Export, it is being applied to a var or function
+  // This will be handled in ParseDeclaratorInternal()

hubert-reinterpretcast wrote:

> That is deeply strange behavior IMO. I can't think of anything else in the 
> language that works like that in that syntactic position.

In the traditional implementation, `_Export` is a declarator like `*` is, 
except it binds more strongly than `()` or `[]`.


https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-04-04 Thread Sean Perry via cfe-commits


@@ -0,0 +1,5 @@
+// REQUIRES: systemz-registered-target

perry-ca wrote:

The `int _Export x, y;` is tested in attr-export.cpp
```
int _Export var3, var4, _Export var5;
```

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-28 Thread Sean Perry via cfe-commits


@@ -5087,6 +5087,19 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, 
AccessSpecifier AS,
   assert(EllipsisLoc.isInvalid() &&
  "Friend ellipsis but not friend-specified?");
 
+  if (DS.isExportSpecified()) {
+VisibilityAttr *existingAttr = TagD->getAttr();
+if (existingAttr) {
+  VisibilityAttr::VisibilityType existingValue =
+  existingAttr->getVisibility();
+  if (existingValue != VisibilityAttr::Default)
+Diag(DS.getExportSpecLoc(), diag::err_mismatched_visibility);
+} else {
+  Tag->addAttr(

perry-ca wrote:

When -fvisibility=hidden (which is the default on z/OS), etc this is needed to 
ensure the symbol is exported.  This is analogous to a declaration with the 
default visibility attribute specified.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-25 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,5 @@
+// REQUIRES: systemz-registered-target

AaronBallman wrote:

Yes, there should be. As well as potentially confusing uses of `_Export` as in 
`int _Export x, y;`.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-25 Thread Aaron Ballman via cfe-commits


@@ -4456,6 +4456,12 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // If we find kw__Export, it is being applied to a var or function
+  // This will be handled in ParseDeclaratorInternal()

AaronBallman wrote:

> in int _Export x,y; only x is exported.

That is deeply strange behavior IMO. I can't think of anything else in the 
language that works like that in that syntactic position.

> We do have to match the existing XL compiler for backwards compatibility.

That can be handled in the downstream too. For example, in this case, I would 
expect a diagnostic to let the user know that `_Export` very likely does not 
behave the way they expect in your code example.


https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-24 Thread Hubert Tong via cfe-commits


@@ -0,0 +1,5 @@
+// REQUIRES: systemz-registered-target

hubert-reinterpretcast wrote:

Should there be diagnostics (and corresponding testing) for ignored/meaningless 
uses of `_Export`?

e.g.,
```cpp
typedef int _Export ty;
ty x;
int f(int _Export x);
static int _Export s;
struct S {
  int _Export nonstaticdatamember;
};
void g() {
  int _Export automatic;
}
```

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-24 Thread Sean Perry via cfe-commits


@@ -4456,6 +4456,12 @@ void Parser::ParseDeclarationSpecifiers(
   isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
   break;
 
+case tok::kw__Export:
+  // If we find kw__Export, it is being applied to a var or function
+  // This will be handled in ParseDeclaratorInternal()

perry-ca wrote:

The _Export keyword is part of the declarator.  This code is to stop the 
declspec parsing.  For example, in `int _Export x,y;` only `x` is exported.  
The flag was added to the DeclSpec class to handle the case of `class _Export 
A`.  That is later passed on to the Decl for the class.  If there is a better 
way to do this, I'd be interested.  We do have to match the existing XL 
compiler for backwards compatibility.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-15 Thread Sean Perry via cfe-commits

https://github.com/perry-ca commented:

@AaronBallman Thanks for the feedback.  I'll make the changes and look into why 
_Exxport wasn't implemented like the other declspecs.

I did consider these to be the same feature (two ways to set the same 
information).  If it's easier for reviewing I can look into splitting the PR.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-13 Thread Sean Perry via cfe-commits


@@ -1273,6 +1273,168 @@ void 
Sema::AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD) {
 FD->addAttr(NoBuiltinAttr::CreateImplicit(Context, V.data(), V.size()));
 }
 
+static bool typeListMatches(FunctionDecl *FD,
+const clang::Sema::SymbolLabel &Label) {
+  assert(Label.TypeList.has_value());
+  if (FD->getNumParams() != Label.TypeList->size()) {
+return false;
+  }
+
+  // Check if arguments match.
+  for (unsigned i = 0; i != FD->getNumParams(); ++i) {
+const ParmVarDecl *PVD = FD->getParamDecl(i);
+QualType ParmType = PVD->getOriginalType().getCanonicalType();

perry-ca wrote:

@efriedma-quic I've found a problem related to this comment.  If I have a 
pragma like:
```cpp
void fd6(int (*)()) {}
#pragma export (fd6(int (*)()))
```
I noticed that the type chain for the function arguments when I parse them on 
the pragma has the ParenType.  eg:
```
PointerType 0xc7957d5eeb0 'int (*)(void)'
`-ParenType 0xc7957d5ee80 'int (void)' sugar
  `-FunctionProtoType 0xc7957d5eb90 'int (void)' cdecl
`-BuiltinType 0xc7957d2e570 'int'
```
This results in a type mismatch when I do the QualType compare in this code.  
Any idea on how to solve this?  Thanks


https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-13 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> I did consider these to be the same feature (two ways to set the same 
> information). If it's easier for reviewing I can look into splitting the PR.

I don't insist on a split, FWIW.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-12 Thread Sean Perry via cfe-commits


@@ -1273,6 +1273,168 @@ void 
Sema::AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD) {
 FD->addAttr(NoBuiltinAttr::CreateImplicit(Context, V.data(), V.size()));
 }
 
+static bool typeListMatches(FunctionDecl *FD,
+const clang::Sema::SymbolLabel &Label) {
+  assert(Label.TypeList.has_value());
+  if (FD->getNumParams() != Label.TypeList->size()) {
+return false;
+  }
+
+  // Check if arguments match.
+  for (unsigned i = 0; i != FD->getNumParams(); ++i) {
+const ParmVarDecl *PVD = FD->getParamDecl(i);
+QualType ParmType = PVD->getOriginalType().getCanonicalType();

perry-ca wrote:

Good catch.  This code does work for a case like:
```
void func(int []);
#pragma export(func(int[]))
```
but not for:
```
void func(int []);
#pragma export(func(int*))
```
(or vice versa)

The later case should work.  I'll add code to use `getType()` and then to decay 
the types.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-12 Thread Sean Perry via cfe-commits


@@ -5722,6 +5723,7 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D) 
{
 
   TypeSourceInfo *ReturnTypeInfo = nullptr;
   QualType T = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo);
+  fprintf(stderr, "SDP: === GetTypeForDeclarator\n"); T->dump(); 
fprintf(stderr, "SDP: === GetTypeForDeclarator\n");

perry-ca wrote:

yeah.  I merged in the latest code and the PR got updated.  I'll remove it.  
I'm sorting out a problem so not ready for a review again.  I wish I could put 
the PR in draft mode.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-12 Thread Sean Perry via cfe-commits


@@ -1906,6 +1906,36 @@ class Sema final : public SemaBase {
   ActOnPragmaMSFunction(SourceLocation Loc,
 const llvm::SmallVectorImpl &NoBuiltins);
 
+  /// A label from a C++ #pragma export, for a symbol that we
+  /// haven't seen the declaration for yet. The TypeList is the argument list
+  /// the function must match if HasTypeList is true.
+  struct SymbolLabel {
+std::optional> TypeList;
+StringRef MappedName;
+SourceLocation NameLoc;
+bool HasTypeList;
+Qualifiers CVQual;
+  };
+
+  typedef SmallVector PendingSymbolOverloads;
+  typedef llvm::DenseMap
+  SymbolNames;
+  SymbolNames PendingExportNames;
+
+  FunctionDecl *tryFunctionLookUp(NestedNameSpecifier *NestedName,

perry-ca wrote:

This is used by another pragma I'm going to upstream next.  This isn't used by 
pragma export but it is used by other pragmas we'll upstream after this one.  I 
missed this when removing all of that code and can remove it for now if you 
wish.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-12 Thread Sean Perry via cfe-commits


@@ -1906,6 +1906,36 @@ class Sema final : public SemaBase {
   ActOnPragmaMSFunction(SourceLocation Loc,
 const llvm::SmallVectorImpl &NoBuiltins);
 
+  /// A label from a C++ #pragma export, for a symbol that we
+  /// haven't seen the declaration for yet. The TypeList is the argument list
+  /// the function must match if HasTypeList is true.
+  struct SymbolLabel {
+std::optional> TypeList;
+StringRef MappedName;
+SourceLocation NameLoc;
+bool HasTypeList;
+Qualifiers CVQual;
+  };
+
+  typedef SmallVector PendingSymbolOverloads;
+  typedef llvm::DenseMap
+  SymbolNames;
+  SymbolNames PendingExportNames;
+
+  FunctionDecl *tryFunctionLookUp(NestedNameSpecifier *NestedName,
+  SourceLocation NameLoc);
+
+  /// trySymbolLookUp try to look up a decl matching the nested specifier
+  /// with optional type list.
+  NamedDecl *trySymbolLookUp(NestedNameSpecifier *NestedName,

perry-ca wrote:

Sure.  I'll pick a name the works with the other pragmas too.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-12 Thread Sean Perry via cfe-commits

https://github.com/perry-ca edited 
https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -2002,6 +2014,9 @@ class Declarator {
   /// this declarator as a parameter pack.
   SourceLocation EllipsisLoc;
 
+  /// The source location of the _Export keyword on this declarator

AaronBallman wrote:

```suggestion
  /// The source location of the _Export keyword on this declarator.
```

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -1401,6 +1417,164 @@ bool Parser::HandlePragmaMSAllocText(StringRef 
PragmaName,
   return true;
 }
 
+NestedNameSpecifier *Parser::zOSParseIdentifier(StringRef PragmaName,
+IdentifierInfo *IdentName) {

AaronBallman wrote:

```suggestion
const IdentifierInfo 
*IdentName) {
```

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -1956,6 +1964,10 @@ class Declarator {
   LLVM_PREFERRED_TYPE(bool)
   unsigned InlineStorageUsed : 1;
 
+  /// Indicates whether this is set as _Export

AaronBallman wrote:

```suggestion
  /// Indicates whether this is set as _Export.
```

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -7502,6 +7502,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the _Export keyword with a function name or external variable to declare

AaronBallman wrote:

```suggestion
Use the ``_Export`` keyword on a function or external variable to declare
```

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,40 @@
+// REQUIRES: systemz-registered-target
+// RUN: %clang_cc1 %s -emit-llvm -fzos-extensions -triple s390x-none-zos 
-fvisibility=hidden -verify -o - | FileCheck %s
+
+// Testing missing declarations.
+#pragma export(d0) // expected-warning{{failed to resolve '#pragma export' to 
a declaration}}
+#pragma export(f9) // expected-warning{{failed to resolve '#pragma export' to 
a declaration}}
+
+// Testing pragma export after decl.
+void f0(void) {}
+static void sf0(void) {} // expected-warning{{#pragma export is applicable to 
symbols with external linkage only; not applied to 'sf0'}}
+int v0;
+static int s0; // expected-warning{{#pragma export is applicable to symbols 
with external linkage only; not applied to 's0'}}
+#pragma export(f0)
+#pragma export(sf0)
+#pragma export(v0)
+#pragma export(s0)
+
+// Testing pragma export before decl.
+#pragma export(f1)
+#pragma export(sf1)
+#pragma export(v1)
+#pragma export(s1)
+void f1(void) {}
+static void sf1(void) {} // expected-warning{{#pragma export is applicable to 
symbols with external linkage only; not applied to 'sf1'}}
+int v1;
+static int s1; // expected-warning{{#pragma export is applicable to symbols 
with external linkage only; not applied to 's1'}}

AaronBallman wrote:

These look like they should be testing in Sema rather than in CodeGen.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,5 @@
+// REQUIRES: systemz-registered-target

AaronBallman wrote:

This question is still open, but also, these look like they should be tested in 
Sema and not CodeGen. Further, it's missing the `-verify` line so these 
expected diagnostics aren't actually being tested.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,12 @@
+// REQUIRES: systemz-registered-target
+// RUN: %clang_cc1 -emit-llvm -triple s390x-none-zos -fvisibility=hidden %s -o 
- | FileCheck %s
+// expected-no-diagnostics

AaronBallman wrote:

There's no `-verify` line, so this comment doesn't do anything and can be 
removed.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -1401,6 +1417,164 @@ bool Parser::HandlePragmaMSAllocText(StringRef 
PragmaName,
   return true;
 }
 
+NestedNameSpecifier *Parser::zOSParseIdentifier(StringRef PragmaName,
+IdentifierInfo *IdentName) {
+  NestedNameSpecifier *NestedId = nullptr;
+  if (Tok.is(tok::coloncolon)) {
+NestedId = NestedNameSpecifier::Create(Actions.Context, IdentName);
+  } else if (Actions.CurContext->isNamespace()) {
+auto *NS = cast(Actions.CurContext);
+NestedId =
+NestedNameSpecifier::Create(Actions.Context, NS->getIdentifier());
+NestedId =
+NestedNameSpecifier::Create(Actions.Context, NestedId, IdentName);
+PP.Lex(Tok);
+  } else {
+NestedId = NestedNameSpecifier::Create(Actions.Context, IdentName);
+PP.Lex(Tok);
+  }
+  while (Tok.is(tok::coloncolon)) {
+PP.Lex(Tok);
+IdentName = Tok.getIdentifierInfo();

AaronBallman wrote:

```suggestion
IdentifierInfo *II = Tok.getIdentifierInfo();
```
Better to use a local variable instead of reusing the parameter.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman requested changes to this pull request.

Thanks for this! Some things that are missing:

* a release note in `clang/docs/ReleaseNotes.rst`
* Parsing and Sema tests

Also, it looks like these are two separate (but related) features, one for the 
pragma and another for `_Export`. Is that the case? If so, they should be split 
into separate PRs.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -7502,6 +7502,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the _Export keyword with a function name or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the _Export
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function anthony, if you define the function in the
+translation unit. The _Export keyword must immediately precede the object name.
+If you apply the _Export keyword to a class, the compiler automatically exports
+all static data members and member functions of the class. However, if you want
+it to apply to individual class members, then you must apply it to each member
+that can be referenced.

AaronBallman wrote:

```suggestion
This statement exports the function ``anthony``, if you define the function in 
the
translation unit. The ``_Export`` keyword must immediately precede the 
declaration name.
If you apply the ``_Export`` keyword to a class, the compiler automatically 
exports
all static data members and member functions of the class. However, if you want
it to apply to individual class members, then you must apply it to each member
that can be referenced.
```

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -2110,6 +2126,18 @@ class Declarator {
   Range.setEnd(SR.getEnd());
   }
 
+  /// Set this declarator as _Export

AaronBallman wrote:

```suggestion
  /// Set this declarator as _Export.
```
I'll stop commenting on these now, can you take a pass over all the new 
comments you've added and ensure they have appropriate trailing punctuation?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,12 @@
+// REQUIRES: systemz-registered-target
+// RUN: %clang_cc1 -x c++ -emit-llvm -triple s390x-none-zos 
-fvisibility=hidden %s -o - | FileCheck %s
+// expected-no-diagnostics

AaronBallman wrote:

There's no `-verify` line, so this comment doesn't do anything and can be 
removed.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -4250,6 +4250,7 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   // The TypeSourceInfo that this function returns will not be a null type.
   // If there is an error, this function will fill in a dummy type as fallback.
   QualType T = declSpecType;
+  fprintf(stderr, "SDP: === GetFullTypeForDeclarator\n"); T->dump(); 
fprintf(stderr, "SDP: === GetFullTypeForDeclarator\n");

AaronBallman wrote:

Debugging code?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2025-03-07 Thread Sean Perry via cfe-commits

https://github.com/perry-ca updated 
https://github.com/llvm/llvm-project/pull/111035

>From e8d355c9cd165e0a255bbbfb5b0126cf7b1461a6 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Wed, 2 Oct 2024 12:56:43 -0500
Subject: [PATCH 1/9] initial work for pragma export & _Export keyword

---
 clang/include/clang/AST/ASTConsumer.h |   3 +
 clang/include/clang/Basic/Attr.td |   6 +
 clang/include/clang/Basic/AttrDocs.td |  21 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/Basic/TokenKinds.def  |   5 +
 clang/include/clang/Parse/Parser.h|  13 ++
 clang/include/clang/Sema/DeclSpec.h   |  31 ++-
 clang/include/clang/Sema/Sema.h   |  30 +++
 clang/lib/CodeGen/BackendConsumer.h   |   1 +
 clang/lib/CodeGen/CodeGenAction.cpp   |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  15 ++
 clang/lib/CodeGen/CodeGenModule.h |   2 +
 clang/lib/CodeGen/ModuleBuilder.cpp   |   6 +-
 clang/lib/Driver/ToolChains/ZOS.cpp   |  12 +-
 clang/lib/Parse/ParseDecl.cpp |  18 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |   6 +
 clang/lib/Parse/ParsePragma.cpp   | 208 ++
 clang/lib/Parse/Parser.cpp|   3 +
 clang/lib/Sema/DeclSpec.cpp   |   6 +
 clang/lib/Sema/Sema.cpp   |  21 ++
 clang/lib/Sema/SemaAttr.cpp   | 162 ++
 clang/lib/Sema/SemaDecl.cpp   |  13 ++
 clang/test/CodeGen/attr-export-failing.cpp|   4 +
 clang/test/CodeGen/attr-export.cpp|  51 +
 clang/test/CodeGen/pragma-export.c|  39 
 clang/test/CodeGen/pragma-export.cpp  |  82 +++
 clang/test/CodeGen/zos-pragmas.c  |  11 +
 clang/test/CodeGen/zos-pragmas.cpp|  11 +
 28 files changed, 784 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-export-failing.cpp
 create mode 100644 clang/test/CodeGen/attr-export.cpp
 create mode 100644 clang/test/CodeGen/pragma-export.c
 create mode 100644 clang/test/CodeGen/pragma-export.cpp
 create mode 100644 clang/test/CodeGen/zos-pragmas.c
 create mode 100644 clang/test/CodeGen/zos-pragmas.cpp

diff --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index 447f2592d2359..b15d53e700c67 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -108,6 +108,9 @@ class ASTConsumer {
   /// completed.
   virtual void CompleteExternalDeclaration(DeclaratorDecl *D) {}
 
+  /// CompletePragmaExport - complete #pragma export statements.
+  virtual void CompletePragmaExport(Decl *D) {}
+
   /// Callback invoked when an MSInheritanceAttr has been attached to a
   /// CXXRecordDecl.
   virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fbcbf0ed41641..884c4147cf128 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4520,6 +4520,12 @@ def ReleaseHandle : InheritableParamAttr {
   let Documentation = [ReleaseHandleDocs];
 }
 
+def zOSExport : InheritableAttr {
+  let Spellings = [CustomKeyword<"_Export">];
+  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
+  let Documentation = [zOSExportDocs];
+}
+
 def UnsafeBufferUsage : InheritableAttr {
   let Spellings = [Clang<"unsafe_buffer_usage">];
   let Subjects = SubjectList<[Function, Field]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 53d88482698f0..bf56fa6ad7162 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6863,6 +6863,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the _Export keyword with a function name or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the _Export
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function anthony, if you define the function in the
+translation unit. The _Export keyword must immediately precede the object name.
+If you apply the _Export keyword to a class, the compiler automatically exports
+all static data members and member functions of the class. However, if you want
+it to apply to individual class members, then you must apply it to each member
+that can be referenced.
+  }];
+}
+
 def UnsafeBufferUsageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64e6d0407b0ce..09842ed02efd4 100644
--- a/clang/inc

[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-12-12 Thread Sean Perry via cfe-commits

https://github.com/perry-ca updated 
https://github.com/llvm/llvm-project/pull/111035

>From e8d355c9cd165e0a255bbbfb5b0126cf7b1461a6 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Wed, 2 Oct 2024 12:56:43 -0500
Subject: [PATCH 1/9] initial work for pragma export & _Export keyword

---
 clang/include/clang/AST/ASTConsumer.h |   3 +
 clang/include/clang/Basic/Attr.td |   6 +
 clang/include/clang/Basic/AttrDocs.td |  21 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/Basic/TokenKinds.def  |   5 +
 clang/include/clang/Parse/Parser.h|  13 ++
 clang/include/clang/Sema/DeclSpec.h   |  31 ++-
 clang/include/clang/Sema/Sema.h   |  30 +++
 clang/lib/CodeGen/BackendConsumer.h   |   1 +
 clang/lib/CodeGen/CodeGenAction.cpp   |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  15 ++
 clang/lib/CodeGen/CodeGenModule.h |   2 +
 clang/lib/CodeGen/ModuleBuilder.cpp   |   6 +-
 clang/lib/Driver/ToolChains/ZOS.cpp   |  12 +-
 clang/lib/Parse/ParseDecl.cpp |  18 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |   6 +
 clang/lib/Parse/ParsePragma.cpp   | 208 ++
 clang/lib/Parse/Parser.cpp|   3 +
 clang/lib/Sema/DeclSpec.cpp   |   6 +
 clang/lib/Sema/Sema.cpp   |  21 ++
 clang/lib/Sema/SemaAttr.cpp   | 162 ++
 clang/lib/Sema/SemaDecl.cpp   |  13 ++
 clang/test/CodeGen/attr-export-failing.cpp|   4 +
 clang/test/CodeGen/attr-export.cpp|  51 +
 clang/test/CodeGen/pragma-export.c|  39 
 clang/test/CodeGen/pragma-export.cpp  |  82 +++
 clang/test/CodeGen/zos-pragmas.c  |  11 +
 clang/test/CodeGen/zos-pragmas.cpp|  11 +
 28 files changed, 784 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-export-failing.cpp
 create mode 100644 clang/test/CodeGen/attr-export.cpp
 create mode 100644 clang/test/CodeGen/pragma-export.c
 create mode 100644 clang/test/CodeGen/pragma-export.cpp
 create mode 100644 clang/test/CodeGen/zos-pragmas.c
 create mode 100644 clang/test/CodeGen/zos-pragmas.cpp

diff --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index 447f2592d23595..b15d53e700c679 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -108,6 +108,9 @@ class ASTConsumer {
   /// completed.
   virtual void CompleteExternalDeclaration(DeclaratorDecl *D) {}
 
+  /// CompletePragmaExport - complete #pragma export statements.
+  virtual void CompletePragmaExport(Decl *D) {}
+
   /// Callback invoked when an MSInheritanceAttr has been attached to a
   /// CXXRecordDecl.
   virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fbcbf0ed416416..884c4147cf1285 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4520,6 +4520,12 @@ def ReleaseHandle : InheritableParamAttr {
   let Documentation = [ReleaseHandleDocs];
 }
 
+def zOSExport : InheritableAttr {
+  let Spellings = [CustomKeyword<"_Export">];
+  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
+  let Documentation = [zOSExportDocs];
+}
+
 def UnsafeBufferUsage : InheritableAttr {
   let Spellings = [Clang<"unsafe_buffer_usage">];
   let Subjects = SubjectList<[Function, Field]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 53d88482698f00..bf56fa6ad7162f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6863,6 +6863,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the _Export keyword with a function name or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the _Export
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function anthony, if you define the function in the
+translation unit. The _Export keyword must immediately precede the object name.
+If you apply the _Export keyword to a class, the compiler automatically exports
+all static data members and member functions of the class. However, if you want
+it to apply to individual class members, then you must apply it to each member
+that can be referenced.
+  }];
+}
+
 def UnsafeBufferUsageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64e6d0407b0ce3..09842ed02efd4b 100644
--- a/c

[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-11-25 Thread Sean Perry via cfe-commits

https://github.com/perry-ca updated 
https://github.com/llvm/llvm-project/pull/111035

>From e8d355c9cd165e0a255bbbfb5b0126cf7b1461a6 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Wed, 2 Oct 2024 12:56:43 -0500
Subject: [PATCH 1/9] initial work for pragma export & _Export keyword

---
 clang/include/clang/AST/ASTConsumer.h |   3 +
 clang/include/clang/Basic/Attr.td |   6 +
 clang/include/clang/Basic/AttrDocs.td |  21 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/Basic/TokenKinds.def  |   5 +
 clang/include/clang/Parse/Parser.h|  13 ++
 clang/include/clang/Sema/DeclSpec.h   |  31 ++-
 clang/include/clang/Sema/Sema.h   |  30 +++
 clang/lib/CodeGen/BackendConsumer.h   |   1 +
 clang/lib/CodeGen/CodeGenAction.cpp   |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  15 ++
 clang/lib/CodeGen/CodeGenModule.h |   2 +
 clang/lib/CodeGen/ModuleBuilder.cpp   |   6 +-
 clang/lib/Driver/ToolChains/ZOS.cpp   |  12 +-
 clang/lib/Parse/ParseDecl.cpp |  18 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |   6 +
 clang/lib/Parse/ParsePragma.cpp   | 208 ++
 clang/lib/Parse/Parser.cpp|   3 +
 clang/lib/Sema/DeclSpec.cpp   |   6 +
 clang/lib/Sema/Sema.cpp   |  21 ++
 clang/lib/Sema/SemaAttr.cpp   | 162 ++
 clang/lib/Sema/SemaDecl.cpp   |  13 ++
 clang/test/CodeGen/attr-export-failing.cpp|   4 +
 clang/test/CodeGen/attr-export.cpp|  51 +
 clang/test/CodeGen/pragma-export.c|  39 
 clang/test/CodeGen/pragma-export.cpp  |  82 +++
 clang/test/CodeGen/zos-pragmas.c  |  11 +
 clang/test/CodeGen/zos-pragmas.cpp|  11 +
 28 files changed, 784 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-export-failing.cpp
 create mode 100644 clang/test/CodeGen/attr-export.cpp
 create mode 100644 clang/test/CodeGen/pragma-export.c
 create mode 100644 clang/test/CodeGen/pragma-export.cpp
 create mode 100644 clang/test/CodeGen/zos-pragmas.c
 create mode 100644 clang/test/CodeGen/zos-pragmas.cpp

diff --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index 447f2592d23595..b15d53e700c679 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -108,6 +108,9 @@ class ASTConsumer {
   /// completed.
   virtual void CompleteExternalDeclaration(DeclaratorDecl *D) {}
 
+  /// CompletePragmaExport - complete #pragma export statements.
+  virtual void CompletePragmaExport(Decl *D) {}
+
   /// Callback invoked when an MSInheritanceAttr has been attached to a
   /// CXXRecordDecl.
   virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fbcbf0ed416416..884c4147cf1285 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4520,6 +4520,12 @@ def ReleaseHandle : InheritableParamAttr {
   let Documentation = [ReleaseHandleDocs];
 }
 
+def zOSExport : InheritableAttr {
+  let Spellings = [CustomKeyword<"_Export">];
+  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
+  let Documentation = [zOSExportDocs];
+}
+
 def UnsafeBufferUsage : InheritableAttr {
   let Spellings = [Clang<"unsafe_buffer_usage">];
   let Subjects = SubjectList<[Function, Field]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 53d88482698f00..bf56fa6ad7162f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6863,6 +6863,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the _Export keyword with a function name or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the _Export
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function anthony, if you define the function in the
+translation unit. The _Export keyword must immediately precede the object name.
+If you apply the _Export keyword to a class, the compiler automatically exports
+all static data members and member functions of the class. However, if you want
+it to apply to individual class members, then you must apply it to each member
+that can be referenced.
+  }];
+}
+
 def UnsafeBufferUsageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64e6d0407b0ce3..09842ed02efd4b 100644
--- a/c

[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-07 Thread Sean Perry via cfe-commits

https://github.com/perry-ca updated 
https://github.com/llvm/llvm-project/pull/111035

>From e8d355c9cd165e0a255bbbfb5b0126cf7b1461a6 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Wed, 2 Oct 2024 12:56:43 -0500
Subject: [PATCH 1/7] initial work for pragma export & _Export keyword

---
 clang/include/clang/AST/ASTConsumer.h |   3 +
 clang/include/clang/Basic/Attr.td |   6 +
 clang/include/clang/Basic/AttrDocs.td |  21 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/Basic/TokenKinds.def  |   5 +
 clang/include/clang/Parse/Parser.h|  13 ++
 clang/include/clang/Sema/DeclSpec.h   |  31 ++-
 clang/include/clang/Sema/Sema.h   |  30 +++
 clang/lib/CodeGen/BackendConsumer.h   |   1 +
 clang/lib/CodeGen/CodeGenAction.cpp   |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  15 ++
 clang/lib/CodeGen/CodeGenModule.h |   2 +
 clang/lib/CodeGen/ModuleBuilder.cpp   |   6 +-
 clang/lib/Driver/ToolChains/ZOS.cpp   |  12 +-
 clang/lib/Parse/ParseDecl.cpp |  18 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |   6 +
 clang/lib/Parse/ParsePragma.cpp   | 208 ++
 clang/lib/Parse/Parser.cpp|   3 +
 clang/lib/Sema/DeclSpec.cpp   |   6 +
 clang/lib/Sema/Sema.cpp   |  21 ++
 clang/lib/Sema/SemaAttr.cpp   | 162 ++
 clang/lib/Sema/SemaDecl.cpp   |  13 ++
 clang/test/CodeGen/attr-export-failing.cpp|   4 +
 clang/test/CodeGen/attr-export.cpp|  51 +
 clang/test/CodeGen/pragma-export.c|  39 
 clang/test/CodeGen/pragma-export.cpp  |  82 +++
 clang/test/CodeGen/zos-pragmas.c  |  11 +
 clang/test/CodeGen/zos-pragmas.cpp|  11 +
 28 files changed, 784 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-export-failing.cpp
 create mode 100644 clang/test/CodeGen/attr-export.cpp
 create mode 100644 clang/test/CodeGen/pragma-export.c
 create mode 100644 clang/test/CodeGen/pragma-export.cpp
 create mode 100644 clang/test/CodeGen/zos-pragmas.c
 create mode 100644 clang/test/CodeGen/zos-pragmas.cpp

diff --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index 447f2592d23595..b15d53e700c679 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -108,6 +108,9 @@ class ASTConsumer {
   /// completed.
   virtual void CompleteExternalDeclaration(DeclaratorDecl *D) {}
 
+  /// CompletePragmaExport - complete #pragma export statements.
+  virtual void CompletePragmaExport(Decl *D) {}
+
   /// Callback invoked when an MSInheritanceAttr has been attached to a
   /// CXXRecordDecl.
   virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fbcbf0ed416416..884c4147cf1285 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4520,6 +4520,12 @@ def ReleaseHandle : InheritableParamAttr {
   let Documentation = [ReleaseHandleDocs];
 }
 
+def zOSExport : InheritableAttr {
+  let Spellings = [CustomKeyword<"_Export">];
+  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
+  let Documentation = [zOSExportDocs];
+}
+
 def UnsafeBufferUsage : InheritableAttr {
   let Spellings = [Clang<"unsafe_buffer_usage">];
   let Subjects = SubjectList<[Function, Field]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 53d88482698f00..bf56fa6ad7162f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6863,6 +6863,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the _Export keyword with a function name or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the _Export
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function anthony, if you define the function in the
+translation unit. The _Export keyword must immediately precede the object name.
+If you apply the _Export keyword to a class, the compiler automatically exports
+all static data members and member functions of the class. However, if you want
+it to apply to individual class members, then you must apply it to each member
+that can be referenced.
+  }];
+}
+
 def UnsafeBufferUsageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64e6d0407b0ce3..09842ed02efd4b 100644
--- a/c

[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-07 Thread Eli Friedman via cfe-commits


@@ -1906,6 +1906,36 @@ class Sema final : public SemaBase {
   ActOnPragmaMSFunction(SourceLocation Loc,
 const llvm::SmallVectorImpl &NoBuiltins);
 
+  /// A label from a C++ #pragma export, for a symbol that we
+  /// haven't seen the declaration for yet. The TypeList is the argument list
+  /// the function must match if HasTypeList is true.
+  struct SymbolLabel {
+std::optional> TypeList;
+StringRef MappedName;
+SourceLocation NameLoc;
+bool HasTypeList;
+Qualifiers CVQual;
+  };
+
+  typedef SmallVector PendingSymbolOverloads;
+  typedef llvm::DenseMap
+  SymbolNames;
+  SymbolNames PendingExportNames;
+
+  FunctionDecl *tryFunctionLookUp(NestedNameSpecifier *NestedName,

efriedma-quic wrote:

tryFunctionLookUp is dead code?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-07 Thread Eli Friedman via cfe-commits


@@ -5087,6 +5087,19 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, 
AccessSpecifier AS,
   assert(EllipsisLoc.isInvalid() &&
  "Friend ellipsis but not friend-specified?");
 
+  if (DS.isExportSpecified()) {
+VisibilityAttr *existingAttr = TagD->getAttr();
+if (existingAttr) {
+  VisibilityAttr::VisibilityType existingValue =
+  existingAttr->getVisibility();
+  if (existingValue != VisibilityAttr::Default)
+Diag(DS.getExportSpecLoc(), diag::err_mismatched_visibility);
+} else {
+  Tag->addAttr(

efriedma-quic wrote:

Not sure adding implicit attributes is necessary?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-07 Thread Eli Friedman via cfe-commits


@@ -0,0 +1,5 @@
+// REQUIRES: systemz-registered-target

efriedma-quic wrote:

Do these tests actually require systemz-registered-target?

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-07 Thread Eli Friedman via cfe-commits


@@ -1273,6 +1273,168 @@ void 
Sema::AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD) {
 FD->addAttr(NoBuiltinAttr::CreateImplicit(Context, V.data(), V.size()));
 }
 
+static bool typeListMatches(FunctionDecl *FD,
+const clang::Sema::SymbolLabel &Label) {
+  assert(Label.TypeList.has_value());
+  if (FD->getNumParams() != Label.TypeList->size()) {
+return false;
+  }
+
+  // Check if arguments match.
+  for (unsigned i = 0; i != FD->getNumParams(); ++i) {
+const ParmVarDecl *PVD = FD->getParamDecl(i);
+QualType ParmType = PVD->getOriginalType().getCanonicalType();

efriedma-quic wrote:

Using getOriginalType() here seems weird; does that really produce the result 
you want?  Please add tests with function parameters that decay (array/function 
types).

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-07 Thread Eli Friedman via cfe-commits


@@ -1906,6 +1906,36 @@ class Sema final : public SemaBase {
   ActOnPragmaMSFunction(SourceLocation Loc,
 const llvm::SmallVectorImpl &NoBuiltins);
 
+  /// A label from a C++ #pragma export, for a symbol that we
+  /// haven't seen the declaration for yet. The TypeList is the argument list
+  /// the function must match if HasTypeList is true.
+  struct SymbolLabel {
+std::optional> TypeList;
+StringRef MappedName;
+SourceLocation NameLoc;
+bool HasTypeList;
+Qualifiers CVQual;
+  };
+
+  typedef SmallVector PendingSymbolOverloads;
+  typedef llvm::DenseMap
+  SymbolNames;
+  SymbolNames PendingExportNames;
+
+  FunctionDecl *tryFunctionLookUp(NestedNameSpecifier *NestedName,
+  SourceLocation NameLoc);
+
+  /// trySymbolLookUp try to look up a decl matching the nested specifier
+  /// with optional type list.
+  NamedDecl *trySymbolLookUp(NestedNameSpecifier *NestedName,

efriedma-quic wrote:

Please name this so it's clear it's specifically the lookup algorithm for 
pragma export.

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-07 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SystemZ][z/OS] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-04 Thread Sean Perry via cfe-commits

https://github.com/perry-ca edited 
https://github.com/llvm/llvm-project/pull/111035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits