Skip to content

Commit c08988a

Browse files
apply suggestions
1 parent cbfed6b commit c08988a

File tree

6 files changed

+61
-62
lines changed

6 files changed

+61
-62
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ Non-comprehensive list of changes in this release
327327
``__reference_constructs_from_temporary`` should be used instead. (#GH44056)
328328
- Added `__builtin_get_vtable_pointer` to directly load the primary vtable pointer from a
329329
polymorphic object.
330+
- `libclang` receives a family of new bindings to query basic facts about
331+
GCC-style inline assembly blocks, including whether the block is `volatile`
332+
and its template string following the LLVM IR `asm` format. (#GH143424)
330333
- Clang no longer rejects reinterpret_cast conversions between indirect
331334
ARC-managed pointers and other pointer types. The prior behavior was overly
332335
strict and inconsistent with the ARC specification.

clang/include/clang-c/Index.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,32 +4518,46 @@ CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor);
45184518
* The index N in both cases points into the the total inputs and outputs,
45194519
* or more specifically, into the list of outputs followed by the inputs,
45204520
* starting from index 0 as the first available template argument.
4521+
*
4522+
* This function also returns a valid empty string if the cursor does not point
4523+
* at a GCC inline assembly block.
45214524
*/
45224525

45234526
CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor);
45244527

45254528
/**
45264529
* Given a CXCursor_GCCAsmStmt cursor, check if the assembly block has goto
45274530
* labels.
4531+
* This function also returns FALSE if the cursor does not point at a GCC inline
4532+
* assembly block.
45284533
*/
45294534

45304535
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor);
45314536

45324537
/**
4533-
* Given a CXCursor_GCCAsmStmt cursor, count the number of outputs
4538+
* Given a CXCursor_GCCAsmStmt cursor, count the number of outputs.
4539+
* This function also returns 0 if the cursor does not point at a GCC inline
4540+
* assembly block.
45344541
*/
45354542

45364543
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor);
45374544

45384545
/**
4539-
* Given a CXCursor_GCCAsmStmt cursor, count the number of inputs
4546+
* Given a CXCursor_GCCAsmStmt cursor, count the number of inputs.
4547+
* This function also returns 0 if the cursor does not point at a GCC inline
4548+
* assembly block.
45404549
*/
45414550

45424551
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor);
45434552

45444553
/**
45454554
* Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
45464555
* to the Index-th input.
4556+
* This function returns TRUE when the cursor points at a GCC inline assembly
4557+
* statement, `Index` is within bounds and both the `Constraint` and `Expr` are
4558+
* not NULL.
4559+
* Otherwise, this function returns FALSE but leaves `Constraint` and `Expr`
4560+
* intact.
45474561
*/
45484562

45494563
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
@@ -4554,6 +4568,11 @@ CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
45544568
/**
45554569
* Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
45564570
* to the Index-th output.
4571+
* This function returns TRUE when the cursor points at a GCC inline assembly
4572+
* statement, `Index` is within bounds and both the `Constraint` and `Expr` are
4573+
* not NULL.
4574+
* Otherwise, this function returns FALSE but leaves `Constraint` and `Expr`
4575+
* intact.
45574576
*/
45584577

45594578
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
@@ -4563,26 +4582,26 @@ CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
45634582

45644583
/**
45654584
* Given a CXCursor_GCCAsmStmt cursor, count the clobbers in it.
4585+
* This function also returns 0 if the cursor does not point at a GCC inline
4586+
* assembly block.
45664587
*/
45674588

45684589
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor);
45694590

45704591
/**
45714592
* Given a CXCursor_GCCAsmStmt cursor, get the Index-th clobber of it.
4593+
* This function returns a valid empty string if the cursor does not point
4594+
* at a GCC inline assembly block or `Index` is out of bounds.
45724595
*/
45734596

45744597
CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor,
45754598
unsigned Index);
45764599

4577-
/**
4578-
* Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is simple.
4579-
*/
4580-
4581-
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblySimple(CXCursor Cursor);
4582-
45834600
/**
45844601
* Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is
45854602
* `volatile`.
4603+
* This function returns FALSE if the cursor does not point at a GCC inline
4604+
* assembly block.
45864605
*/
45874606

45884607
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyVolatile(CXCursor Cursor);

