Skip to content

Commit

Permalink
merge main into amd-stg-open
Browse files Browse the repository at this point in the history
Change-Id: If415bdc965a197d5dac2b4d870a4753ed921f9cd
  • Loading branch information
Jenkins committed Nov 24, 2023
2 parents 6e10f49 + 18a5ca1 commit d091f6f
Show file tree
Hide file tree
Showing 172 changed files with 3,365 additions and 1,062 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
paths:
- 'llvm/docs/**'
- 'clang/docs/**'
- 'clang/include/clang/Basic/AttrDocs.td'
- 'clang/include/clang/Driver/ClangOptionDocs.td'
- 'clang/include/clang/Basic/DiagnosticDocs.td'
- 'clang-tools-extra/docs/**'
- 'lldb/docs/**'
- 'libunwind/docs/**'
Expand All @@ -29,6 +32,9 @@ on:
paths:
- 'llvm/docs/**'
- 'clang/docs/**'
- 'clang/include/clang/Basic/AttrDocs.td'
- 'clang/include/clang/Driver/ClangOptionDocs.td'
- 'clang/include/clang/Basic/DiagnosticDocs.td'
- 'clang-tools-extra/docs/**'
- 'lldb/docs/**'
- 'libunwind/docs/**'
Expand Down Expand Up @@ -64,6 +70,9 @@ jobs:
- 'llvm/docs/**'
clang:
- 'clang/docs/**'
- 'clang/include/clang/Basic/AttrDocs.td'
- 'clang/include/clang/Driver/ClangOptionDocs.td'
- 'clang/include/clang/Basic/DiagnosticDocs.td'
clang-tools-extra:
- 'clang-tools-extra/docs/**'
lldb:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/libcxx-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ env:

