Skip to content

Commit b04ccdb

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:c4bc1b1d8177 into origin/amd-gfx:23e6bf1399b8
Local branch origin/amd-gfx 23e6bf1 Merged main:7b75db5755e6 into origin/amd-gfx:ecd811392b7a Remote branch main c4bc1b1 [clang] Update Mach-O ptrauth driver defaults (llvm#132834)
2 parents 23e6bf1 + c4bc1b1 commit b04ccdb

File tree

34 files changed

+811
-81
lines changed

34 files changed

+811
-81
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ Bug Fixes in This Version
323323
- Fixed a modules crash where exception specifications were not propagated properly (#GH121245, relanded in #GH129982)
324324
- Fixed a problematic case with recursive deserialization within ``FinishedDeserializing()`` where
325325
``PassInterestingDeclsToConsumer()`` was called before the declarations were safe to be passed. (#GH129982)
326+
- Fixed a modules crash where an explicit Constructor was deserialized. (#GH132794)
326327

327328
Bug Fixes to Compiler Builtins
328329
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,13 @@ void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const {
12011201
}
12021202
}
12031203

1204+
void DarwinClang::addClangTargetOptions(
1205+
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
1206+
Action::OffloadKind DeviceOffloadKind) const {
1207+
1208+
Darwin::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
1209+
}
1210+
12041211
/// Take a path that speculatively points into Xcode and return the
12051212
/// `XCODE/Contents/Developer` path if it is an Xcode path, or an empty path
12061213
/// otherwise.
@@ -3056,9 +3063,43 @@ bool Darwin::isSizedDeallocationUnavailable() const {
30563063
return TargetVersion < sizedDeallocMinVersion(OS);
30573064
}
30583065

3066+
void MachO::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
3067+
llvm::opt::ArgStringList &CC1Args,
3068+
Action::OffloadKind DeviceOffloadKind) const {
3069+
3070+
ToolChain::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
3071+
3072+
// On arm64e, enable pointer authentication (for the return address and
3073+
// indirect calls), as well as usage of the intrinsics.
3074+
if (getArchName() == "arm64e") {
3075+
if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
3076+
options::OPT_fno_ptrauth_returns))
3077+
CC1Args.push_back("-fptrauth-returns");
3078+
3079+
if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
3080+
options::OPT_fno_ptrauth_intrinsics))
3081+
CC1Args.push_back("-fptrauth-intrinsics");
3082+
3083+
if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
3084+
options::OPT_fno_ptrauth_calls))
3085+
CC1Args.push_back("-fptrauth-calls");
3086+
3087+
if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
3088+
options::OPT_fno_ptrauth_indirect_gotos))
3089+
CC1Args.push_back("-fptrauth-indirect-gotos");
3090+
3091+
if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
3092+
options::OPT_fno_ptrauth_auth_traps))
3093+
CC1Args.push_back("-fptrauth-auth-traps");
3094+
}
3095+
}
3096+
30593097
void Darwin::addClangTargetOptions(
30603098
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
30613099
Action::OffloadKind DeviceOffloadKind) const {
3100+
3101+
MachO::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
3102+
30623103
// Pass "-faligned-alloc-unavailable" only when the user hasn't manually
30633104
// enabled or disabled aligned allocations.
30643105
if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,

clang/lib/Driver/ToolChains/Darwin.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
145145
Tool *buildStaticLibTool() const override;
146146
Tool *getTool(Action::ActionClass AC) const override;
147147

148+
void
149+
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
150+
llvm::opt::ArgStringList &CC1Args,
151+
Action::OffloadKind DeviceOffloadKind) const override;
152+
148153
private:
149154
mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
150155
mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
@@ -653,6 +658,11 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
653658

654659
void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
655660

661+
void
662+
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
663+
llvm::opt::ArgStringList &CC1Args,
664+
Action::OffloadKind DeviceOffloadKind) const override;
665+
656666
void AddLinkARCArgs(const llvm::opt::ArgList &Args,
657667
llvm::opt::ArgStringList &CmdArgs) const override;
658668

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
17261726
"CXXConstructorDeclBits");
17271727

