[Chapel Merge] Improve extern blocks to handle extern unions and

Branch: refs/heads/master
Revision: e9aa84d
Author: mppf
Log Message:

Merge pull request #17409 from mppf/extern-block-union-anon

Improve extern blocks to handle extern unions and anonymous unions

@souris-dev on Gitter was asking about inter-operating with C types like this:

typedef struct someStruct {
    // Anonymous union
    union {
        char alpha;
        int num;
    } u;
} someStruct;

This PR gets this example case working with --llvm (but unfortunately I
don't see a way to get the anonymous union working with the C backend).

To do so, this PR:

  • refactors and simplifies legalizeName. Now legalizeName is an
    operation on strings but legalizeSymbolName applies to Symbols.
  • adds the idea of extern unions to the compiler, including with a query
    in ChapelBase that can be used in ChapelIO. These are just unions
    marked FLAG_EXTERN.
  • adjusts the clang integration code to handle anonymous record/unions
    by generating a name for them based upon their source location. This
    works to let the Chapel compiler have a name for these but doesn't
    work with the C backend when the Chapel compiler tries to create a
    named reference type for these.
  • resolved a problem with TBAA metadata generation for types declared as
    extern record but that are actually unions.

While updating some extern block support, this PR also fixes problems
with flexible array members under --baseline. There the problems were
that the compiler was trying to get a reference to the flexible array
member field but such a field is sortof already a reference (it is a C
pointer that refers to the 0th element). So this PR adjusts the field
accessor functions to return by value for such fields. It adds a flag to
mark these fields so that the field accessor can be built appropriately.

Resolves #17375

Future work:

  • get it also working if the anonymous union is unnamed (i.e. remove the
    u in the above) -- issue #17748.
  • do we really want to declare extern unions with extern record or
    could we use extern union instead? #17749
  • [x] full local testing

Reviewed by @e-kayrakli - thanks!

Modified Files:
A test/extern/ferguson/externblock/extern-record-containing-anon-union.chpl

A test/extern/ferguson/externblock/extern-record-containing-anon-union.compopts
A test/extern/ferguson/externblock/extern-record-containing-anon-union.good
A test/extern/ferguson/externblock/extern-record-containing-anon-unnamed-union.chpl
A test/extern/ferguson/externblock/extern-record-containing-anon-unnamed-union.future
A test/extern/ferguson/externblock/extern-record-containing-anon-unnamed-union.good
A test/extern/ferguson/externblock/extern-record-containing-union.chpl
A test/extern/ferguson/externblock/extern-record-containing-union.good
A test/extern/unions/externAnonUnnamedUnionC.chpl
A test/extern/unions/externAnonUnnamedUnionC.compopts
A test/extern/unions/externAnonUnnamedUnionC.good
A test/extern/unions/externAnonUnnamedUnionLLVM.chpl
A test/extern/unions/externAnonUnnamedUnionLLVM.compopts
A test/extern/unions/externAnonUnnamedUnionLLVM.future
A test/extern/unions/externAnonUnnamedUnionLLVM.good
A test/extern/unions/externAnonUnnamedUnionLLVM.skipif
R test/extern/unions.skipif
R test/extern/unions/COMPOPTS
M compiler/AST/checkAST.cpp
M compiler/AST/primitive.cpp
M compiler/codegen/codegen.cpp
M compiler/codegen/expr.cpp
M compiler/codegen/symbol.cpp
M compiler/include/clangUtil.h
M compiler/include/codegen.h
M compiler/include/flags_list.h
M compiler/include/primitive_list.h
M compiler/llvm/clangUtil.cpp
M compiler/passes/buildDefaultFunctions.cpp
M compiler/passes/externCResolve.cpp
M compiler/resolution/preFold.cpp
M modules/internal/ChapelBase.chpl
M modules/standard/ChapelIO.chpl
M test/extern/unions/unions.h

Compare: https://github.com/chapel-lang/chapel/compare/7fc0776a0285...e9aa84d8f388