clang/test/Index/inline-assembly.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ static void inline_assembly_template_regardless_of_target_machine() {
1717
// CHECK: o_value ${1:w}
1818
// CHECK: ===ASM TEMPLATE END===
1919
// CHECK: volatile: true
20-
// CHECK: simple: false
2120
// CHECK: Output #0 Constraint (=&r): DeclRefExpr=tmp:2:9
2221
// CHECK: Input #0 Constraint (r): UnexposedExpr=tmp:2:9
2322
// CHECK: Clobber #0: cc
@@ -40,9 +39,8 @@ static void inline_assembly_valid_x86_example() {
4039
// CHECK: mov ${1:w}, ${0:w}
4140
// CHECK: ===ASM TEMPLATE END===
4241
// CHECK: volatile: false
43-
// CHECK: simple: false
44-
// CHECK: Output #0 Constraint (=&r): DeclRefExpr=tmp:28:9
45-
// CHECK: Input #0 Constraint (r): UnexposedExpr=tmp:28:9
42+
// CHECK: Output #0 Constraint (=&r): DeclRefExpr=tmp:27:9
43+
// CHECK: Input #0 Constraint (r): UnexposedExpr=tmp:27:9
4644
// CHECK: Clobber #0: cc
4745
// CHECK: Clobber #1: memory
4846
// CHECK: ===ASM END===

clang/tools/c-index-test/c-index-test.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,9 +1997,9 @@ PrintGCCInlineAssembly(CXCursor cursor, CXCursor p, CXClientData d) {
19971997
CXString Constraint, Template, Clobber;
19981998
CXCursor Expr;
19991999
unsigned hasGoto, i, e;
2000-
if (clang_getCursorKind(cursor) != CXCursor_AsmStmt) {
2000+
if (clang_getCursorKind(cursor) != CXCursor_AsmStmt)
20012001
return CXChildVisit_Recurse;
2002-
}
2002+
20032003
hasGoto = clang_Cursor_isGCCAssemblyHasGoto(cursor);
20042004
printf("===ASM TEMPLATE%s===\n", hasGoto ? " (WITH GOTO)" : "");
20052005
Template = clang_Cursor_getGCCAssemblyTemplate(cursor);
@@ -2009,8 +2009,6 @@ PrintGCCInlineAssembly(CXCursor cursor, CXCursor p, CXClientData d) {
20092009

20102010
printf("volatile: %s\n",
20112011
clang_Cursor_isGCCAssemblyVolatile(cursor) ? "true" : "false");
2012-
printf("simple: %s\n",
2013-
clang_Cursor_isGCCAssemblySimple(cursor) ? "true" : "false");
20142012

20152013
for (i = 0, e = clang_Cursor_getGCCAssemblyNumOutputs(cursor); i < e; ++i) {
20162014
clang_Cursor_getGCCAssemblyOutput(cursor, i, &Constraint, &Expr);

clang/tools/libclang/CIndex.cpp

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8655,9 +8655,9 @@ void clang_annotateTokens(CXTranslationUnit TU, CXToken *Tokens,
86558655
CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor Cursor) {
86568656
if (!clang_isStatement(Cursor.kind))
86578657
return cxstring::createEmpty();
8658-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8659-
auto const &C = getCursorContext(Cursor);
8660-
auto AsmTemplate = Stmt->generateAsmString(C);
8658+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8659+
ASTContext const &C = getCursorContext(Cursor);
8660+
std::string AsmTemplate = S->generateAsmString(C);
86618661
return cxstring::createDup(AsmTemplate);
86628662
}
86638663
return cxstring::createEmpty();
@@ -8666,59 +8666,52 @@ CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor Cursor) {
86668666
unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor Cursor) {
86678667
if (!clang_isStatement(Cursor.kind))
86688668
return 0;
8669-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8670-
return Stmt->isAsmGoto();
8671-
}
8669+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8670+
return S->isAsmGoto();
86728671
return 0;
86738672
}
86748673

86758674
unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor Cursor) {
86768675
if (!clang_isStatement(Cursor.kind))
86778676
return 0;
8678-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8679-
return Stmt->getNumOutputs();
8680-
}
8677+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8678+
return S->getNumOutputs();
86818679
return 0;
86828680
}
86838681

86848682
unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor Cursor) {
86858683
if (!clang_isStatement(Cursor.kind))
86868684
return 0;
8687-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8688-
return Stmt->getNumInputs();
8689-
}
8685+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8686+
return S->getNumInputs();
86908687
return 0;
86918688
}
86928689

