Skip to content

Commit f87bd28

Browse files
committed
merge main
2 parents a23352c + 6306f0f commit f87bd28

File tree

92 files changed

+4557
-2255
lines changed

Some content is hidden

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

92 files changed

+4557
-2255
lines changed

clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ on the control flow of the function, an overload where all problematic
4242

4343
This issue can also be resolved by adding ``[[clang::lifetimebound]]``. Clang
4444
enable ``-Wdangling`` warning by default which can detect mis-uses of the
45-
annotated function. See `lifetimebound attribute <https://clang.llvm.org/docs/AttributeReference.html#id11>`_
45+
annotated function. See `lifetimebound attribute <https://clang.llvm.org/docs/AttributeReference.html#lifetimebound>`_
4646
for details.
4747

4848
.. code-block:: c++

clang/docs/LibClang.rst

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Libclang tutorial
55
=================
66
The C Interface to Clang provides a relatively small API that exposes facilities for parsing source code into an abstract syntax tree (AST), loading already-parsed ASTs, traversing the AST, associating physical source locations with elements within the AST, and other facilities that support Clang-based development tools.
7-
This C interface to Clang will never provide all of the information representation stored in Clang's C++ AST, nor should it: the intent is to maintain an API that is relatively stable from one release to the next, providing only the basic functionality needed to support development tools.
7+
This C interface to Clang will never provide all of the information representation stored in Clang's C++ AST, nor should it: the intent is to maintain an API that is :ref:`relatively stable <Stability>` from one release to the next, providing only the basic functionality needed to support development tools.
88
The entire C interface of libclang is available in the file `Index.h`_
99

1010
Essential types overview
@@ -358,3 +358,49 @@ Complete example code
358358
359359
360360
.. _Index.h: https://github.com/llvm/llvm-project/blob/main/clang/include/clang-c/Index.h
361+
362+
.. _Stability:
363+
364+
ABI and API Stability
365+
---------------------
366+
367+
The C interfaces in libclang are intended to be relatively stable. This allows
368+
a programmer to use libclang without having to worry as much about Clang
369+
upgrades breaking existing code. However, the library is not unchanging. For
370+
example, the library will gain new interfaces over time as needs arise,
371+
existing APIs may be deprecated for eventual removal, etc. Also, the underlying
372+
implementation of the facilities by Clang may change behavior as bugs are
373+
fixed, features get implemented, etc.
374+
375+
The library should be ABI and API stable over time, but ABI- and API-breaking
376+
changes can happen in the following (non-exhaustive) situations:
377+
378+
* Adding new enumerator to an enumeration (can be ABI-breaking in C++).
379+
* Removing an explicitly deprecated API after a suitably long deprecation
380+
period.
381+
* Using implementation details, such as names or comments that say something
382+
is "private", "reserved", "internal", etc.
383+
* Bug fixes and changes to Clang's internal implementation happen routinely and
384+
will change the behavior of callers.
385+
* Rarely, bug fixes to libclang itself.
386+
387+
The library has version macros (``CINDEX_VERSION_MAJOR``,
388+
``CINDEX_VERSION_MINOR``, and ``CINDEX_VERSION``) which can be used to test for
389+
specific library versions at compile time. The ``CINDEX_VERSION_MAJOR`` macro
390+
is only incremented if there are major source- or ABI-breaking changes. Except
391+
for removing an explicitly deprecated API, the changes listed above are not
392+
considered major source- or ABI-breaking changes. Historically, the value this
393+
macro expands to has not changed, but may be incremented in the future should
394+
the need arise. The ``CINDEX_VERSION_MINOR`` macro is incremented as new APIs
395+
are added. The ``CINDEX_VERSION`` macro expands to a value based on the major
396+
and minor version macros.
397+
398+
In an effort to allow the library to be modified as new needs arise, the
399+
following situations are explicitly unsupported:
400+
401+
* Loading different library versions into the same executable and passing
402+
objects between the libraries; despite general ABI stability, different
403+
versions of the library may use different implementation details that are not
404+
compatible across library versions.
405+
* For the same reason as above, serializing objects from one version of the
406+
library and deserializing with a different version is also not supported.

