Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from llvm:main #9

Merged
merged 10 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ class ModuleDepCollectorPP final : public PPCallbacks {

/// Adds direct modular dependencies that have already been built to the
/// ModuleDeps instance.
void addDirectPrebuiltModuleDeps(const Module *M, ModuleDeps &MD);
void
addAllSubmodulePrebuiltDeps(const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &SeenSubmodules);
void addModulePrebuiltDeps(const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &SeenSubmodules);

/// Traverses the previously collected direct modular dependencies to discover
/// transitive modular dependencies and fills the parent \c ModuleDepCollector
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
Fn->addFnAttr("packed-stack");
}

if (CGM.getCodeGenOpts().WarnStackSize != UINT_MAX)
if (CGM.getCodeGenOpts().WarnStackSize != UINT_MAX &&
!CGM.getDiags().isIgnored(diag::warn_fe_backend_frame_larger_than, Loc))
Fn->addFnAttr("warn-stack-size",
std::to_string(CGM.getCodeGenOpts().WarnStackSize));

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6444,5 +6444,5 @@ bool CodeGenModule::stopAutoInit() {

void CodeGenModule::printPostfixForExternalizedStaticVar(
llvm::raw_ostream &OS) const {
OS << ".static." << getContext().getCUIDHash();
OS << "__static__" << getContext().getCUIDHash();
}
22 changes: 17 additions & 5 deletions clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
// Add direct prebuilt module dependencies now, so that we can use them when
// creating a CompilerInvocation and computing context hash for this
// ModuleDeps instance.
addDirectPrebuiltModuleDeps(M, MD);
llvm::DenseSet<const Module *> SeenModules;
addAllSubmodulePrebuiltDeps(M, MD, SeenModules);

MD.Invocation = MDC.makeInvocationForModuleBuildWithoutPaths(MD);
MD.ID.ContextHash = MD.Invocation.getModuleHash();
Expand All @@ -242,12 +243,23 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
return MD.ID;
}