86938690
unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor, unsigned Index,
86948691
CXString *Constraint,
8695-
CXCursor *Expr) {
8696-
if (!clang_isStatement(Cursor.kind) || !Constraint || !Expr)
8692+
CXCursor *ExprCursor) {
8693+
if (!clang_isStatement(Cursor.kind) || !Constraint || !ExprCursor)
86978694
return 0;
8698-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8699-
Stmt && Index < Stmt->getNumInputs()) {
8700-
auto Constraint_ = Stmt->getInputConstraint(Index);
8701-
auto const *Expr_ = Stmt->getInputExpr(Index);
8702-
*Constraint = cxstring::createDup(Constraint_);
8703-
*Expr = MakeCXCursor(Expr_, getCursorDecl(Cursor),
8704-
cxcursor::getCursorTU(Cursor));
8695+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8696+
S && Index < S->getNumInputs()) {
8697+
*Constraint = cxstring::createDup(S->getInputConstraint(Index));
8698+
*ExprCursor = MakeCXCursor(S->getInputExpr(Index), getCursorDecl(Cursor),
8699+
cxcursor::getCursorTU(Cursor));
87058700
return 1;
87068701
}
87078702
return 0;
87088703
}
87098704

87108705
unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor, unsigned Index,
87118706
CXString *Constraint,
8712-
CXCursor *Expr) {
8713-
if (!clang_isStatement(Cursor.kind) || !Constraint || !Expr)
8707+
CXCursor *ExprCursor) {
8708+
if (!clang_isStatement(Cursor.kind) || !Constraint || !ExprCursor)
87148709
return 0;
8715-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8716-
Stmt && Index < Stmt->getNumOutputs()) {
8717-
auto Constraint_ = Stmt->getOutputConstraint(Index);
8718-
auto const *Expr_ = Stmt->getOutputExpr(Index);
8719-
*Constraint = cxstring::createDup(Constraint_);
8720-
*Expr = MakeCXCursor(Expr_, getCursorDecl(Cursor),
8721-
cxcursor::getCursorTU(Cursor));
8710+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8711+
S && Index < S->getNumOutputs()) {
8712+
*Constraint = cxstring::createDup(S->getOutputConstraint(Index));
8713+
*ExprCursor = MakeCXCursor(S->getOutputExpr(Index), getCursorDecl(Cursor),
8714+
cxcursor::getCursorTU(Cursor));
87228715
return 1;
87238716
}
87248717
return 0;
@@ -8727,9 +8720,8 @@ unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor, unsigned Index,
87278720
unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor) {
87288721
if (!clang_isStatement(Cursor.kind))
87298722
return 0;
8730-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8731-
return Stmt->getNumClobbers();
8732-
}
8723+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8724+
return S->getNumClobbers();
87338725
return 0;
87348726
}
87358727

@@ -8742,21 +8734,11 @@ CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor, unsigned Index) {
87428734
return cxstring::createEmpty();
87438735
}
87448736

8745-
unsigned clang_Cursor_isGCCAssemblySimple(CXCursor Cursor) {
8746-
if (!clang_isStatement(Cursor.kind))
8747-
return 0;
8748-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8749-
return Stmt->isSimple();
8750-
}
8751-
return 0;
8752-
}
8753-
87548737
unsigned clang_Cursor_isGCCAssemblyVolatile(CXCursor Cursor) {
87558738
if (!clang_isStatement(Cursor.kind))
87568739
return 0;
8757-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8758-
return Stmt->isVolatile();
8759-
}
8740+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8741+
return S->isVolatile();
87608742
return 0;
87618743
}
87628744

clang/tools/libclang/libclang.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ LLVM_21 {
449449
clang_Cursor_getGCCAssemblyOutput;
450450
clang_Cursor_getGCCAssemblyNumClobbers;
451451
clang_Cursor_getGCCAssemblyClobber;
452-
clang_Cursor_isGCCAssemblySimple;
453452
clang_Cursor_isGCCAssemblyVolatile;
454453
};
455454

0 commit comments

Comments
 (0)