Skip to content

Commit 894877c

Browse files
authored
Merge pull request #1878 from brentdax/merged-into-an-umbrella-corporation
Manually merge apple/stable/20200714 -> swift/main
2 parents 0bd1713 + 9fa69d8 commit 894877c

File tree

84 files changed

+1754
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1754
-187
lines changed

clang/docs/SourceBasedCodeCoverage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ directory structure will be created. Additionally, the following special
7979

8080
* "%h" expands out to the hostname of the machine running the program.
8181

82+
* "%t" expands out to the value of the ``TMPDIR`` environment variable. On
83+
Darwin, this is typically set to a temporary scratch directory.
84+
8285
* "%Nm" expands out to the instrumented binary's signature. When this pattern
8386
is specified, the runtime creates a pool of N raw profiles which are used for
8487
on-line profile merging. The runtime takes care of selecting a raw profile

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def ExtraSemi : DiagGroup<"extra-semi", [CXX98CompatExtraSemi,
234234
def GNUFlexibleArrayInitializer : DiagGroup<"gnu-flexible-array-initializer">;
235235
def GNUFlexibleArrayUnionMember : DiagGroup<"gnu-flexible-array-union-member">;
236236
def GNUFoldingConstant : DiagGroup<"gnu-folding-constant">;
237+
def FormatInsufficientArgs : DiagGroup<"format-insufficient-args">;
237238
def FormatExtraArgs : DiagGroup<"format-extra-args">;
238239
def FormatZeroLength : DiagGroup<"format-zero-length">;
239240

@@ -840,7 +841,8 @@ def FormatPedantic : DiagGroup<"format-pedantic">;
840841
def FormatTypeConfusion : DiagGroup<"format-type-confusion">;
841842
def Format : DiagGroup<"format",
842843
[FormatExtraArgs, FormatZeroLength, NonNull,
843-
FormatSecurity, FormatY2K, FormatInvalidSpecifier]>,
844+
FormatSecurity, FormatY2K, FormatInvalidSpecifier,
845+
FormatInsufficientArgs]>,
844846
DiagCategory<"Format String Issue">;
845847
def FormatNonLiteral : DiagGroup<"format-nonliteral">;
846848
def Format2 : DiagGroup<"format=2",

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8945,7 +8945,7 @@ def note_array_declared_here : Note<
89458945
"array %0 declared here">;
89468946

89478947
def warn_printf_insufficient_data_args : Warning<
8948-
"more '%%' conversions than data arguments">, InGroup<Format>;
8948+
"more '%%' conversions than data arguments">, InGroup<FormatInsufficientArgs>;
89498949
def warn_printf_data_arg_not_used : Warning<
89508950
"data argument not used by format string">, InGroup<FormatExtraArgs>;
89518951
def warn_format_invalid_conversion : Warning<

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,10 +3746,7 @@ void CodeGenFunction::EmitNonNullArgCheck(RValue RV, QualType ArgType,
37463746
}
37473747

37483748
SanitizerScope SanScope(this);
3749-
assert(RV.isScalar());
3750-
llvm::Value *V = RV.getScalarVal();
3751-
llvm::Value *Cond =
3752-
Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
3749+
llvm::Value *Cond = EmitNonNullRValueCheck(RV, ArgType);
37533750
llvm::Constant *StaticData[] = {
37543751
EmitCheckSourceLocation(ArgLoc), EmitCheckSourceLocation(AttrLoc),
37553752
llvm::ConstantInt::get(Int32Ty, ArgNo + 1),

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,13 @@ Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
11701170
return Address(EmitScalarExpr(E), Align);
11711171
}
11721172

