Skip to content

Commit 4e2fa1a

Browse files
committed
Merge "merge main into amd-staging" into amd-staging
2 parents 777e5cd + e0a727c commit 4e2fa1a

File tree

160 files changed

+6551
-3204
lines changed

Some content is hidden

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

160 files changed

+6551
-3204
lines changed

clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,22 @@ class Environment {
289289
/// `E` must be a glvalue or a `BuiltinType::BuiltinFn`
290290
StorageLocation *getStorageLocation(const Expr &E) const;
291291

292+
/// Returns the result of casting `getStorageLocation(...)` to a subclass of
293+
/// `StorageLocation` (using `cast_or_null<T>`).
294+
/// This assert-fails if the result of `getStorageLocation(...)` is not of
295+
/// type `T *`; if the storage location is not guaranteed to have type `T *`,
296+
/// consider using `dyn_cast_or_null<T>(getStorageLocation(...))` instead.
297+
template <typename T>
298+
std::enable_if_t<std::is_base_of_v<StorageLocation, T>, T *>
299+
get(const ValueDecl &D) const {
300+
return cast_or_null<T>(getStorageLocation(D));
301+
}
302+
template <typename T>
303+
std::enable_if_t<std::is_base_of_v<StorageLocation, T>, T *>
304+
get(const Expr &E) const {
305+
return cast_or_null<T>(getStorageLocation(E));
306+
}
307+
292308
/// Returns the storage location assigned to the `this` pointee in the
293309
/// environment or null if the `this` pointee has no assigned storage location
294310
/// in the environment.
@@ -457,6 +473,26 @@ class Environment {
457473
/// storage location in the environment, otherwise returns null.
458474
Value *getValue(const Expr &E) const;
459475

476+
/// Returns the result of casting `getValue(...)` to a subclass of `Value`
477+
/// (using `cast_or_null<T>`).
478+
/// This assert-fails if the result of `getValue(...)` is not of type `T *`;
479+
/// if the value is not guaranteed to have type `T *`, consider using
480+
/// `dyn_cast_or_null<T>(getValue(...))` instead.
481+
template <typename T>
482+
std::enable_if_t<std::is_base_of_v<Value, T>, T *>
483+
get(const StorageLocation &Loc) const {
484+
return cast_or_null<T>(getValue(Loc));
485+
}
486+
template <typename T>
487+
std::enable_if_t<std::is_base_of_v<Value, T>, T *>
488+
get(const ValueDecl &D) const {
489+
return cast_or_null<T>(getValue(D));
490+
}
491+
template <typename T>
492+
std::enable_if_t<std::is_base_of_v<Value, T>, T *> get(const Expr &E) const {
493+
return cast_or_null<T>(getValue(E));
494+
}
495+
460496
// FIXME: should we deprecate the following & call arena().create() directly?
461497

462498
/// Creates a `T` (some subclass of `Value`), forwarding `args` to the
@@ -691,20 +727,9 @@ RecordStorageLocation *getBaseObjectLocation(const MemberExpr &ME,
691727
std::vector<FieldDecl *> getFieldsForInitListExpr(const RecordDecl *RD);
692728

693729
/// Associates a new `RecordValue` with `Loc` and returns the new value.
694-
/// It is not defined whether the field values remain the same or not.
695-
///
696-
/// This function is primarily intended for use by checks that set custom
697-
/// properties on `RecordValue`s to model the state of these values. Such checks
698-
/// should avoid modifying the properties of an existing `RecordValue` because
699-
/// these changes would be visible to other `Environment`s that share the same
700-
/// `RecordValue`. Instead, call `refreshRecordValue()`, then set the properties
701-
/// on the new `RecordValue` that it returns. Typical usage:
702-
///
703-
/// refreshRecordValue(Loc, Env).setProperty("my_prop", MyPropValue);
704730
RecordValue &refreshRecordValue(RecordStorageLocation &Loc, Environment &Env);
705731

706732
/// Associates a new `RecordValue` with `Expr` and returns the new value.
707-
/// See also documentation for the overload above.
708733
RecordValue &refreshRecordValue(const Expr &Expr, Environment &Env);
709734

710735
} // namespace dataflow

clang/include/clang/Analysis/FlowSensitive/RecordOps.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,13 @@ namespace dataflow {
2222
/// Copies a record (struct, class, or union) from `Src` to `Dst`.
2323
///
2424
/// This performs a deep copy, i.e. it copies every field (including synthetic
25-
/// fields) and recurses on fields of record type. It also copies properties
26-
/// from the `RecordValue` associated with `Src` to the `RecordValue` associated
27-
/// with `Dst` (if these `RecordValue`s exist).
25+
/// fields) and recurses on fields of record type.
2826
///
2927
/// If there is a `RecordValue` associated with `Dst` in the environment, this
3028
/// function creates a new `RecordValue` and associates it with `Dst`; clients
3129
/// need to be aware of this and must not assume that the `RecordValue`
3230
/// associated with `Dst` remains the same after the call.
3331
///
34-
/// We create a new `RecordValue` rather than modifying properties on the old
35-
/// `RecordValue` because the old `RecordValue` may be shared with other
36-
/// `Environment`s, and we don't want changes to properties to be visible there.
37-
///
3832
/// Requirements:
3933
///
4034
/// `Src` and `Dst` must have the same canonical unqualified type.
@@ -49,9 +43,7 @@ void copyRecord(RecordStorageLocation &Src, RecordStorageLocation &Dst,
4943
///
5044
/// This performs a deep comparison, i.e. it compares every field (including
5145
/// synthetic fields) and recurses on fields of record type. Fields of reference
52-
/// type compare equal if they refer to the same storage location. If
53-
/// `RecordValue`s are associated with `Loc1` and Loc2`, it also compares the
54-
/// properties on those `RecordValue`s.
46+
/// type compare equal if they refer to the same storage location.
5547
///
5648
/// Note on how to interpret the result:
5749
/// - If this returns true, the records are guaranteed to be equal at runtime.

clang/include/clang/Analysis/FlowSensitive/Value.h

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ class Value {
6363

6464
/// Assigns `Val` as the value of the synthetic property with the given
6565
/// `Name`.
66+
///
67+
/// Properties may not be set on `RecordValue`s; use synthetic fields instead
68+
/// (for details, see documentation for `RecordStorageLocation`).
6669
void setProperty(llvm::StringRef Name, Value &Val) {
70+
assert(getKind() != Kind::Record);
6771
Properties.insert_or_assign(Name, &Val);
6872
}
6973

@@ -184,33 +188,23 @@ class PointerValue final : public Value {
184188
/// In C++, prvalues of class type serve only a limited purpose: They can only
185189
/// be used to initialize a result object. It is not possible to access member
186190
/// variables or call member functions on a prvalue of class type.
187-
/// Correspondingly, `RecordValue` also serves only two limited purposes:
188-
/// - It conveys a prvalue of class type from the place where the object is
189-
/// constructed to the result object that it initializes.
191+
/// Correspondingly, `RecordValue` also serves only a limited purpose: It
192+
/// conveys a prvalue of class type from the place where the object is
193+
/// constructed to the result object that it initializes.
190194
///
191-
/// When creating a prvalue of class type, we already need a storage location
192-
/// for `this`, even though prvalues are otherwise not associated with storage
193-
/// locations. `RecordValue` is therefore essentially a wrapper for a storage
194-
/// location, which is then used to set the storage location for the result
195-
/// object when we process the AST node for that result object.
195+
/// When creating a prvalue of class type, we already need a storage location
196+
/// for `this`, even though prvalues are otherwise not associated with storage
197+
/// locations. `RecordValue` is therefore essentially a wrapper for a storage
198+
/// location, which is then used to set the storage location for the result
199+
/// object when we process the AST node for that result object.
196200
///
197-
/// For example:
198-
/// MyStruct S = MyStruct(3);
201+
/// For example:
202+
/// MyStruct S = MyStruct(3);
199203
///
200-
/// In this example, `MyStruct(3) is a prvalue, which is modeled as a
201-
/// `RecordValue` that wraps a `RecordStorageLocation`. This
202-
// `RecordStorageLocation` is then used as the storage location for `S`.
204+
/// In this example, `MyStruct(3) is a prvalue, which is modeled as a
205+
/// `RecordValue` that wraps a `RecordStorageLocation`. This
206+
/// `RecordStorageLocation` is then used as the storage location for `S`.
203207
///
204-
/// - It allows properties to be associated with an object of class type.
205-
/// Note that when doing so, you should avoid mutating the properties of an
206-
/// existing `RecordValue` in place, as these changes would be visible to
207-
/// other `Environment`s that share the same `RecordValue`. Instead, associate
208-
/// a new `RecordValue` with the `RecordStorageLocation` and set the
209-
/// properties on this new `RecordValue`. (See also `refreshRecordValue()` in
210-
/// DataflowEnvironment.h, which makes this easy.)
211-
/// Note also that this implies that it is common for the same
212-
/// `RecordStorageLocation` to be associated with different `RecordValue`s
213-
/// in different environments.
214208
/// Over time, we may eliminate `RecordValue` entirely. See also the discussion
215209
/// here: https://reviews.llvm.org/D155204#inline-1503204
216210
class RecordValue final : public Value {

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ ENUM_LANGOPT(SignReturnAddressScope, SignReturnAddressScopeKind, 2, SignReturnAd
464464
ENUM_LANGOPT(SignReturnAddressKey, SignReturnAddressKeyKind, 1, SignReturnAddressKeyKind::AKey,
465465
"Key used for return address signing")
466466
LANGOPT(BranchTargetEnforcement, 1, 0, "Branch-target enforcement enabled")
467+
LANGOPT(BranchProtectionPAuthLR, 1, 0, "Use PC as a diversifier using PAuthLR NOP instructions.")
467468

468469
LANGOPT(SpeculativeLoadHardening, 1, 0, "Speculative load hardening enabled")
469470

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ class TargetInfo : public TransferrableTargetInfo,
13721372
LangOptions::SignReturnAddressKeyKind SignKey =
13731373
LangOptions::SignReturnAddressKeyKind::AKey;
13741374
bool BranchTargetEnforcement = false;
1375+
bool BranchProtectionPAuthLR = false;
13751376
};
13761377

13771378
/// Determine if the Architecture in this TargetInfo supports branch

0 commit comments

Comments
 (0)