void ModuleDepCollectorPP::addDirectPrebuiltModuleDeps(const Module *M,
ModuleDeps &MD) {
void ModuleDepCollectorPP::addAllSubmodulePrebuiltDeps(
const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &SeenSubmodules) {
addModulePrebuiltDeps(M, MD, SeenSubmodules);

for (const Module *SubM : M->submodules())
addAllSubmodulePrebuiltDeps(SubM, MD, SeenSubmodules);
}

void ModuleDepCollectorPP::addModulePrebuiltDeps(
const Module *M, ModuleDeps &MD,
llvm::DenseSet<const Module *> &SeenSubmodules) {
for (const Module *Import : M->Imports)
if (Import->getTopLevelModule() != M->getTopLevelModule())
if (MDC.isPrebuiltModule(Import))
MD.PrebuiltModuleDeps.emplace_back(Import);
if (MDC.isPrebuiltModule(Import->getTopLevelModule()))
if (SeenSubmodules.insert(Import->getTopLevelModule()).second)
MD.PrebuiltModuleDeps.emplace_back(Import->getTopLevelModule());
}

void ModuleDepCollectorPP::addAllSubmoduleDeps(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"directory": "DIR",
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch",
"file": "DIR/pch.h"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"directory": "DIR",
"command": "clang -fsyntax-only DIR/tu.c -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/pch.h -o DIR/tu.o",
"file": "DIR/tu.c"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mod_common_sub.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module ModCommon {
header "mod_common.h"

module ModCommonSub {
header "mod_common_sub.h"
}
}

module ModTU {
header "mod_tu.h"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mod_common.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mod_tu.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"directory": "DIR",
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch",
"file": "DIR/pch.h"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"directory": "DIR",
"command": "clang -fsyntax-only DIR/tu.c -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/pch.h -o DIR/tu.o",
"file": "DIR/tu.c"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mod_common.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module ModCommon {
header "mod_common.h"
}

module ModTU {
header "mod_tu.h"

module ModTUSub {
header "mod_tu_sub.h"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mod_common.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mod_tu.h"
140 changes: 140 additions & 0 deletions clang/test/ClangScanDeps/modules-pch-common-submodule.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Check that when depending on a precompiled module, we depend on the
// **top-level** module. Submodules don't have some information present (for
// example the path to the modulemap file) and depending on them might cause
// problems in the dependency scanner (e.g. generating empty `-fmodule-map-file=`
// arguments).

// RUN: rm -rf %t && mkdir %t
// RUN: cp %S/Inputs/modules-pch-common-submodule/* %t

// Scan dependencies of the PCH:
//
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch-common-submodule/cdb_pch.json > %t/cdb.json
// RUN: echo -%t > %t/result_pch.json
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
// RUN: -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
// RUN: cat %t/result_pch.json | sed 's:\\\\\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
//
// CHECK-PCH: -[[PREFIX:.*]]
// CHECK-PCH-NEXT: {
// CHECK-PCH-NEXT: "modules": [
// CHECK-PCH-NEXT: {
// CHECK-PCH-NEXT: "clang-module-deps": [],
// CHECK-PCH-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
// CHECK-PCH-NEXT: "command-line": [
// CHECK-PCH-NEXT: "-cc1"
// CHECK-PCH: "-emit-module"
// CHECK-PCH: "-fmodules"
// CHECK-PCH: "-fmodule-name=ModCommon"
// CHECK-PCH: "-fno-implicit-modules"
// CHECK-PCH: ],
// CHECK-PCH-NEXT: "context-hash": "[[HASH_MOD_COMMON:.*]]",
// CHECK-PCH-NEXT: "file-deps": [
// CHECK-PCH-NEXT: "[[PREFIX]]/mod_common.h",
// CHECK-PCH-NEXT: "[[PREFIX]]/mod_common_sub.h",
// CHECK-PCH-NEXT: "[[PREFIX]]/module.modulemap"
// CHECK-PCH-NEXT: ],
// CHECK-PCH-NEXT: "name": "ModCommon"
// CHECK-PCH-NEXT: }
// CHECK-PCH-NEXT: ],
// CHECK-PCH-NEXT: "translation-units": [
// CHECK-PCH-NEXT: {
// CHECK-PCH-NEXT: "clang-context-hash": "[[HASH_PCH:.*]]",
// CHECK-PCH-NEXT: "clang-module-deps": [
// CHECK-PCH-NEXT: {
// CHECK-PCH-NEXT: "context-hash": "[[HASH_MOD_COMMON]]",
// CHECK-PCH-NEXT: "module-name": "ModCommon"
// CHECK-PCH-NEXT: }
// CHECK-PCH-NEXT: ],
// CHECK-PCH-NEXT: "command-line": [
// CHECK-PCH-NEXT: "-fno-implicit-modules"
// CHECK-PCH-NEXT: "-fno-implicit-module-maps"
// CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON]]/ModCommon-{{.*}}.pcm"
// CHECK-PCH-NEXT: "-fmodule-map-file=[[PREFIX]]/module.modulemap"
// CHECK-PCH-NEXT: ],
// CHECK-PCH-NEXT: "file-deps": [
// CHECK-PCH-NEXT: "[[PREFIX]]/pch.h"
// CHECK-PCH-NEXT: ],
// CHECK-PCH-NEXT: "input-file": "[[PREFIX]]/pch.h"
// CHECK-PCH-NEXT: }
// CHECK-PCH-NEXT: ]
// CHECK-PCH-NEXT: }

// Explicitly build the PCH:
//
// RUN: tail -n +2 %t/result_pch.json > %t/result_pch_stripped.json
// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
// RUN: --module-name=ModCommon > %t/mod_common.cc1.rsp
// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
// RUN: --tu-index=0 > %t/pch.rsp
//
// RUN: %clang @%t/mod_common.cc1.rsp
// RUN: %clang -x c-header %t/pch.h -fmodules -gmodules -fimplicit-module-maps \
// RUN: -fmodules-cache-path=%t/cache -o %t/pch.h.gch @%t/pch.rsp

// Scan dependencies of the TU:
//
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch-common-submodule/cdb_tu.json > %t/cdb.json
// RUN: echo -%t > %t/result_tu.json
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
// RUN: -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu.json
// RUN: cat %t/result_tu.json | sed 's:\\\\\?:/:g' | FileCheck %s -check-prefix=CHECK-TU
//
// CHECK-TU: -[[PREFIX:.*]]
// CHECK-TU-NEXT: {
// CHECK-TU-NEXT: "modules": [
// CHECK-TU-NEXT: {
// CHECK-TU-NEXT: "clang-module-deps": [],
// CHECK-TU-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
// CHECK-TU-NEXT: "command-line": [
// CHECK-TU-NEXT: "-cc1"
// CHECK-TU: "-fmodule-map-file=[[PREFIX]]/module.modulemap"
// CHECK-TU: "-emit-module"
// CHECK-TU: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON:.*]]/ModCommon-{{.*}}.pcm"
// CHECK-TU: "-fmodules"
// CHECK-TU: "-fmodule-name=ModTU"
// CHECK-TU: "-fno-implicit-modules"
// CHECK-TU: ],
// CHECK-TU-NEXT: "context-hash": "[[HASH_MOD_TU:.*]]",
// CHECK-TU-NEXT: "file-deps": [
// CHECK-TU-NEXT: "[[PREFIX]]/mod_tu.h",
// CHECK-TU-NEXT: "[[PREFIX]]/module.modulemap"
// CHECK-TU-NEXT: ],
// CHECK-TU-NEXT: "name": "ModTU"
// CHECK-TU-NEXT: }
// CHECK-TU-NEXT: ],
// CHECK-TU-NEXT: "translation-units": [
// CHECK-TU-NEXT: {
// CHECK-TU-NEXT: "clang-context-hash": "[[HASH_TU:.*]]",
// CHECK-TU-NEXT: "clang-module-deps": [
// CHECK-TU-NEXT: {
// CHECK-TU-NEXT: "context-hash": "[[HASH_MOD_TU]]"
// CHECK-TU-NEXT: "module-name": "ModTU"
// CHECK-TU-NEXT: }
// CHECK-TU-NEXT: ],
// CHECK-TU-NEXT: "command-line": [
// CHECK-TU-NEXT: "-fno-implicit-modules",
// CHECK-TU-NEXT: "-fno-implicit-module-maps",
// CHECK-TU-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_TU:.*]]/ModTU-{{.*}}.pcm",
// CHECK-TU-NEXT: "-fmodule-map-file=[[PREFIX]]/module.modulemap"
// CHECK-TU-NEXT: ],
// CHECK-TU-NEXT: "file-deps": [
// CHECK-TU-NEXT: "[[PREFIX]]/tu.c",
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.gch"
// CHECK-TU-NEXT: ],
// CHECK-TU-NEXT: "input-file": "[[PREFIX]]/tu.c"
// CHECK-TU-NEXT: }
// CHECK-TU-NEXT: ]
// CHECK-TU-NEXT: }

// Explicitly build the TU:
//
// RUN: tail -n +2 %t/result_tu.json > %t/result_tu_stripped.json
// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu_stripped.json \
// RUN: --module-name=ModTU > %t/mod_tu.cc1.rsp
// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu_stripped.json \
// RUN: --tu-index=0 > %t/tu.rsp
//
// RUN: %clang @%t/mod_tu.cc1.rsp
// RUN: %clang -fsyntax-only %t/tu.c -fmodules -gmodules -fimplicit-module-maps \
// RUN: -fmodules-cache-path=%t/cache -include %t/pch.h -o %t/tu.o @%t/tu.rsp
Loading