1173+
llvm::Value *CodeGenFunction::EmitNonNullRValueCheck(RValue RV, QualType T) {
1174+
llvm::Value *V = RV.getScalarVal();
1175+
if (auto MPT = T->getAs<MemberPointerType>())
1176+
return CGM.getCXXABI().EmitMemberPointerIsNotNull(*this, V, MPT);
1177+
return Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
1178+
}
1179+
11731180
RValue CodeGenFunction::GetUndefRValue(QualType Ty) {
11741181
if (Ty->isVoidType())
11751182
return RValue::get(nullptr);

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,9 @@ class CodeGenFunction : public CodeGenTypeCache {
35633563
// LValue Expression Emission
35643564
//===--------------------------------------------------------------------===//
35653565

3566+
/// Create a check that a scalar RValue is non-null.
3567+
llvm::Value *EmitNonNullRValueCheck(RValue RV, QualType T);
3568+
35663569
/// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
35673570
RValue GetUndefRValue(QualType Ty);
35683571

clang/lib/Lex/PPLexerChange.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ static void collectAllSubModulesWithUmbrellaHeader(
263263
}
264264

265265
void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module &Mod) {
266-
assert(Mod.getUmbrellaHeader() && "Module must use umbrella header");
267-
SourceLocation StartLoc =
268-
SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
269-
if (getDiagnostics().isIgnored(diag::warn_uncovered_module_header, StartLoc))
266+
const Module::Header &UmbrellaHeader = Mod.getUmbrellaHeader();
267+
assert(UmbrellaHeader.Entry && "Module must use umbrella header");
268+
const FileID &File = SourceMgr.translateFile(UmbrellaHeader.Entry);
269+
SourceLocation ExpectedHeadersLoc = SourceMgr.getLocForEndOfFile(File);
270+
if (getDiagnostics().isIgnored(diag::warn_uncovered_module_header,
271+
ExpectedHeadersLoc))
270272
return;
271273

272274
ModuleMap &ModMap = getHeaderSearchInfo().getModuleMap();
@@ -291,7 +293,7 @@ void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module &Mod) {
291293
// Find the relative path that would access this header.
292294
SmallString<128> RelativePath;
293295
computeRelativePath(FileMgr, Dir, *Header, RelativePath);
294-
Diag(StartLoc, diag::warn_uncovered_module_header)
296+
Diag(ExpectedHeadersLoc, diag::warn_uncovered_module_header)
295297
<< Mod.getFullModuleName() << RelativePath;
296298
}
297299
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=nullability-arg | FileCheck %s -check-prefixes=ITANIUM,ALL
2+
// RUN: %clang_cc1 -x c++ -triple x86_64-pc-windows-msvc -emit-llvm -o - %s -fsanitize=nullability-arg | FileCheck %s -check-prefixes=MSVC,ALL
3+
4+
namespace method_ptr {
5+
6+
struct S0 {
7+
void foo1();
8+
};
9+
10+
void foo1(void (S0::*_Nonnull f)());
11+
12+
// ITANIUM-LABEL: @_ZN10method_ptr5test1Ev(){{.*}} {
13+
// ITANIUM: br i1 icmp ne (i64 ptrtoint (void (%"struct.method_ptr::S0"*)* @_ZN10method_ptr2S04foo1Ev to i64), i64 0), label %[[CONT:.*]], label %[[FAIL:[^,]*]]
14+
// ITANIUM-EMPTY:
15+
// ITANIUM-NEXT: [[FAIL]]:
16+
// ITANIUM-NEXT: call void @__ubsan_handle_nullability_arg
17+
18+
// MSVC-LABEL: @"?test1@method_ptr@@YAXXZ"(){{.*}} {
19+
// MSVC: br i1 true, label %[[CONT:.*]], label %[[FAIL:[^,]*]]
20+
// MSVC-EMPTY:
21+
// MSVC-NEXT: [[FAIL]]:
22+
// MSVC-NEXT: call void @__ubsan_handle_nullability_arg
23+
void test1() {
24+
foo1(&S0::foo1);
25+
}
26+
27+
} // namespace method_ptr
28+
29+
namespace data_ptr {
30+
31+
struct S0 {
32+
int field1;
33+
};
34+
35+
using member_ptr = int S0::*;
36+
37+
void foo1(member_ptr _Nonnull);
38+
39+
// ITANIUM-LABEL: @_ZN8data_ptr5test1ENS_2S0E(
40+
// MSVC-LABEL: @"?test1@data_ptr@@YAXUS0@1@@Z"(
41+
// ALL: [[DATA_PTR_CHECK:%.*]] = icmp ne {{.*}}, -1, !nosanitize
42+
// ALL-NEXT: br i1 [[DATA_PTR_CHECK]], label %[[CONT:.*]], label %[[FAIL:[^,]+]]
43+
// ALL-EMPTY:
44+
// ALL-NEXT: [[FAIL]]:
45+
// ALL-NEXT: call void @__ubsan_handle_nullability_arg
46+
void test1(S0 s) {
47+
int S0::*member = &S0::field1;
48+
foo1(member);
49+
}
50+
51+
} // namespace data_ptr

clang/test/Misc/warning-wall.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CHECK-NEXT: -Wnonnull
1515
CHECK-NEXT: -Wformat-security
1616
CHECK-NEXT: -Wformat-y2k
1717
CHECK-NEXT: -Wformat-invalid-specifier
18+
CHECK-NEXT: -Wformat-insufficient-args
1819
CHECK-NEXT: -Wfor-loop-analysis
1920
CHECK-NEXT: -Wframe-address
2021
CHECK-NEXT: -Wimplicit

clang/test/Modules/incomplete-umbrella.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
#import <Foo/Baz.h>
77
@import Foo.Private;
88

9-
// CHECK: warning: umbrella header for module 'Foo' does not include header 'Bar.h'
10-
// CHECK: warning: umbrella header for module 'Foo.Private' does not include header 'Baz.h'
9+
// CHECK: While building module 'Foo' imported from {{.*[/\]}}incomplete-umbrella.m:4:
10+
// CHECK-NEXT: In file included from <module-includes>:1:
11+
// CHECK-NEXT: {{.*Foo[.]framework[/\]Headers[/\]}}FooPublic.h:2:1: warning: umbrella header for module 'Foo' does not include header 'Bar.h'
12+
// CHECK: While building module 'Foo' imported from {{.*[/\]}}incomplete-umbrella.m:4:
13+
// CHECK-NEXT: In file included from <module-includes>:2:
14+
// CHECK-NEXT: {{.*Foo[.]framework[/\]PrivateHeaders[/\]}}Foo.h:2:1: warning: umbrella header for module 'Foo.Private' does not include header 'Baz.h'
1115
int foo() {
1216
int a = BAR_PUBLIC;
1317
int b = BAZ_PRIVATE;

0 commit comments

Comments
 (0)