r301846 - Fix initial diagnostic state setup for an explicit module with no diagnostic pragmas.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue May 2 08:52:58 PDT 2017


On 1 May 2017 10:29 pm, "NAKAMURA Takumi" <geek4civic at gmail.com> wrote:

It didn't pass for targeting *-win32, since MicrosoftRecordLayoutBuilder
doesn't have ability of -Wpadded.
Tweaked in r301898.


Thank you!

I guess other diag would be available here but I have no good idea.

On Tue, May 2, 2017 at 7:23 AM Richard Smith via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: rsmith
> Date: Mon May  1 17:10:47 2017
> New Revision: 301846
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301846&view=rev
> Log:
> Fix initial diagnostic state setup for an explicit module with no
> diagnostic pragmas.
>
> If a file has no diagnostic pragmas, we build its diagnostic state lazily,
> but
> in this case we never set up the root state to be the diagnostic state in
> which
> the module was originally built, so the diagnostic flags for files in the
> module with no diagnostic pragmas were incorrectly based on the user of the
> module rather than the diagnostic state when the module was built.
>
> Added:
>     cfe/trunk/test/Modules/diag-flags.cpp
> Modified:
>     cfe/trunk/lib/Serialization/ASTReader.cpp
>     cfe/trunk/test/Modules/Inputs/module.map
>
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Serialization/ASTReader.cpp?rev=301846&r1=301845&r2=301846&view=diff
> ============================================================
> ==================
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon May  1 17:10:47 2017
> @@ -3765,6 +3765,13 @@ ASTReader::ASTReadResult ASTReader::Read
>        SourceMgr.getLoadedSLocEntryByID(Index);
>      }
>
> +    // Map the original source file ID into the ID space of the current
> +    // compilation.
> +    if (F.OriginalSourceFileID.isValid()) {
> +      F.OriginalSourceFileID = FileID::get(
> +          F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() -
> 1);
> +    }
> +
>      // Preload all the pending interesting identifiers by marking them
> out of
>      // date.
>      for (auto Offset : F.PreloadIdentifierOffsets) {
> @@ -3873,10 +3880,6 @@ ASTReader::ASTReadResult ASTReader::Read
>
>    ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule();
>    if (PrimaryModule.OriginalSourceFileID.isValid()) {
> -    PrimaryModule.OriginalSourceFileID
> -      = FileID::get(PrimaryModule.SLocEntryBaseID
> -                    + PrimaryModule.OriginalSourceFileID.getOpaqueValue()
> - 1);
> -
>      // If this AST file is a precompiled preamble, then set the
>      // preamble file ID of the source manager to the file source file
>      // from which the preamble was built.
> @@ -5575,6 +5578,13 @@ void ASTReader::ReadPragmaDiagnosticMapp
>        FirstState = ReadDiagState(
>            F.isModule() ? DiagState() : *Diag.DiagStatesByLoc.
> CurDiagState,
>            SourceLocation(), F.isModule());
> +
> +      // For an explicit module, set up the root buffer of the module to
> start
> +      // with the initial diagnostic state of the module itself, to cover
> files
> +      // that contain no explicit transitions.
> +      if (F.isModule())
> +        Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID]
> +            .StateTransitions.push_back({FirstState, 0});
>      }
>
>      // Read the state transitions.
>
> Modified: cfe/trunk/test/Modules/Inputs/module.map
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> Modules/Inputs/module.map?rev=301846&r1=301845&r2=301846&view=diff
> ============================================================
> ==================
> --- cfe/trunk/test/Modules/Inputs/module.map (original)
> +++ cfe/trunk/test/Modules/Inputs/module.map Mon May  1 17:10:47 2017
> @@ -261,6 +261,10 @@ module config {
>    config_macros [exhaustive] WANT_FOO, WANT_BAR
>  }
>
> +module diag_flags {
> +  header "diag_flags.h"
> +}
> +
>  module diag_pragma {
>    header "diag_pragma.h"
>  }
>
> Added: cfe/trunk/test/Modules/diag-flags.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> Modules/diag-flags.cpp?rev=301846&view=auto
> ============================================================
> ==================
> --- cfe/trunk/test/Modules/diag-flags.cpp (added)
> +++ cfe/trunk/test/Modules/diag-flags.cpp Mon May  1 17:10:47 2017
> @@ -0,0 +1,22 @@
> +// RUN: rm -rf %t
> +//
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module
> -fmodules-cache-path=%t -fmodule-name=diag_flags -x c++
> %S/Inputs/module.map -fmodules-ts
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify
> -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify
> -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts -DIMPLICIT_FLAG
> -Werror=padded
> +//
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module
> -fmodule-name=diag_flags -x c++ %S/Inputs/module.map -fmodules-ts -o
> %t/explicit.pcm -Werror=string-plus-int -Wpadded
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify
> -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts -DEXPLICIT_FLAG
> -fmodule-file=%t/explicit.pcm
> +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify
> -fmodules-cache-path=%t -I %S/Inputs %s -fmodules-ts -DEXPLICIT_FLAG
> -fmodule-file=%t/explicit.pcm -Werror=padded
> +
> +import diag_flags;
> +
> +// Diagnostic flags from the module user make no difference to diagnostics
> +// emitted within the module when using an explicitly-loaded module.
> +#ifdef IMPLICIT_FLAG
> +// expected-error at diag_flags.h:14 {{padding struct}}
> +#elif defined(EXPLICIT_FLAG)
> +// expected-warning at diag_flags.h:14 {{padding struct}}
> +#else
> +// expected-no-diagnostics
> +#endif
> +unsigned n = sizeof(Padded);
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170502/d6a4dd19/attachment-0001.html>


More information about the cfe-commits mailing list