17281728
Record.push_back(D->getTrailingAllocKind());
1729-
addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1729+
addExplicitSpecifier(D->getExplicitSpecifierInternal(), Record);
17301730
if (auto Inherited = D->getInheritedConstructor()) {
17311731
Record.AddDeclRef(Inherited.getShadowDecl());
17321732
Record.AddDeclRef(Inherited.getConstructor());

clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,23 @@ static bool getPrintfFormatArgumentNum(const CallEvent &Call,
10801080
const ArgIdxTy CallNumArgs = fromArgumentCount(Call.getNumArgs());
10811081

10821082
for (const auto *Format : FDecl->specific_attrs<FormatAttr>()) {
1083+
// The format attribute uses 1-based parameter indexing, for example
1084+
// plain `printf(const char *fmt, ...)` would be annotated with
1085+
// `__format__(__printf__, 1, 2)`, so we need to subtract 1 to get a
1086+
// 0-based index. (This checker uses 0-based parameter indices.)
10831087
ArgNum = Format->getFormatIdx() - 1;
1088+
// The format attribute also counts the implicit `this` parameter of
1089+
// methods, so e.g. in `SomeClass::method(const char *fmt, ...)` could be
1090+
// annotated with `__format__(__printf__, 2, 3)`. This checker doesn't
1091+
// count the implicit `this` parameter, so in this case we need to subtract
1092+
// one again.
1093+
// FIXME: Apparently the implementation of the format attribute doesn't
1094+
// support methods with an explicit object parameter, so we cannot
1095+
// implement proper support for that rare case either.
1096+
const CXXMethodDecl *MDecl = dyn_cast<CXXMethodDecl>(FDecl);
1097+
if (MDecl && !MDecl->isStatic())
1098+
ArgNum--;
1099+
10841100
if ((Format->getType()->getName() == "printf") && CallNumArgs > ArgNum)
10851101
return true;
10861102
}

clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
15851585
if (LookupRes.empty())
15861586
return std::nullopt;
15871587

1588-
// Prioritze typedef declarations.
1588+
// Prioritize typedef declarations.
15891589
// This is needed in case of C struct typedefs. E.g.:
15901590
// typedef struct FILE FILE;
15911591
// In this case, we have a RecordDecl 'struct FILE' with the name 'FILE'

clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ STAT_COUNTER(NumTimesZ3QueryRejectReport,
4141
STAT_COUNTER(NumTimesZ3QueryRejectEQClass,
4242
"Number of times rejecting an report equivalenece class");
4343

44+
STAT_COUNTER(TimeSpentSolvingZ3Queries,
45+
"Total time spent solving Z3 queries excluding retries");
46+
STAT_MAX(MaxTimeSpentSolvingZ3Queries,
47+
"Max time spent solving a Z3 query excluding retries");
48+
4449
using namespace clang;
4550
using namespace ento;
4651

@@ -145,6 +150,8 @@ Z3CrosscheckOracle::Z3Decision Z3CrosscheckOracle::interpretQueryResult(
145150
const Z3CrosscheckVisitor::Z3Result &Query) {
146151
++NumZ3QueriesDone;
147152
AccumulatedZ3QueryTimeInEqClass += Query.Z3QueryTimeMilliseconds;
153+
TimeSpentSolvingZ3Queries += Query.Z3QueryTimeMilliseconds;
154+
MaxTimeSpentSolvingZ3Queries.updateMax(Query.Z3QueryTimeMilliseconds);
148155

149156
if (Query.IsSAT && Query.IsSAT.value()) {
150157
++NumTimesZ3QueryAcceptsReport;

clang/test/Analysis/analyzer-stats/entry-point-stats.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
// CHECK-NEXT: "NumTimesZ3SpendsTooMuchTimeOnASingleEQClass": "{{[0-9]+}}",
3232
// CHECK-NEXT: "NumTimesZ3TimedOut": "{{[0-9]+}}",
3333
// CHECK-NEXT: "NumZ3QueriesDone": "{{[0-9]+}}",
34+
// CHECK-NEXT: "TimeSpentSolvingZ3Queries": "{{[0-9]+}}",
3435
// CHECK-NEXT: "MaxBugClassSize": "{{[0-9]+}}",
3536
// CHECK-NEXT: "MaxCFGSize": "{{[0-9]+}}",
3637
// CHECK-NEXT: "MaxQueueSize": "{{[0-9]+}}",
3738
// CHECK-NEXT: "MaxReachableSize": "{{[0-9]+}}",
39+
// CHECK-NEXT: "MaxTimeSpentSolvingZ3Queries": "{{[0-9]+}}",
3840
// CHECK-NEXT: "MaxValidBugClassSize": "{{[0-9]+}}",
3941
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}"
4042
// CHECK-NEXT: },
@@ -64,10 +66,12 @@
6466
// CHECK-NEXT: "NumTimesZ3SpendsTooMuchTimeOnASingleEQClass": "{{[0-9]+}}",
6567
// CHECK-NEXT: "NumTimesZ3TimedOut": "{{[0-9]+}}",
6668
// CHECK-NEXT: "NumZ3QueriesDone": "{{[0-9]+}}",
69+
// CHECK-NEXT: "TimeSpentSolvingZ3Queries": "{{[0-9]+}}",
6770
// CHECK-NEXT: "MaxBugClassSize": "{{[0-9]+}}",
6871
// CHECK-NEXT: "MaxCFGSize": "{{[0-9]+}}",
6972
// CHECK-NEXT: "MaxQueueSize": "{{[0-9]+}}",
7073
// CHECK-NEXT: "MaxReachableSize": "{{[0-9]+}}",
74+
// CHECK-NEXT: "MaxTimeSpentSolvingZ3Queries": "{{[0-9]+}}",
7175
// CHECK-NEXT: "MaxValidBugClassSize": "{{[0-9]+}}",
7276
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}"
7377
// CHECK-NEXT: }

clang/test/Analysis/taint-generic.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,45 @@ void top() {
161161
clang_analyzer_isTainted(A.data); // expected-warning {{YES}}
162162
}
163163
} // namespace gh114270
164+
165+
166+
namespace format_attribute {
167+
__attribute__((__format__ (__printf__, 1, 2)))
168+
void log_freefunc(const char *fmt, ...);
169+
170+
void test_format_attribute_freefunc() {
171+
int n;
172+
fscanf(stdin, "%d", &n); // Get a tainted value.
173+
174+
log_freefunc("This number is suspicious: %d\n", n); // no-warning
175+
}
176+
177+
struct Foo {
178+
// When the format attribute is applied to a method, argumet '1' is the
179+
// implicit `this`, so e.g. in this case argument '2' specifies `fmt`.
180+
// Specifying '1' instead of '2' would produce a compilation error:
181+
// "format attribute cannot specify the implicit this argument as the format string"
182+
__attribute__((__format__ (__printf__, 2, 3)))
183+
void log_method(const char *fmt, ...);
184+
185+
void test_format_attribute_method() {
186+
int n;
187+
fscanf(stdin, "%d", &n); // Get a tainted value.
188+
189+
// The analyzer used to misinterpret the parameter indices in the format
190+
// attribute when the format attribute is applied to a method.
191+
log_method("This number is suspicious: %d\n", n); // no-warning
192+
}
193+
194+
__attribute__((__format__ (__printf__, 1, 2)))
195+
static void log_static_method(const char *fmt, ...);
196+
197+
void test_format_attribute_static_method() {
198+
int n;
199+
fscanf(stdin, "%d", &n); // Get a tainted value.
200+
201+
log_static_method("This number is suspicious: %d\n", n); // no-warning
202+
}
203+
};
204+
205+
} // namespace format_attribute
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// REQUIRES: mips64-registered-target
2+
// RUN: %clang --target=mips64-linux-gnu -mcpu=i6400 -o %t -c %s 2>&1 | FileCheck --allow-empty %s
3+
// CHECK-NOT: {{.*}} is not a recognized feature for this target
4+
5+
// RUN: %clang --target=mips64-linux-gnu -mcpu=i6500 -o %t -c %s 2>&1 | FileCheck --allow-empty %s
6+
// CHECK-NOT: {{.*}} is not a recognized feature for this target

0 commit comments

Comments
 (0)