clang/include/clang/Basic/AttrDocs.td

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4396,8 +4396,6 @@ annotated parameter.
43964396
addToSet(str, s); // Not detected.
43974397
}
43984398
}
4399-
4400-
.. _`lifetimebound`: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
44014399
}];
44024400
}
44034401

@@ -9042,14 +9040,14 @@ def CoroLifetimeBoundDoc : Documentation {
90429040
let Category = DocCatDecl;
90439041
let Content = [{
90449042
The ``[[clang::coro_lifetimebound]]`` is a class attribute which can be applied
9045-
to a coroutine return type (`CRT`_) (i.e.
9043+
to a coroutine return type (`coro_return_type, coro_wrapper`_) (i.e.
90469044
it should also be annotated with ``[[clang::coro_return_type]]``).
90479045

90489046
All parameters of a function are considered to be lifetime bound if the function returns a
90499047
coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.
90509048
This lifetime bound analysis can be disabled for a coroutine wrapper or a coroutine by annotating the function
90519049
with ``[[clang::coro_disable_lifetimebound]]`` function attribute .
9052-
See `documentation`_ of ``[[clang::lifetimebound]]`` for details about lifetime bound analysis.
9050+
See documentation of `lifetimebound`_ for details about lifetime bound analysis.
90539051

90549052

90559053
Reference parameters of a coroutine are susceptible to capturing references to temporaries or local variables.
@@ -9109,9 +9107,6 @@ but do not pass them to the underlying coroutine or pass them by value.
91099107
void use() {
91109108
auto task = coro_wrapper(1); // use of temporary is fine as the argument is not lifetime bound.
91119109
}
9112-
9113-
.. _`documentation`: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
9114-
.. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
91159110
}];
91169111
}
91179112

clang/include/clang/CIR/Dialect/IR/CIRDataLayout.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef CLANG_CIR_DIALECT_IR_CIRDATALAYOUT_H
1313
#define CLANG_CIR_DIALECT_IR_CIRDATALAYOUT_H
1414

15+
#include "mlir/Dialect/DLTI/DLTI.h"
1516
#include "mlir/IR/BuiltinOps.h"
1617

1718
namespace cir {
@@ -21,11 +22,18 @@ namespace cir {
2122
class CIRDataLayout {
2223
// This is starting with the minimum functionality needed for code that is
2324
// being upstreamed. Additional methods and members will be added as needed.
25+
bool bigEndian = false;
26+
2427
public:
2528
mlir::DataLayout layout;
2629

2730
/// Constructs a DataLayout the module's data layout attribute.
28-
CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} {}
31+
CIRDataLayout(mlir::ModuleOp modOp);
32+
33+
/// Parse a data layout string (with fallback to default values).
34+
void reset(mlir::DataLayoutSpecInterface spec);
35+
36+
bool isBigEndian() const { return bigEndian; }
2937
};
3038

3139
} // namespace cir

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <set>
3838
#include <sstream>
3939

40-
using namespace llvm;
4140
using namespace clang;
4241

4342
#ifndef NDEBUG
@@ -474,7 +473,7 @@ static bool isSafeSpanTwoParamConstruct(const CXXConstructExpr &Node,
474473
auto HaveEqualConstantValues = [&Ctx](const Expr *E0, const Expr *E1) {
475474
if (auto E0CV = E0->getIntegerConstantExpr(Ctx))
476475
if (auto E1CV = E1->getIntegerConstantExpr(Ctx)) {
477-
return APSInt::compareValues(*E0CV, *E1CV) == 0;
476+
return llvm::APSInt::compareValues(*E0CV, *E1CV) == 0;
478477
}
479478
return false;
480479
};
@@ -485,7 +484,7 @@ static bool isSafeSpanTwoParamConstruct(const CXXConstructExpr &Node,
485484
}
486485
return false;
487486
};
488-
std::optional<APSInt> Arg1CV = Arg1->getIntegerConstantExpr(Ctx);
487+
std::optional<llvm::APSInt> Arg1CV = Arg1->getIntegerConstantExpr(Ctx);
489488

490489
if (Arg1CV && Arg1CV->isZero())
491490
// Check form 5:
@@ -528,10 +527,10 @@ static bool isSafeSpanTwoParamConstruct(const CXXConstructExpr &Node,
528527
QualType Arg0Ty = Arg0->IgnoreImplicit()->getType();
529528

530529
if (auto *ConstArrTy = Ctx.getAsConstantArrayType(Arg0Ty)) {
531-
const APSInt ConstArrSize = APSInt(ConstArrTy->getSize());
530+
const llvm::APSInt ConstArrSize = llvm::APSInt(ConstArrTy->getSize());
532531

533532
// Check form 4:
534-
return Arg1CV && APSInt::compareValues(ConstArrSize, *Arg1CV) == 0;
533+
return Arg1CV && llvm::APSInt::compareValues(ConstArrSize, *Arg1CV) == 0;
535534
}
536535
// Check form 6:
537536
if (auto CCast = dyn_cast<CStyleCastExpr>(Arg0)) {
@@ -1099,9 +1098,10 @@ static bool hasUnsafeSnprintfBuffer(const CallExpr &Node,
10991098
// explicit cast will be needed, which will make this check unreachable.
11001099
// Therefore, the array extent is same as its' bytewise size.
11011100
if (Size->EvaluateAsInt(ER, Ctx)) {
1102-
APSInt EVal = ER.Val.getInt(); // Size must have integer type
1101+
llvm::APSInt EVal = ER.Val.getInt(); // Size must have integer type
11031102

1104-
return APSInt::compareValues(EVal, APSInt(CAT->getSize(), true)) != 0;
1103+
return llvm::APSInt::compareValues(
1104+
EVal, llvm::APSInt(CAT->getSize(), true)) != 0;
11051105
}
11061106
}
11071107
}
@@ -2148,8 +2148,8 @@ namespace {
21482148
// declarations to its uses and make sure we've covered all uses with our
21492149
// analysis before we try to fix the declaration.
21502150
class DeclUseTracker {
2151-
using UseSetTy = SmallSet<const DeclRefExpr *, 16>;
2152-
using DefMapTy = DenseMap<const VarDecl *, const DeclStmt *>;
2151+
using UseSetTy = llvm::SmallSet<const DeclRefExpr *, 16>;
2152+
using DefMapTy = llvm::DenseMap<const VarDecl *, const DeclStmt *>;
21532153

21542154
// Allocate on the heap for easier move.
21552155
std::unique_ptr<UseSetTy> Uses{std::make_unique<UseSetTy>()};
@@ -3640,7 +3640,7 @@ static FixItList fixVarDeclWithArray(const VarDecl *D, const ASTContext &Ctx,
36403640
}
36413641

36423642
SmallString<32> Replacement;
3643-
raw_svector_ostream OS(Replacement);
3643+
llvm::raw_svector_ostream OS(Replacement);
36443644
OS << "std::array<" << ElemTypeTxt << ", " << ArraySizeTxt << "> "
36453645
<< IdentText->str();
36463646

@@ -4064,7 +4064,8 @@ static void applyGadgets(const Decl *D, FixableGadgetList FixableGadgets,
40644064
#endif
40654065

40664066
// Fixpoint iteration for pointer assignments
4067-
using DepMapTy = DenseMap<const VarDecl *, llvm::SetVector<const VarDecl *>>;
4067+
using DepMapTy =
4068+
llvm::DenseMap<const VarDecl *, llvm::SetVector<const VarDecl *>>;
40684069
DepMapTy DependenciesMap{};
40694070
DepMapTy PtrAssignmentGraph{};
40704071

clang/lib/CIR/CodeGen/CIRGenerator.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
#include "mlir/Dialect/OpenACC/OpenACC.h"
1616
#include "mlir/IR/MLIRContext.h"
17+
#include "mlir/Target/LLVMIR/Import.h"
1718

1819
#include "clang/AST/DeclGroup.h"
1920
#include "clang/CIR/CIRGenerator.h"
2021
#include "clang/CIR/Dialect/IR/CIRDialect.h"
2122
#include "clang/CIR/Dialect/OpenACC/RegisterOpenACCExtensions.h"
23+
#include "llvm/IR/DataLayout.h"
2224

2325
using namespace cir;
2426
using namespace clang;
@@ -35,12 +37,20 @@ CIRGenerator::~CIRGenerator() {
3537
assert(deferredInlineMemberFuncDefs.empty() || diags.hasErrorOccurred());
3638
}
3739

40+
static void setMLIRDataLayout(mlir::ModuleOp &mod, const llvm::DataLayout &dl) {
41+
mlir::MLIRContext *mlirContext = mod.getContext();
42+
mlir::DataLayoutSpecInterface dlSpec =
43+
mlir::translateDataLayout(dl, mlirContext);
44+
mod->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, dlSpec);
45+
}
46+
3847
void CIRGenerator::Initialize(ASTContext &astContext) {
3948
using namespace llvm;
4049

4150
this->astContext = &astContext;
4251

4352
mlirContext = std::make_unique<mlir::MLIRContext>();
53+
mlirContext->loadDialect<mlir::DLTIDialect>();
4454
mlirContext->loadDialect<cir::CIRDialect>();
4555
mlirContext->getOrLoadDialect<mlir::acc::OpenACCDialect>();
4656

@@ -51,6 +61,10 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
5161

5262
cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
5363
*mlirContext.get(), astContext, codeGenOpts, diags);
64+
mlir::ModuleOp mod = cgm->getModule();
65+
llvm::DataLayout layout =
66+
llvm::DataLayout(astContext.getTargetInfo().getDataLayoutString());
67+
setMLIRDataLayout(mod, layout);
5468
}
5569

5670
bool CIRGenerator::verifyModule() const { return cgm->verifyModule(); }

clang/lib/CIR/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ add_clang_library(clangCIR
4242
CIROpenACCSupport
4343
MLIRCIR
4444
MLIRCIRInterfaces
45+
MLIRTargetLLVMIRImport
4546
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
2+
3+
using namespace cir;
4+
5+
//===----------------------------------------------------------------------===//
6+
// DataLayout Class Implementation
7+
//===----------------------------------------------------------------------===//
8+
9+
CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout(modOp) {
10+
reset(modOp.getDataLayoutSpec());
11+
}
12+
13+
void CIRDataLayout::reset(mlir::DataLayoutSpecInterface spec) {
14+
bigEndian = false;
15+
if (spec) {
16+
mlir::StringAttr key = mlir::StringAttr::get(
17+
spec.getContext(), mlir::DLTIDialect::kDataLayoutEndiannessKey);
18+
if (mlir::DataLayoutEntryInterface entry = spec.getSpecForIdentifier(key))
19+
if (auto str = llvm::dyn_cast<mlir::StringAttr>(entry.getValue()))
20+
bigEndian = str == mlir::DLTIDialect::kDataLayoutEndiannessBig;
21+
}
22+
}

clang/lib/CIR/Dialect/IR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_clang_library(MLIRCIR
33
CIRDialect.cpp
44
CIRMemorySlot.cpp
55
CIRTypes.cpp
6+
CIRDataLayout.cpp
67

78
DEPENDS
89
MLIRCIROpsIncGen

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
7070
#include "llvm/Transforms/Instrumentation/KCFI.h"
7171
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
72-
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
72+
#include "llvm/Transforms/Instrumentation/MemProfInstrumentation.h"
73+
#include "llvm/Transforms/Instrumentation/MemProfUse.h"
7374
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
7475
#include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
7576
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"

0 commit comments

Comments
 (0)