jobs:
stage1:
if: github.repository_owner == 'llvm'
runs-on:
group: libcxx-runners-8
continue-on-error: false
Expand Down Expand Up @@ -81,6 +82,7 @@ jobs:
**/CMakeOutput.log
**/crash_diagnostics/*
stage2:
if: github.repository_owner == 'llvm'
runs-on:
group: libcxx-runners-8
needs: [ stage1 ]
Expand Down Expand Up @@ -130,6 +132,7 @@ jobs:
**/CMakeOutput.log
**/crash_diagnostics/*
stage3:
if: github.repository_owner == 'llvm'
needs: [ stage1, stage2 ]
continue-on-error: false
strategy:
Expand Down
4 changes: 2 additions & 2 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ Non-comprehensive list of changes in this release
determined at runtime.
* The ``__datasizeof`` keyword has been added. It is similar to ``sizeof``
except that it returns the size of a type ignoring tail padding.
* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the return value ``18``,
to match GCC 14's behavior.
* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the return value ``18``
and vector types as return value ``19``, to match GCC 14's behavior.

New Compiler Flags
------------------
Expand Down
138 changes: 69 additions & 69 deletions clang/docs/analyzer/checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,75 @@ security
Security related checkers.
.. _security-cert-env-InvalidPtr:
security.cert.env.InvalidPtr
""""""""""""""""""""""""""""""""""
Corresponds to SEI CERT Rules `ENV31-C <https://wiki.sei.cmu.edu/confluence/display/c/ENV31-C.+Do+not+rely+on+an+environment+pointer+following+an+operation+that+may+invalidate+it>`_ and `ENV34-C <https://wiki.sei.cmu.edu/confluence/display/c/ENV34-C.+Do+not+store+pointers+returned+by+certain+functions>`_.
* **ENV31-C**:
Rule is about the possible problem with ``main`` function's third argument, environment pointer,
"envp". When environment array is modified using some modification function
such as ``putenv``, ``setenv`` or others, It may happen that memory is reallocated,
however "envp" is not updated to reflect the changes and points to old memory
region.
* **ENV34-C**:
Some functions return a pointer to a statically allocated buffer.
Consequently, subsequent call of these functions will invalidate previous
pointer. These functions include: ``getenv``, ``localeconv``, ``asctime``, ``setlocale``, ``strerror``
.. code-block:: c
int main(int argc, const char *argv[], const char *envp[]) {
if (setenv("MY_NEW_VAR", "new_value", 1) != 0) {
// setenv call may invalidate 'envp'
/* Handle error */
}
if (envp != NULL) {
for (size_t i = 0; envp[i] != NULL; ++i) {
puts(envp[i]);
// envp may no longer point to the current environment
// this program has unanticipated behavior, since envp
// does not reflect changes made by setenv function.
}
}
return 0;
}
void previous_call_invalidation() {
char *p, *pp;
p = getenv("VAR");
setenv("SOMEVAR", "VALUE", /*overwrite = */1);
// call to 'setenv' may invalidate p
*p;
// dereferencing invalid pointer
}
The ``InvalidatingGetEnv`` option is available for treating ``getenv`` calls as
invalidating. When enabled, the checker issues a warning if ``getenv`` is called
multiple times and their results are used without first creating a copy.
This level of strictness might be considered overly pedantic for the commonly
used ``getenv`` implementations.
To enable this option, use:
``-analyzer-config security.cert.env.InvalidPtr:InvalidatingGetEnv=true``.
By default, this option is set to *false*.
When this option is enabled, warnings will be generated for scenarios like the
following:
.. code-block:: c
char* p = getenv("VAR");
char* pp = getenv("VAR2"); // assumes this call can invalidate `env`
strlen(p); // warns about accessing invalid ptr
.. _security-FloatLoopCounter:
security.FloatLoopCounter (C)
Expand Down Expand Up @@ -2549,75 +2618,6 @@ alpha.security.cert.env
SEI CERT checkers of `Environment C coding rules <https://wiki.sei.cmu.edu/confluence/x/JdcxBQ>`_.
.. _alpha-security-cert-env-InvalidPtr:
alpha.security.cert.env.InvalidPtr
""""""""""""""""""""""""""""""""""
Corresponds to SEI CERT Rules ENV31-C and ENV34-C.
ENV31-C:
Rule is about the possible problem with `main` function's third argument, environment pointer,
"envp". When environment array is modified using some modification function
such as putenv, setenv or others, It may happen that memory is reallocated,
however "envp" is not updated to reflect the changes and points to old memory
region.
ENV34-C:
Some functions return a pointer to a statically allocated buffer.
Consequently, subsequent call of these functions will invalidate previous
pointer. These functions include: getenv, localeconv, asctime, setlocale, strerror
.. code-block:: c
int main(int argc, const char *argv[], const char *envp[]) {
if (setenv("MY_NEW_VAR", "new_value", 1) != 0) {
// setenv call may invalidate 'envp'
/* Handle error */
}
if (envp != NULL) {
for (size_t i = 0; envp[i] != NULL; ++i) {
puts(envp[i]);
// envp may no longer point to the current environment
// this program has unanticipated behavior, since envp
// does not reflect changes made by setenv function.
}
}
return 0;
}
void previous_call_invalidation() {
char *p, *pp;
p = getenv("VAR");
setenv("SOMEVAR", "VALUE", /*overwrite = */1);
// call to 'setenv' may invalidate p
*p;
// dereferencing invalid pointer
}
The ``InvalidatingGetEnv`` option is available for treating getenv calls as
invalidating. When enabled, the checker issues a warning if getenv is called
multiple times and their results are used without first creating a copy.
This level of strictness might be considered overly pedantic for the commonly
used getenv implementations.
To enable this option, use:
``-analyzer-config alpha.security.cert.env.InvalidPtr:InvalidatingGetEnv=true``.
By default, this option is set to *false*.
When this option is enabled, warnings will be generated for scenarios like the
following:
.. code-block:: c
char* p = getenv("VAR");
char* pp = getenv("VAR2"); // assumes this call can invalidate `env`
strlen(p); // warns about accessing invalid ptr
alpha.security.taint
^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/APINotes/APINotesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class APINotesManager {
ArrayRef<APINotesReader *> getCurrentModuleReaders() const {
bool HasPublic = CurrentModuleReaders[ReaderKind::Public];
bool HasPrivate = CurrentModuleReaders[ReaderKind::Private];
assert(!HasPrivate || HasPublic && "private module requires public module");
assert(!HasPrivate || (HasPublic && "private module requires public module"));
if (!HasPrivate && !HasPublic)
return {};
return ArrayRef(CurrentModuleReaders).slice(0, HasPrivate ? 2 : 1);
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -7776,10 +7776,10 @@ class OMPOrderClause final : public OMPClause {
/// \param MLoc Location of the modifier
OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc,
SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, OpenMPOrderClauseModifier M,
SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier,
SourceLocation MLoc)
: OMPClause(llvm::omp::OMPC_order, StartLoc, EndLoc),
LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), Modifier(M),
LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), Modifier(Modifier),
ModifierKwLoc(MLoc) {}

/// Build an empty clause.
Expand Down
14 changes: 8 additions & 6 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -7585,11 +7585,11 @@ def CoroLifetimeBoundDoc : Documentation {
let Category = DocCatDecl;
let Content = [{
The ``[[clang::coro_lifetimebound]]`` is a class attribute which can be applied
to a `coroutine return type (CRT) <https://clang.llvm.org/docs/AttributeReference.html#coro-return-type>` _ (i.e.
to a coroutine return type (`CRT`_) (i.e.
it should also be annotated with ``[[clang::coro_return_type]]``).

All parameters of a function are considered to be lifetime bound. See documentation
of ``[[clang::lifetimebound]]`` for more `details <https://clang.llvm.org/docs/AttributeReference.html#lifetimebound> _`.
All parameters of a function are considered to be lifetime bound. See `documentation`_
of ``[[clang::lifetimebound]]`` for more details.
if the function returns a coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.

Reference parameters of a coroutine are susceptible to capturing references to temporaries or local variables.
Expand All @@ -7606,9 +7606,8 @@ For example,
return coro(a);
}

`Lifetime bound <https://clang.llvm.org/docs/AttributeReference.html#lifetimebound> _` static analysis
can be used to detect such instances when coroutines capture references which may die earlier than the
coroutine frame itself. In the above example, if the CRT `task` is annotated with
Lifetime bound static analysis can be used to detect such instances when coroutines capture references
which may die earlier than the coroutine frame itself. In the above example, if the CRT `task` is annotated with
``[[clang::coro_lifetimebound]]``, then lifetime bound analysis would detect capturing reference to
temporaries or return address of a local variable.

Expand All @@ -7635,5 +7634,8 @@ Both coroutines and coroutine wrappers are part of this analysis.
[[clang::coro_wrapper]] Task<int> stack_reference(int a) {
return coro(a); // warning: returning address of stack variable `a`.
}

.. _`documentation`: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
.. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
}];
}
28 changes: 15 additions & 13 deletions clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ def InsecureAPI : Package<"insecureAPI">, ParentPackage<Security>;
def SecurityAlpha : Package<"security">, ParentPackage<Alpha>;
def Taint : Package<"taint">, ParentPackage<SecurityAlpha>;

def CERT : Package<"cert">, ParentPackage<SecurityAlpha>;
def POS : Package<"pos">, ParentPackage<CERT>;
def CERT : Package<"cert">, ParentPackage<Security>;
def ENV : Package<"env">, ParentPackage<CERT>;

def CERTAlpha : Package<"cert">, ParentPackage<SecurityAlpha>;
def POSAlpha : Package<"pos">, ParentPackage<CERTAlpha>;

def Unix : Package<"unix">;
def UnixAlpha : Package<"unix">, ParentPackage<Alpha>;
def CString : Package<"cstring">, ParentPackage<Unix>;
Expand Down Expand Up @@ -993,15 +995,6 @@ def FloatLoopCounter : Checker<"FloatLoopCounter">,

} // end "security"

let ParentPackage = POS in {

def PutenvWithAuto : Checker<"34c">,
HelpText<"Finds calls to the 'putenv' function which pass a pointer to "
"an automatic variable as the argument.">,
Documentation<HasDocumentation>;

} // end "alpha.cert.pos"

let ParentPackage = ENV in {

def InvalidPtrChecker : Checker<"InvalidPtr">,
Expand All @@ -1013,11 +1006,20 @@ let ParentPackage = ENV in {
"standard), which can lead to false positives depending on "
"implementation.",
"false",
InAlpha>,
Released>,
]>,
Documentation<HasDocumentation>;

} // end "alpha.cert.env"
} // end "security.cert.env"

let ParentPackage = POSAlpha in {

def PutenvWithAuto : Checker<"34c">,
HelpText<"Finds calls to the 'putenv' function which pass a pointer to "
"an automatic variable as the argument.">,
Documentation<HasDocumentation>;

} // end "alpha.cert.pos"

let ParentPackage = SecurityAlpha in {

Expand Down
10 changes: 10 additions & 0 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3513,6 +3513,14 @@ class IsTypeDeclaredInsideVisitor
return {};
}

std::optional<bool>
VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
// The "associated declaration" can be the same as ParentDC.
if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
return true;
return {};
}

std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
return true;
Expand Down Expand Up @@ -3573,6 +3581,8 @@ class IsTypeDeclaredInsideVisitor
};
} // namespace

/// This function checks if the function has 'auto' return type that contains
/// a reference (in any way) to a declaration inside the same function.
bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) {
QualType FromTy = D->getType();
const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/ExprConstShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ enum class GCCTypeClass {
// literals.
// Lang = 16,
// OpaqueType = 17,
BitInt = 18
BitInt = 18,
Vector = 19
};

GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11615,16 +11615,18 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
return EvaluateBuiltinClassifyType(
CanTy->castAs<AtomicType>()->getValueType(), LangOpts);

case Type::BlockPointer:
case Type::Vector:
case Type::ExtVector:
return GCCTypeClass::Vector;

case Type::BlockPointer:
case Type::ConstantMatrix:
case Type::ObjCObject:
case Type::ObjCInterface:
case Type::ObjCObjectPointer:
case Type::Pipe:
// GCC classifies vectors as None. We follow its lead and classify all
// other types that don't fit into the regular classification the same way.
// Classify all other types that don't fit into the regular
// classification the same way.
return GCCTypeClass::None;

case Type::BitInt:
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ resolveTargetAttrOverride(const std::vector<std::string> &FeaturesVec,
std::vector<std::string> NonISAExtFeature =
collectNonISAExtFeature(FeaturesNeedOverride, XLen);

auto ResolvedFeature = std::vector(++I, FeaturesVec.end());
auto ResolvedFeature = std::vector<std::string>(++I, FeaturesVec.end());
ResolvedFeature.insert(ResolvedFeature.end(), NonISAExtFeature.begin(),
NonISAExtFeature.end());

Expand Down
Loading

0 comments on commit d091f6f

Please sign in to comment.