[all-commits] [llvm/llvm-project] d02757: [Modules] Fix using `va_list` with modules and a p...

Volodymyr Sapsai via All-commits all-commits at lists.llvm.org
Fri Aug 2 08:33:10 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d02757ce9ee3b439ba8cb7a67676e725a22a8651
      https://github.com/llvm/llvm-project/commit/d02757ce9ee3b439ba8cb7a67676e725a22a8651
  Author: Volodymyr Sapsai <421892+vsapsai at users.noreply.github.com>
  Date:   2024-08-02 (Fri, 02 Aug 2024)

  Changed paths:
    M clang/lib/Sema/Sema.cpp
    A clang/test/Modules/builtin-vararg.c

  Log Message:
  -----------
  [Modules] Fix using `va_list` with modules and a precompiled header. (#100837)

Fix the false warning
> incompatible pointer types passing 'va_list' (aka '__builtin_va_list')
to parameter of type 'struct __va_list_tag *'
[-Wincompatible-pointer-types]

The warning is wrong because both in the function declaration and at the
call site we are using `va_list`.

When we call `ASTContext::getBuiltinVaListDecl` at a specific moment, we
end up re-entering this function which causes creating 2 instances of
`BuiltinVaListDecl` and 2 instances of `VaListTagDecl` but the stored
instances are unrelated to each other because of the call sequence like

    getBuiltinVaListDecl
      CreateX86_64ABIBuiltinVaListDecl
        VaListTagDecl = TagA
        indirectly call getBuiltinVaListDecl
          CreateX86_64ABIBuiltinVaListDecl
            VaListTagDecl = TagB
          BuiltinVaListDecl = ListB
      BuiltinVaListDecl = ListA

Now we have `BuiltinVaListDecl == ListA` and `VaListTagDecl == TagB`.

For x86_64 '__builtin_va_list' and 'struct __va_list_tag *' are
compatible because '__builtin_va_list' == '__va_list_tag[1]'. But
because we have unrelated decls for VaListDecl and VaListTagDecl the
types are considered incompatible as we are comparing type pointers.

Fix the error by creating `BuiltinVaListDecl` before
`ASTReader::InitializeSema`, so that during
`ASTContext::getBuiltinVaListDecl` ASTReader doesn't try to de-serialize
'__builtin_va_list' and to call `ASTContext::getBuiltinVaListDecl`
again.

rdar://130947515



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